aboutsummaryrefslogtreecommitdiff
path: root/challenge-238/deadmarshal/cl
diff options
context:
space:
mode:
authordeadmarshal <adeadmarshal@gmail.com>2023-10-12 13:16:43 +0330
committerdeadmarshal <adeadmarshal@gmail.com>2023-10-12 13:16:43 +0330
commita6233090f6700d2c4b34d30c9e50c6b113b722d2 (patch)
tree9b0578ac04be9e99bb41354c2f715dac218873a0 /challenge-238/deadmarshal/cl
parent3143f9657ea324e7588d575d67c35eb28bc276f3 (diff)
downloadperlweeklychallenge-club-a6233090f6700d2c4b34d30c9e50c6b113b722d2.tar.gz
perlweeklychallenge-club-a6233090f6700d2c4b34d30c9e50c6b113b722d2.tar.bz2
perlweeklychallenge-club-a6233090f6700d2c4b34d30c9e50c6b113b722d2.zip
TWC238
Diffstat (limited to 'challenge-238/deadmarshal/cl')
-rw-r--r--challenge-238/deadmarshal/cl/ch1.lisp8
-rw-r--r--challenge-238/deadmarshal/cl/ch2.lisp20
2 files changed, 28 insertions, 0 deletions
diff --git a/challenge-238/deadmarshal/cl/ch1.lisp b/challenge-238/deadmarshal/cl/ch1.lisp
new file mode 100644
index 0000000000..d394b05dde
--- /dev/null
+++ b/challenge-238/deadmarshal/cl/ch1.lisp
@@ -0,0 +1,8 @@
+(defun running-sum (list)
+ (loop :for e :in list :sum e :into s :collect s))
+
+(progn
+ (print (running-sum '(1 2 3 4 5)))
+ (print (running-sum '(1 1 1 1 1)))
+ (print (running-sum '(0 -1 1 2))))
+
diff --git a/challenge-238/deadmarshal/cl/ch2.lisp b/challenge-238/deadmarshal/cl/ch2.lisp
new file mode 100644
index 0000000000..c2d1ff22d7
--- /dev/null
+++ b/challenge-238/deadmarshal/cl/ch2.lisp
@@ -0,0 +1,20 @@
+(defun digits (n)
+ (map 'list #'digit-char-p (prin1-to-string n)))
+
+(defun helper (acc n)
+ (if (< n 10)
+ acc
+ (helper (1+ acc) (apply #'* (digits n)))))
+
+(defun persistence-sort (list)
+ (sort list #'(lambda (a b)
+ (let ((ha (helper 0 a))
+ (hb (helper 0 b)))
+ (if (/= ha hb)
+ (< ha hb)
+ (< a b))))))
+
+(progn
+ (print (persistence-sort '(15 99 1 34)))
+ (print (persistence-sort '(50 25 33 22))))
+