aboutsummaryrefslogtreecommitdiff
path: root/p99/p19.neb
diff options
context:
space:
mode:
authormryouse2023-06-03 20:22:18 +0000
committermryouse2023-06-03 20:22:18 +0000
commit7b7bf727da3250907284368b98b0083a4b4e2386 (patch)
tree34802caea5181dc0fb97992746ab99b080448418 /p99/p19.neb
initial commit
Diffstat (limited to 'p99/p19.neb')
-rw-r--r--p99/p19.neb15
1 files changed, 15 insertions, 0 deletions
diff --git a/p99/p19.neb b/p99/p19.neb
new file mode 100644
index 0000000..09ff324
--- /dev/null
+++ b/p99/p19.neb
@@ -0,0 +1,15 @@
+; P19 Rotate a list N places to the left.
+
+(def a (list "a" "b" "c" "d" "e" "f" "g" "h"))
+
+(func rotate (lst cnt)
+ (branch
+ ((eq? 0 cnt) lst)
+ ((> cnt 0)
+ (rotate (append (rest lst) (first lst)) (- cnt 1)))
+ ((< cnt 0)
+ (rotate (prepend (most lst) (last lst)) (+ cnt 1)))))
+
+(print (->string a))
+(print (->string (rotate a 3)))
+(print (->string (rotate a (- 2))))