summaryrefslogtreecommitdiff
path: root/examples/abacus
diff options
context:
space:
mode:
authorDaniel Cerqueira <dan.git@lispclub.com>2025-09-03 12:55:14 +0100
committerDaniel Cerqueira <dan.git@lispclub.com>2025-09-03 12:55:14 +0100
commitb18e1682318452372b0d8017f9ffe72db3e890db (patch)
tree635a99a4fe8df0d2d46906e64dcb665f0f53e801 /examples/abacus
parentf3260d01f80a2dd16a095f2c06a3c2e3fb1094ee (diff)
add some *nice* lali scripts
Diffstat (limited to 'examples/abacus')
-rwxr-xr-xexamples/abacus/reading.lali69
-rwxr-xr-xexamples/abacus/writing.lali69
2 files changed, 138 insertions, 0 deletions
diff --git a/examples/abacus/reading.lali b/examples/abacus/reading.lali
new file mode 100755
index 0000000..d4e510e
--- /dev/null
+++ b/examples/abacus/reading.lali
@@ -0,0 +1,69 @@
+;; variables
+(set 'max-columns +4)
+
+;; functions
+(defun random-number (cases)
+ (fill
+ ((dif cases +0) (cons (random +9) ()))
+ (f (cons (random +9) (random-number (- cases +1))))))
+
+(defun number-to-symbol (num)
+ (fill
+ ((dif +0 num) '0)
+ ((dif +1 num) '1)
+ ((dif +2 num) '2)
+ ((dif +3 num) '3)
+ ((dif +4 num) '4)
+ ((dif +5 num) '5)
+ ((dif +6 num) '6)
+ ((dif +7 num) '7)
+ ((dif +8 num) '8)
+ ((dif +9 num) '9)))
+
+(defun number-to-earth-rod (num)
+ (fill
+ ((dif +0 num) "[@-@][@@@@-@]")
+ ((dif +1 num) "[@-@][@@@-@@]")
+ ((dif +2 num) "[@-@][@@-@@@]")
+ ((dif +3 num) "[@-@][@-@@@@]")
+ ((dif +4 num) "[@-@][-@@@@@]")
+ ((dif +5 num) "[-@@][@@@@-@]")
+ ((dif +6 num) "[-@@][@@@-@@]")
+ ((dif +7 num) "[-@@][@@-@@@]")
+ ((dif +8 num) "[-@@][@-@@@@]")
+ ((dif +9 num) "[-@@][-@@@@@]")))
+
+(defun number-to-air-rod (num)
+ (fill
+ ((dif +0 num) "[@-@@@@][@-@]")
+ ((dif +1 num) "[@@-@@@][@-@]")
+ ((dif +2 num) "[@@@-@@][@-@]")
+ ((dif +3 num) "[@@@@-@][@-@]")
+ ((dif +4 num) "[@@@@@-][@-@]")
+ ((dif +5 num) "[@-@@@@][@@-]")
+ ((dif +6 num) "[@@-@@@][@@-]")
+ ((dif +7 num) "[@@@-@@][@@-]")
+ ((dif +8 num) "[@@@@-@][@@-]")
+ ((dif +9 num) "[@@@@@-][@@-]")))
+
+;; main
+(defun main ()
+ (progs
+ f
+ (set 'n-rand (random-number (random max-columns)))
+ (map (lambda (num) (princ (number-to-earth-rod num)) (newline)) n-rand)
+ (read)
+ (print (map number-to-symbol n-rand))
+ ;; (print n-rand)
+ (newline)
+ (read)
+ (newline)
+ (read)))
+
+;; loop
+(defun loop ()
+ (fill
+ ((main) ())
+ (f (loop))))
+
+(loop)
diff --git a/examples/abacus/writing.lali b/examples/abacus/writing.lali
new file mode 100755
index 0000000..2ba300b
--- /dev/null
+++ b/examples/abacus/writing.lali
@@ -0,0 +1,69 @@
+;; variables
+(set 'max-columns +3)
+
+;; functions
+(defun random-number (cases)
+ (fill
+ ((dif cases +0) (cons (random +9) ()))
+ (f (cons (random +9) (random-number (- cases +1))))))
+
+(defun number-to-symbol (num)
+ (fill
+ ((dif +0 num) '0)
+ ((dif +1 num) '1)
+ ((dif +2 num) '2)
+ ((dif +3 num) '3)
+ ((dif +4 num) '4)
+ ((dif +5 num) '5)
+ ((dif +6 num) '6)
+ ((dif +7 num) '7)
+ ((dif +8 num) '8)
+ ((dif +9 num) '9)))
+
+(defun number-to-earth-rod (num)
+ (fill
+ ((dif +0 num) "[@-@][@@@@-@]")
+ ((dif +1 num) "[@-@][@@@-@@]")
+ ((dif +2 num) "[@-@][@@-@@@]")
+ ((dif +3 num) "[@-@][@-@@@@]")
+ ((dif +4 num) "[@-@][-@@@@@]")
+ ((dif +5 num) "[-@@][@@@@-@]")
+ ((dif +6 num) "[-@@][@@@-@@]")
+ ((dif +7 num) "[-@@][@@-@@@]")
+ ((dif +8 num) "[-@@][@-@@@@]")
+ ((dif +9 num) "[-@@][-@@@@@]")))
+
+(defun number-to-air-rod (num)
+ (fill
+ ((dif +0 num) "[@-@@@@][@-@]")
+ ((dif +1 num) "[@@-@@@][@-@]")
+ ((dif +2 num) "[@@@-@@][@-@]")
+ ((dif +3 num) "[@@@@-@][@-@]")
+ ((dif +4 num) "[@@@@@-][@-@]")
+ ((dif +5 num) "[@-@@@@][@@-]")
+ ((dif +6 num) "[@@-@@@][@@-]")
+ ((dif +7 num) "[@@@-@@][@@-]")
+ ((dif +8 num) "[@@@@-@][@@-]")
+ ((dif +9 num) "[@@@@@-][@@-]")))
+
+;; main
+(defun main ()
+ (progs
+ f
+ (set 'n-rand (random-number (random max-columns)))
+ (print (map number-to-symbol n-rand))
+ ;; (print n-rand)
+ (newline)
+ (read)
+ (map (lambda (num) (princ (number-to-earth-rod num)) (newline)) n-rand)
+ (read)
+ (newline)
+ (read)))
+
+;; loop
+(defun loop ()
+ (fill
+ ((main) ())
+ (f (loop))))
+
+(loop)