aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Krňávek <Jan.Krnavek@gmail.com>2021-07-31 14:24:53 +0200
committerJan Krňávek <Jan.Krnavek@gmail.com>2021-07-31 14:24:53 +0200
commiteb91d4aec41da945d8b9d48942a8d66aa9a26ebd (patch)
tree42fcf198766ef96860ca90183b1e9e2c666c0259
parent997f80b6026ed842b2f647a6883f34ad0f76e947 (diff)
downloadperlweeklychallenge-club-eb91d4aec41da945d8b9d48942a8d66aa9a26ebd.tar.gz
perlweeklychallenge-club-eb91d4aec41da945d8b9d48942a8d66aa9a26ebd.tar.bz2
perlweeklychallenge-club-eb91d4aec41da945d8b9d48942a8d66aa9a26ebd.zip
solutions week 123
-rw-r--r--challenge-123/wambash/raku/ch-1.raku31
-rw-r--r--challenge-123/wambash/raku/ch-2.raku26
2 files changed, 57 insertions, 0 deletions
diff --git a/challenge-123/wambash/raku/ch-1.raku b/challenge-123/wambash/raku/ch-1.raku
new file mode 100644
index 0000000000..f45ee3fbfd
--- /dev/null
+++ b/challenge-123/wambash/raku/ch-1.raku
@@ -0,0 +1,31 @@
+#!/usr/bin/env raku
+
+multi ugly-numbers ($n, :$ubounds!) {
+ my @twos = 1,2,4 ... $ubounds;
+ my @threes = 1,3,9 ... $ubounds;
+ my @fives = 1,5,25 ... $ubounds;
+
+ @twos X* @threes X* @fives
+ andthen .sort
+ andthen .[$n-1]
+}
+
+multi ugly-numbers ($n) {
+ my $guess = ugly-numbers $n, ubounds => 5**($n**(1/3));
+
+ ugly-numbers $n, ubounds => $guess;
+}
+
+multi MAIN ( $n ) {
+ say ugly-numbers $n;
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is ugly-numbers( 7), 8;
+ is ugly-numbers(10), 12;
+ is ugly-numbers(150, ubounds=> 5**(150**(1/3))), 5832;
+ is ugly-numbers(150), 5832;
+ is ugly-numbers(2¹⁶), 2³³ * 3⁴⁹;
+ done-testing;
+}
diff --git a/challenge-123/wambash/raku/ch-2.raku b/challenge-123/wambash/raku/ch-2.raku
new file mode 100644
index 0000000000..2a813e131d
--- /dev/null
+++ b/challenge-123/wambash/raku/ch-2.raku
@@ -0,0 +1,26 @@
+#!/usr/bin/env raku
+class Point {
+ has $.x;
+ has $.y;
+
+ method COERCE ( @list ) {
+ Point.new: x => @list.[0], y => @list.[1];
+ }
+}
+
+sub square-points ( Point() $a, Point() $b, Point() $c, Point() $d ) {
+ ($a.x - $c.x)*($b.x - $d.x) + ($a.y - $c.y)*($b.y-$d.y) == 0
+ and
+ ($a.x - $c.x)² + ($a.y - $c.y)² == ($b.x - $d.x)² + ($b.y - $d.y)²
+}
+
+multi MAIN (*@points) {
+ say square-points |@points.batch(2)
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ ok square-points((10,20),(20,20),(20,10),(10,10));
+ nok square-points((12,24),(16,10),(20,12),(18,16));
+ done-testing;
+}