diff options
| author | Stephen Lynn <bizlsg@localhost.localdomain> | 2024-02-28 18:23:10 +0800 |
|---|---|---|
| committer | Stephen Lynn <bizlsg@localhost.localdomain> | 2024-02-28 18:23:10 +0800 |
| commit | 4e67759bd7b627440010e1c04e9b3ad56c9fcc1f (patch) | |
| tree | c2712708c944e93cb0b4cba8a1c0614d6b61f77c | |
| parent | 4416b8cd33659c6d380e3ea2c5b3e21e4a861a99 (diff) | |
| download | perlweeklychallenge-club-4e67759bd7b627440010e1c04e9b3ad56c9fcc1f.tar.gz perlweeklychallenge-club-4e67759bd7b627440010e1c04e9b3ad56c9fcc1f.tar.bz2 perlweeklychallenge-club-4e67759bd7b627440010e1c04e9b3ad56c9fcc1f.zip | |
pwc 258
| -rw-r--r-- | challenge-258/steve-g-lynn/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-258/steve-g-lynn/perl/ch-1.pl | 9 | ||||
| -rw-r--r-- | challenge-258/steve-g-lynn/perl/ch-2.pl | 33 | ||||
| -rwxr-xr-x | challenge-258/steve-g-lynn/raku/ch-1.sh | 3 | ||||
| -rwxr-xr-x | challenge-258/steve-g-lynn/raku/ch-2.sh | 3 |
5 files changed, 49 insertions, 0 deletions
diff --git a/challenge-258/steve-g-lynn/blog.txt b/challenge-258/steve-g-lynn/blog.txt new file mode 100644 index 0000000000..cb6aa3d79a --- /dev/null +++ b/challenge-258/steve-g-lynn/blog.txt @@ -0,0 +1 @@ +https://thiujiac.blogspot.com/2024/02/pwc-258.html diff --git a/challenge-258/steve-g-lynn/perl/ch-1.pl b/challenge-258/steve-g-lynn/perl/ch-1.pl new file mode 100644 index 0000000000..07e85dc756 --- /dev/null +++ b/challenge-258/steve-g-lynn/perl/ch-1.pl @@ -0,0 +1,9 @@ +# Perl 4.019 on DOSBOX
+
+sub count_even_digits {
+ scalar( grep( ((length($_) % 2) == 0), @_) );
+}
+
+print &count_even_digits(10,1,111,24,1000),"\n"; #3
+print &count_even_digits(111,1,11111),"\n"; #0
+print &count_even_digits(2,8,1024,256),"\n"; #1
diff --git a/challenge-258/steve-g-lynn/perl/ch-2.pl b/challenge-258/steve-g-lynn/perl/ch-2.pl new file mode 100644 index 0000000000..60926ba13b --- /dev/null +++ b/challenge-258/steve-g-lynn/perl/ch-2.pl @@ -0,0 +1,33 @@ +#perl 4.019 on DOSBOX
+
+#get binary number using vec(.).
+#only works for indexes up to 9
+#
+
+print &sum_of_values(1,2,5,9,11,3),"\n"; #17
+print &sum_of_values(2,2,5,9,11,3),"\n"; #11
+print &sum_of_values(0,2,5,9,11,3),"\n"; #2
+
+sub sum_of_values {
+ local($k,@ints)=@_;
+ ($#ints > 9) && (return "Error. Max 10 elements allowed.");
+ grep($_ =~ /[^0-9]/, ($k,@ints)) && (return "Error. Only integers allowed.");
+ local($sum_of_values)=0;
+ foreach (0 .. $#ints) {
+ (&binsum($_)==$k) && ($sum_of_values += $ints[$_]);
+ }
+ $sum_of_values;
+}
+
+
+sub binsum {
+ #sum of digits of binary form of a number
+ local($num)=$_[0];
+ local($binsum)=0;
+ foreach (0 .. 3) {
+ $binsum += vec($num,$_,1);
+ }
+ $binsum;
+}
+
+
diff --git a/challenge-258/steve-g-lynn/raku/ch-1.sh b/challenge-258/steve-g-lynn/raku/ch-1.sh new file mode 100755 index 0000000000..c062dad9e8 --- /dev/null +++ b/challenge-258/steve-g-lynn/raku/ch-1.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +raku -e 'say +@*ARGS.grep({$_.chars %% 2})' $@ diff --git a/challenge-258/steve-g-lynn/raku/ch-2.sh b/challenge-258/steve-g-lynn/raku/ch-2.sh new file mode 100755 index 0000000000..e6e0c5785c --- /dev/null +++ b/challenge-258/steve-g-lynn/raku/ch-2.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +raku -e 'my ($k, @ints)=@*ARGS; say sum @ints[ (0 .. @ints.elems-1).grep({$_.base(2).comb.sum == $k}) ];' $@ |
