From a17eef230d6dca0a32a725ddadfb3e963093be28 Mon Sep 17 00:00:00 2001 From: E7-87-83 Date: Mon, 21 Sep 2020 07:19:23 +0800 Subject: lisp scripts --- challenge-078/cheok-yin-fung/common-lisp/ch-1.lsp | 18 +++++++++++++++ challenge-078/cheok-yin-fung/common-lisp/ch-2.lsp | 27 +++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 challenge-078/cheok-yin-fung/common-lisp/ch-1.lsp create mode 100644 challenge-078/cheok-yin-fung/common-lisp/ch-2.lsp diff --git a/challenge-078/cheok-yin-fung/common-lisp/ch-1.lsp b/challenge-078/cheok-yin-fung/common-lisp/ch-1.lsp new file mode 100644 index 0000000000..792cb452bd --- /dev/null +++ b/challenge-078/cheok-yin-fung/common-lisp/ch-1.lsp @@ -0,0 +1,18 @@ +; The Weekly Challenge - Perl & Raku #078 Task 1 +; Common Lisp script + +(setf mylist (list 9 10 7 5 6 1)) + +(setf *max* -10000) + +(setf ans nil) + +(setf rmylist (reverse mylist)) + +(dolist (x rmylist) (progn + (setf s (pop rmylist)) + (if (> s *max*) (progn + (setf *max* s) + (push s ans))))) + +(print ans) diff --git a/challenge-078/cheok-yin-fung/common-lisp/ch-2.lsp b/challenge-078/cheok-yin-fung/common-lisp/ch-2.lsp new file mode 100644 index 0000000000..e68ee02b81 --- /dev/null +++ b/challenge-078/cheok-yin-fung/common-lisp/ch-2.lsp @@ -0,0 +1,27 @@ +; The Weekly Challenge - Perl & Raku #078 Task 2 +; Common Lisp Script +; ref: https://stackoverflow.com/questions/16678371/circular-list-in-common-lisp +; answered by Rainer Joswig + +(setf *print-circle* t) ; or the Lisp interpreter will crash IF + ; it is required to handle the circular list + +(setf mylist (list 10 20 30 40 50)) +(setf list-len (length mylist)) +(setf rotated-indices (list 3 4)) + +(defun circular (items) + (setf (cdr (last items)) items) + items) + +(circular mylist) + +(defun main (num-list) + (dolist (x num-list) (progn + (setf temp-list nil) + (dotimes (i list-len) + (push (nth (+ i x) mylist) temp-list)) + (nreverse temp-list) + (print temp-list)))) + +(main rotated-indices) -- cgit