🐐 Examples
This commit is contained in:
15
examples/array_sum_max.cent
Normal file
15
examples/array_sum_max.cent
Normal file
@@ -0,0 +1,15 @@
|
||||
// Calculates the sum and max of an array
|
||||
|
||||
DESIGNA array VT [II,XVIII,XV,IX,XIV,XIV,I,VII,VIII,VI]
|
||||
DESIGNA max VT NVLLVS
|
||||
DESIGNA svm VT NVLLVS
|
||||
|
||||
PER x IN array FACE {
|
||||
DESIGNA svm VT svm + x
|
||||
SI x PLVS max TVNC {
|
||||
DESIGNA max VT x
|
||||
}
|
||||
}
|
||||
|
||||
DICE("Sum:", svm)
|
||||
DICE("Max:", max)
|
||||
18
examples/bubble_sort.cent
Normal file
18
examples/bubble_sort.cent
Normal file
@@ -0,0 +1,18 @@
|
||||
// Bubble sort
|
||||
|
||||
DESIGNA arr VT [V, III, VIII, I, IX, II, VII, IV, VI, X]
|
||||
DESIGNA n VT LONGITVDO(arr)
|
||||
|
||||
DONICVM i VT I VSQVE n FACE {
|
||||
DONICVM k VT I VSQVE n - i + I FACE {
|
||||
SI arr[k] PLVS arr[k + I] TVNC {
|
||||
DESIGNA temp VT arr[k]
|
||||
DESIGNA arr[k] VT arr[k + I]
|
||||
DESIGNA arr[k + I] VT temp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PER x IN arr FACE {
|
||||
DICE(x)
|
||||
}
|
||||
9
examples/countdown.cent
Normal file
9
examples/countdown.cent
Normal file
@@ -0,0 +1,9 @@
|
||||
// Counts down from 10
|
||||
DESIGNA conta VT X
|
||||
|
||||
DVM conta MINVS I FACE {
|
||||
DICE(conta)
|
||||
DESIGNA conta VT conta - I
|
||||
}
|
||||
|
||||
DICE("Blast off!")
|
||||
12
examples/factorial.cent
Normal file
12
examples/factorial.cent
Normal file
@@ -0,0 +1,12 @@
|
||||
// Calculates the factorial of the given number
|
||||
CVM MAGNVM
|
||||
|
||||
DEFINI fact(n) VT {
|
||||
SI n MINVS I TVNC {
|
||||
REDI(I)
|
||||
} ALVID {
|
||||
REDI(n * INVOCA fact(n - I))
|
||||
}
|
||||
}
|
||||
|
||||
DICE(INVOCA fact(AVDI_NVMERVS()))
|
||||
@@ -1,3 +1,4 @@
|
||||
// A number guessing game
|
||||
CVM FORS
|
||||
|
||||
DESIGNA correct VT FORTIS_NVMERVS(I,C)
|
||||
|
||||
10
examples/multiplication_table.cent
Normal file
10
examples/multiplication_table.cent
Normal file
@@ -0,0 +1,10 @@
|
||||
// Prints an X×X multiplication table
|
||||
DESIGNA n VT X
|
||||
|
||||
DONICVM i VT I VSQVE n + I FACE {
|
||||
DESIGNA line VT ""
|
||||
DONICVM k VT I VSQVE n + I FACE {
|
||||
DESIGNA line VT line : i * k : " "
|
||||
}
|
||||
DICE(line)
|
||||
}
|
||||
17
examples/rock_paper_scissors.cent
Normal file
17
examples/rock_paper_scissors.cent
Normal file
@@ -0,0 +1,17 @@
|
||||
// Rock, paper, scissors against the computer
|
||||
CVM FORS
|
||||
|
||||
DESIGNA choices VT ["PETRA", "CHARTA", "FORFEX"]
|
||||
DESIGNA compvter VT FORTIS_ELECTIONIS(choices)
|
||||
DICE("Choose: PETRA (rock), CHARTA (paper), or FORFEX (scissors)")
|
||||
DESIGNA player VT AVDI()
|
||||
|
||||
DICE("Computer chose:", compvter)
|
||||
|
||||
SI player EST compvter TVNC {
|
||||
DICE("Draw!")
|
||||
} ALVID SI (player EST "PETRA" ET compvter EST "FORFEX") AVT (player EST "CHARTA" ET compvter EST "PETRA") AVT (player EST "FORFEX" ET compvter EST "CHARTA") TVNC {
|
||||
DICE("You win!")
|
||||
} ALVID {
|
||||
DICE("Computer wins!")
|
||||
}
|
||||
15
examples/sieve.cent
Normal file
15
examples/sieve.cent
Normal file
@@ -0,0 +1,15 @@
|
||||
// Finds all prime numbers up to L (50)
|
||||
|
||||
DESIGNA n VT L
|
||||
|
||||
DONICVM i VT II VSQVE n + I FACE {
|
||||
DESIGNA is_prime VT VERITAS
|
||||
DONICVM k VT II VSQVE i FACE {
|
||||
SI (i / k) * k EST i TVNC {
|
||||
DESIGNA is_prime VT FALSITAS
|
||||
}
|
||||
}
|
||||
SI is_prime TVNC {
|
||||
DICE(i)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user