aboutsummaryrefslogtreecommitdiffhomepage
path: root/samples/rosetta
diff options
context:
space:
mode:
authorMarvin Borner2024-03-14 13:53:46 +0100
committerMarvin Borner2024-03-14 13:53:46 +0100
commit0b77800262b5c46d994e6cb6159f773de8a05c51 (patch)
tree54e63cfea8fcc046072cb9e0028a12fd34937265 /samples/rosetta
parent004f853f260d321753af32318ecdeb2c585af7b0 (diff)
More samples
Diffstat (limited to 'samples/rosetta')
-rw-r--r--samples/rosetta/determine_sentence_type.bruijn12
-rw-r--r--samples/rosetta/greatest_common_divisor.bruijn8
-rw-r--r--samples/rosetta/mutual_recursion.bruijn20
3 files changed, 40 insertions, 0 deletions
diff --git a/samples/rosetta/determine_sentence_type.bruijn b/samples/rosetta/determine_sentence_type.bruijn
new file mode 100644
index 0000000..551703b
--- /dev/null
+++ b/samples/rosetta/determine_sentence_type.bruijn
@@ -0,0 +1,12 @@
+:import std/List .
+:import std/Char .
+
+determine [∅?0 '?' ([(0 =? '?' 'Q' (0 =? '.' 'S' (0 =? '!' 'E' 'N')))] _0)]
+
+:test (determine empty) ('?')
+:test (determine "hi there, how are you today?") ('Q')
+:test (determine "I'd like to present to you the washing machine 9001.") ('S')
+:test (determine "You have been nominated to win one of these!") ('E')
+:test (determine "Just make sure you don't break it") ('N')
+
+main [[0]]
diff --git a/samples/rosetta/greatest_common_divisor.bruijn b/samples/rosetta/greatest_common_divisor.bruijn
new file mode 100644
index 0000000..37bbb66
--- /dev/null
+++ b/samples/rosetta/greatest_common_divisor.bruijn
@@ -0,0 +1,8 @@
+:import std/Combinator .
+:import std/Number .
+
+gcd y [[[=?0 1 (2 0 (1 % 0))]]]
+
+:test ((gcd (+2) (+4)) =? (+2)) ([[1]])
+:test ((gcd (+10) (+5)) =? (+5)) ([[1]])
+:test ((gcd (+3) (+8)) =? (+1)) ([[1]])
diff --git a/samples/rosetta/mutual_recursion.bruijn b/samples/rosetta/mutual_recursion.bruijn
new file mode 100644
index 0000000..3feb143
--- /dev/null
+++ b/samples/rosetta/mutual_recursion.bruijn
@@ -0,0 +1,20 @@
+:import std/Combinator .
+:import std/Number .
+:import std/List .
+
+f' [[[=?0 (+1) (0 - (1 (2 --0)))]]]
+
+m' [[[=?0 (+0) (0 - (2 (1 --0)))]]]
+
+f ^(y* (f' : {}m'))
+
+m _(y* (f' : {}m'))
+
+:test ((f (+0)) =? (+1)) ([[1]])
+:test ((m (+0)) =? (+0)) ([[1]])
+:test ((f (+4)) =? (+3)) ([[1]])
+:test ((m (+4)) =? (+2)) ([[1]])
+:test ((f (+15)) =? (+9)) ([[1]])
+:test ((m (+15)) =? (+9)) ([[1]])
+
+main [[0]]