diff options
| -rw-r--r-- | challenge-048/simon-proctor/raku/ch-1.p6 | 32 | ||||
| -rw-r--r-- | challenge-048/simon-proctor/raku/ch-2.p6 | 34 |
2 files changed, 66 insertions, 0 deletions
diff --git a/challenge-048/simon-proctor/raku/ch-1.p6 b/challenge-048/simon-proctor/raku/ch-1.p6 new file mode 100644 index 0000000000..14c25126a5 --- /dev/null +++ b/challenge-048/simon-proctor/raku/ch-1.p6 @@ -0,0 +1,32 @@ +#!/usr/bin/env perl6 + +use v6.d; + +# I know there's a mathematical model for this (I saw a video on it) +# But I can't remember it so the default version will just calculate it. + +#| Calculate the survior of the swordsmen suicide pact +multi sub MAIN( + UInt $swords = 50, #= Number of swordsmen (default 50) +) { + my @men = [1..$swords]; + while ( @men.elems > 1 ) { + my ( $alive, $dead ) = @men.splice(0,2); + @men.push($alive); + } + + say "Survivor of $swords is number {@men[0]}"; +} + +# So after doing that I got it. +# Find p where p ** 2 < s (swordsmen) +# The survior is the nth odd number where n = s - p + +#| Calculate mathematically +multi sub MAIN( + "math", + UInt $swords = 50, #= Number of swordsmen +) { + my $low-power = (1,* * 2...*).first(* > $swords) div 2; + say "Survivor of $swords is number {(1,3,5...*)[$swords - $low-power]}"; +} diff --git a/challenge-048/simon-proctor/raku/ch-2.p6 b/challenge-048/simon-proctor/raku/ch-2.p6 new file mode 100644 index 0000000000..ea03d428a7 --- /dev/null +++ b/challenge-048/simon-proctor/raku/ch-2.p6 @@ -0,0 +1,34 @@ +#!/usr/bin/env perl6 + +use v6.d; + +#| Find the palendromic numbers (writen mmddyyy) between 2000-01-01 and 2999-01-01 +sub MAIN() { + my sub df( Date $d) { + # Bleh American dates + sprintf "%02d%02d%04d", .month, .day, .year given $d; + } + + constant START = Date.new(2000,1,1,formatter => &df); + constant END = Date.new(2999,12,31, formatter => &df); + + my @out; + + for (1..12) -> $month { + for (1..31) -> $day { + my $date; + my $year = sprintf( "%02d%02d", $month, $day ).flip; + try { + $date = Date.new($year,$month,$day,formatter => &df); + } + next unless $date; + next unless START <= $date <= END; + @out.push($date); + } + } + + .say for @out.sort; +} + + + |
