aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchirvasitua <chirvasitua@gmail.com>2021-07-26 08:41:50 -0400
committerchirvasitua <chirvasitua@gmail.com>2021-07-26 08:41:50 -0400
commitaa609a626af59795fc92e62bdbdb8fa446728602 (patch)
tree1e9ab028246f0a8c372f0921bea69cd0aadc6390
parent4231c2f762b397e1cacd2cb7e3c2799254fcc1a4 (diff)
downloadperlweeklychallenge-club-aa609a626af59795fc92e62bdbdb8fa446728602.tar.gz
perlweeklychallenge-club-aa609a626af59795fc92e62bdbdb8fa446728602.tar.bz2
perlweeklychallenge-club-aa609a626af59795fc92e62bdbdb8fa446728602.zip
1st commit on 123_raku
-rwxr-xr-xchallenge-123/stuart-little/raku/ch-1.raku14
-rwxr-xr-xchallenge-123/stuart-little/raku/ch-2.raku21
2 files changed, 35 insertions, 0 deletions
diff --git a/challenge-123/stuart-little/raku/ch-1.raku b/challenge-123/stuart-little/raku/ch-1.raku
new file mode 100755
index 0000000000..1dee01f189
--- /dev/null
+++ b/challenge-123/stuart-little/raku/ch-1.raku
@@ -0,0 +1,14 @@
+#!/usr/bin/env raku
+use v6;
+
+# run as <script> <number $n> to return the first $n ugly numbers
+
+my %memo=((1,2,3,5) X=> 1).Hash;
+
+sub smth5p($n) { %memo{$n} && return True; return (my $den=(2,3,5).first({ $n %% $_ })) ?? (%memo{$n div $den} && (%memo{$n}=1).Bool || False) !! (False) }
+
+my ($count,$nr)=(0,0);
+while ($count < @*ARGS[0].Int) {
+ $nr+=1;
+ ($nr.&smth5p) && do { say $nr; $count+=1; };
+}
diff --git a/challenge-123/stuart-little/raku/ch-2.raku b/challenge-123/stuart-little/raku/ch-2.raku
new file mode 100755
index 0000000000..464bfb3b9e
--- /dev/null
+++ b/challenge-123/stuart-little/raku/ch-2.raku
@@ -0,0 +1,21 @@
+#!/usr/bin/env raku
+use v6;
+
+# run <script> <x1 y1 x2 y2 ..>
+
+sub sqDist($x1, $y1, $x2, $y2) {
+ return ($x2-$x1)**2 + ($y2-$y1)**2;
+}
+
+sub sqDistHash(@coords) {
+ my %h;
+ @coords.rotor(2).combinations(2).map({ sqDist(|$_.[0], |$_.[1]) }).map({ %h{$_}++ });
+ return %h;
+}
+
+sub isSq(@coords) {
+ my @distCounts = sqDistHash(@coords).values;
+ return (@distCounts.grep(2) && @distCounts.grep(4)).Bool;
+}
+
+say isSq(@*ARGS[0..7].map(*.Num)).Int;