aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--samples/aoc/2023/01/input4
-rw-r--r--samples/aoc/2023/01/solve.bruijn7
-rw-r--r--samples/rosetta/ackermann.bruijn17
-rw-r--r--samples/rosetta/sorting_quicksort.bruijn13
4 files changed, 41 insertions, 0 deletions
diff --git a/samples/aoc/2023/01/input b/samples/aoc/2023/01/input
new file mode 100644
index 0000000..7bbc69a
--- /dev/null
+++ b/samples/aoc/2023/01/input
@@ -0,0 +1,4 @@
+1abc2
+pqr3stu8vwx
+a1b2c3d4e5f
+treb7uchet
diff --git a/samples/aoc/2023/01/solve.bruijn b/samples/aoc/2023/01/solve.bruijn
new file mode 100644
index 0000000..5fdfa88
--- /dev/null
+++ b/samples/aoc/2023/01/solve.bruijn
@@ -0,0 +1,7 @@
+:import std/Math .
+:import std/String .
+:import std/Char C
+
+part1 [[^0 ⋅ (+10) + _0] (filter (gre? (+9)) (C.number! <$> 0))]
+
+main [∑(part1 <$> (lines 0))]
diff --git a/samples/rosetta/ackermann.bruijn b/samples/rosetta/ackermann.bruijn
new file mode 100644
index 0000000..c0689f1
--- /dev/null
+++ b/samples/rosetta/ackermann.bruijn
@@ -0,0 +1,17 @@
+:import std/Combinator .
+:import std/Number/Unary U
+:import std/Math .
+
+# unary ackermann
+ackermann-unary [0 [[U.inc 0 1 (+1u)]] U.inc]
+
+:test (ackermann-unary (+0u) (+0u)) ((+1u))
+:test (ackermann-unary (+3u) (+4u)) ((+125u))
+
+# ternary ackermann (lower space complexity)
+ackermann-ternary y [[[=?1 ++0 (=?0 (2 --1 (+1)) (2 --1 (2 1 --0)))]]]
+
+:test ((ackermann-ternary (+0) (+0)) =? (+1)) ([[1]])
+:test ((ackermann-ternary (+3) (+4)) =? (+125)) ([[1]])
+
+main [[0]]
diff --git a/samples/rosetta/sorting_quicksort.bruijn b/samples/rosetta/sorting_quicksort.bruijn
new file mode 100644
index 0000000..f55f128
--- /dev/null
+++ b/samples/rosetta/sorting_quicksort.bruijn
@@ -0,0 +1,13 @@
+:import std/Combinator .
+:import std/Number .
+:import std/List .
+
+sort y [[0 [[[case-sort]]] case-end]]
+ case-sort (4 lesser) ++ (2 : (4 greater))
+ lesser 1 <#> (\les? 2)
+ greater 1 <#> (\geq? 2)
+ case-end empty
+
+:test (sort ((+3) : ((+2) : {}(+1)))) ((+1) : ((+2) : {}(+3)))
+
+main [[0]]