diff options
| -rw-r--r-- | challenge-087/simon-proctor/raku/ch-1.raku | 13 | ||||
| -rw-r--r-- | challenge-087/simon-proctor/raku/ch-2.raku | 40 |
2 files changed, 53 insertions, 0 deletions
diff --git a/challenge-087/simon-proctor/raku/ch-1.raku b/challenge-087/simon-proctor/raku/ch-1.raku new file mode 100644 index 0000000000..288f6e77f5 --- /dev/null +++ b/challenge-087/simon-proctor/raku/ch-1.raku @@ -0,0 +1,13 @@ +#!/usr/bin/env raku + +use v6; + +sub infix:<olt> (\a,\b) is assoc<chain> is pure { b == a+1 }; + +#| Given a list of integers return the longest list of sequential values or 0 +sub MAIN( + *@N where { $_.all ~~ Int } #= List of integers +) { + my @l = @N.combinations().map( *.sort ).reverse.grep( -> @l { [olt] @l } ).first; + say @l.elems >= 2 ?? @l.join(", ") !! 0; +} diff --git a/challenge-087/simon-proctor/raku/ch-2.raku b/challenge-087/simon-proctor/raku/ch-2.raku new file mode 100644 index 0000000000..ed696b162f --- /dev/null +++ b/challenge-087/simon-proctor/raku/ch-2.raku @@ -0,0 +1,40 @@ +#!/usr/bin/env raku + +use v6; + +#! Given a width and a list of 0's and 1's find the biggest rectangle of 1's +#| found within the grid of the given width +sub MAIN ( + UInt $width, #= Width of the grid + *@G where { ($_.all == 0|1) && ($_.elems %% $width) } #= 0's and 1's to make grid +) { + my $height = @G.elems / $width; + + my @options; + for 0..^$width -> $x { + for 0..^$height -> $y { + for 1..$width-$x -> $w { + for 1..$height-$y -> $h { + @options.push( { :$x, :$y, :$w, :$h } ); + } + } + } + } + for @options.sort( { $^b<w> * $^b<h> <=> $^a<w> * $^a<h> } ) -> %o { + my @res = @G[rect(:$width, |%o)]; + if all(@res) == 1 { + @res.rotor(%o<w>).map( *.join(" ")).join("\n").say; + exit; + } + } + say 0; +} + +sub rect(UInt :$width, UInt :$x, UInt :$y, UInt :$w, UInt :$h) { + my @o; + for 0..^$h -> $dy { + my $s = $x + ( ( $y + $dy ) * $width ); + @o.push( |($s..^$s+$w) ); + } + return @o; +} |
