aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFung Cheok Yin <61836418+E7-87-83@users.noreply.github.com>2020-05-04 18:40:36 +0800
committerGitHub <noreply@github.com>2020-05-04 18:40:36 +0800
commitb89aab02c79a7dffa0c36a01c607b05d61a6fdc6 (patch)
tree39c14cb4f6004c25fdcc036a2d8d66b2d326b8f5
parent7e1c2de792dce48ccc3ba230b5c577d424a110ae (diff)
downloadperlweeklychallenge-club-b89aab02c79a7dffa0c36a01c607b05d61a6fdc6.tar.gz
perlweeklychallenge-club-b89aab02c79a7dffa0c36a01c607b05d61a6fdc6.tar.bz2
perlweeklychallenge-club-b89aab02c79a7dffa0c36a01c607b05d61a6fdc6.zip
Add files via upload
-rw-r--r--ch-1.cl29
-rw-r--r--ch-1.pl28
2 files changed, 57 insertions, 0 deletions
diff --git a/ch-1.cl b/ch-1.cl
new file mode 100644
index 0000000000..e78c8e53c1
--- /dev/null
+++ b/ch-1.cl
@@ -0,0 +1,29 @@
+;(setf *line* '(1 4 3 2 5 2))
+;(setf *K* 3)
+(setf *line* '(5 6 3 2 7 9))
+(setf *K* 6)
+
+(setf *small* nil)
+(setf *large* nil)
+
+(defun newas (R)
+ (append *small* (cons R nil))
+)
+
+(defun newal (R)
+ (append *large* (cons R nil))
+)
+
+(defun biway (R)
+ (if (> *K* R)
+ (setf *small* (newas R ))
+ (setf *large* (newal R ))
+ )
+)
+
+(loop for R in *line*
+ do (biway R)
+)
+
+(print (append *small* *large*))
+
diff --git a/ch-1.pl b/ch-1.pl
new file mode 100644
index 0000000000..3ade87fe43
--- /dev/null
+++ b/ch-1.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+use strict;
+use Test::Simple tests => 3;
+
+
+sub newlist {
+ my @small = ();
+ my @large = ();
+ my ($K, @line) = @_;
+ foreach(@line) {
+ if ($_ < $K) {
+ push @small, $_;
+ }
+ else {
+ push @large, $_;
+ }
+ }
+
+ return (@small, @large);
+}
+
+print join "," , newlist @ARGV;
+print "\n";
+
+ok (newlist(3, 1, 4, 3, 2, 5, 2))==(1, 2, 2, 4, 3, 5) , "bad condition";
+ok (newlist(6,5,6,3,2,7,9)) == (5,3,2,6,7,9), "bad";
+ok (newlist(2 , 3, 2, 1)) == (1, 3, 2), "too bad";
+