diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-07-31 13:57:07 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-31 13:57:07 +0100 |
| commit | 49697bbf6d1d9f78ded0ffbe56bd7ce447583aab (patch) | |
| tree | 7b88253bfe076ee1667a27c84dd11b233eb5cb09 | |
| parent | 49fce48fbc40e3fa0922e862ae0f1d5618199307 (diff) | |
| parent | eb91d4aec41da945d8b9d48942a8d66aa9a26ebd (diff) | |
| download | perlweeklychallenge-club-49697bbf6d1d9f78ded0ffbe56bd7ce447583aab.tar.gz perlweeklychallenge-club-49697bbf6d1d9f78ded0ffbe56bd7ce447583aab.tar.bz2 perlweeklychallenge-club-49697bbf6d1d9f78ded0ffbe56bd7ce447583aab.zip | |
Merge pull request #4631 from wambash/challenge-week-123
solutions week 123
| -rw-r--r-- | challenge-123/wambash/raku/ch-1.raku | 31 | ||||
| -rw-r--r-- | challenge-123/wambash/raku/ch-2.raku | 26 |
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; +} |
