aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFung Cheok Yin <61836418+E7-87-83@users.noreply.github.com>2020-08-16 22:36:29 +0800
committerGitHub <noreply@github.com>2020-08-16 22:36:29 +0800
commita816c885b119179fb423c1f3c0bf34ac590c33b4 (patch)
treef6167bc6e12c44d5dcd129de842b3c524cfced40
parenta7da121b0e431bd3c49c3366e89619a9c5094011 (diff)
downloadperlweeklychallenge-club-a816c885b119179fb423c1f3c0bf34ac590c33b4.tar.gz
perlweeklychallenge-club-a816c885b119179fb423c1f3c0bf34ac590c33b4.tar.bz2
perlweeklychallenge-club-a816c885b119179fb423c1f3c0bf34ac590c33b4.zip
Create ch-1.lsp
-rw-r--r--challenge-073/cheok-yin-fung/common-lisp/ch-1.lsp35
1 files changed, 35 insertions, 0 deletions
diff --git a/challenge-073/cheok-yin-fung/common-lisp/ch-1.lsp b/challenge-073/cheok-yin-fung/common-lisp/ch-1.lsp
new file mode 100644
index 0000000000..f6d014a6f3
--- /dev/null
+++ b/challenge-073/cheok-yin-fung/common-lisp/ch-1.lsp
@@ -0,0 +1,35 @@
+; Perl Weekly Challenge #072 Task 1 Sliding Windows
+; task statement:
+; You are given an array of integers @A and sliding window size $S.
+; Write a script to create an array of min from each sliding window.
+
+( defun smallest (a)
+ (if (> (length a) 2)
+ (min (first a) (smallest (rest a)))
+ (min (first a) (cadr a))
+ )
+)
+
+(setf INPUT (list 1 5 0 2 9 3 7 6 4 8)
+ B INPUT)
+
+(setf S 3
+ ANS ()
+ window ()
+)
+
+
+; initialization of the variable window
+(setf window (list (first INPUT)))
+(loop for i from 1 to (- S 1)
+ do (setf window (append window (list (nth i INPUT))))
+)
+
+(loop for i from 0 to (- (length INPUT) S ) do
+ (setf ANS (append ANS (list (smallest window)) )
+ B (rest B)
+ window (append (rest window) (list (nth (- S 1) B)))
+ )
+)
+
+ANS