diff options
| -rw-r--r-- | challenge-013/simon-proctor/perl6/ch-1.p6 | 12 | ||||
| -rw-r--r-- | challenge-013/simon-proctor/perl6/ch-2.p6 | 28 |
2 files changed, 34 insertions, 6 deletions
diff --git a/challenge-013/simon-proctor/perl6/ch-1.p6 b/challenge-013/simon-proctor/perl6/ch-1.p6 index 2afdf0dbaf..ef8ea26ad6 100644 --- a/challenge-013/simon-proctor/perl6/ch-1.p6 +++ b/challenge-013/simon-proctor/perl6/ch-1.p6 @@ -8,9 +8,9 @@ sub date-format( $date ) { sprintf "%04d/%02d/%02d", .year, .month, .day given $ sub MAIN ( Int() $year #= Year to list Fridays for. ) { - say( date-format( $_ ) ) for (Date.new( :$year, :1month, :1day )...Date.new( :$year, :12month, :31day )) - .grep( *.day-of-week() == 5) - .sort( { $^b <=> $^a } ) - .grep( { state $m = 13; if ( $_.month < $m ) { $m = $_.month;True } else { False } }) - .sort( * <=> * ); -}
\ No newline at end of file + say( date-format($_) ) for (Date.new( :$year, :1month, :1day )...Date.new( :$year, :12month, :31day )) + ==> grep( *.day-of-week() == 5) + ==> sort( { $^b <=> $^a } ) + ==> grep( { state $m = 13; if ( $_.month < $m ) { $m = $_.month;True } else { False } }) + ==> sort( * <=> * ); +} diff --git a/challenge-013/simon-proctor/perl6/ch-2.p6 b/challenge-013/simon-proctor/perl6/ch-2.p6 new file mode 100644 index 0000000000..8b5bf90e9b --- /dev/null +++ b/challenge-013/simon-proctor/perl6/ch-2.p6 @@ -0,0 +1,28 @@ +#!/usr/bin/perl6 + +use v6; + +#| Calculate Hofstadter Female and Male sequences from 0 to n +sub MAIN ( UInt() $n ) { + my @M; + my @F = lazy gather { + my $n = 0; + take 1; + loop { + $n++; + take $n - @M[@F[$n-1]]; + } + } + + @M = lazy gather { + my $n = 0; + take 0; + loop { + $n++; + take $n - @F[@M[$n-1]]; + } + }; + + say "F : {@F[0..$n].join(", ")}"; + say "M : {@M[0..$n].join(", ")}"; +} |
