diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-01-04 19:18:46 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-04 19:18:46 +0000 |
| commit | 32ff6b7fc73fa090a86b79e18ee5bcf8e7efe614 (patch) | |
| tree | 6b35f33737fb667fb0284f53d45a4e0163b9139b | |
| parent | 590f3ed977fc3f3a80cd7c89f05efafc0db84df0 (diff) | |
| parent | b6c966e01966f013c3072928b9842a8234a47e48 (diff) | |
| download | perlweeklychallenge-club-32ff6b7fc73fa090a86b79e18ee5bcf8e7efe614.tar.gz perlweeklychallenge-club-32ff6b7fc73fa090a86b79e18ee5bcf8e7efe614.tar.bz2 perlweeklychallenge-club-32ff6b7fc73fa090a86b79e18ee5bcf8e7efe614.zip | |
Merge pull request #5471 from Scimon/master
Challenge 146 : Back in the saddle
| -rw-r--r-- | challenge-146/simon-proctor/raku/ch-1.raku | 4 | ||||
| -rw-r--r-- | challenge-146/simon-proctor/raku/ch-2.raku | 30 |
2 files changed, 34 insertions, 0 deletions
diff --git a/challenge-146/simon-proctor/raku/ch-1.raku b/challenge-146/simon-proctor/raku/ch-1.raku new file mode 100644 index 0000000000..d495faa793 --- /dev/null +++ b/challenge-146/simon-proctor/raku/ch-1.raku @@ -0,0 +1,4 @@ +#!/usr/bin/env raku + +# Print the 10001st prime +(1..*).grep(*.is-prime)[10000].say; diff --git a/challenge-146/simon-proctor/raku/ch-2.raku b/challenge-146/simon-proctor/raku/ch-2.raku new file mode 100644 index 0000000000..d527facc78 --- /dev/null +++ b/challenge-146/simon-proctor/raku/ch-2.raku @@ -0,0 +1,30 @@ +#!/usr/bin/env raku + +#| Given a Rational number find it's parent and grandparent in the Curious Fraction Tree +multi sub MAIN( Rat() $val ) { + my $parent = parent($val); + my $grandparent = parent($parent); + say "parent = {$parent.nude.join("/")} grandparent = {$grandparent.nude.join("/")}"; +} + +multi sub MAIN('test') is hidden-from-USAGE { + use Test; + is parent(1/2), 1/1; + is parent(1/1), Nil; + is parent(2/5), 2/3; + is parent(5/3), 2/3; + done-testing; +} + +subset Proper of Rat where { $^v.numerator < $^v.denominator }; +subset Improper of Rat where { $^v.numerator > $^v.denominator }; + +multi sub parent( 1.0 ) { 1.0 } + +multi sub parent( Proper \v ) { + return v.numerator / (v.denominator - v.numerator); +} + +multi sub parent( Improper \v ) { + return (v.numerator - v.denominator) / v.denominator; +} |
