Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sub strip-useless( $claim ) {
- # takes an Elven Claim and reduces it to an array:
- # [ x y x-offset y-offset ] where every element is Int
- my @stripped = $claim.split( " " );
- @stripped = @stripped[2..*];
- my @xy = @stripped[0].split( "," );
- my $y = @xy[1].comb.Array;
- $y.pop;
- @xy[1] = $y.join;
- my @offset = @stripped[1].split( "x" );
- @xy.append( @offset ).map: { .Int };
- }
- my $sampleid = "#183 @ 903,595: 21x25";
- sub get-rect-coords( @rect ) {
- my ($x, $y, $x-offset, $y-offset) = @rect;
- $x-offset += $x;
- $y-offset += $y;
- for $y..^$y-offset -> $cur-y {
- for $x..^$x-offset -> $cur-x {
- take $cur-x ~ "x" ~ $cur-y;
- }
- }
- }
- sub toss-in-bag( %bag, @rect ) {
- my @coords = gather get-rect-coords( @rect );
- for @coords -> $c {
- %bag{ $c }++;
- }
- say "Tossed @rect[0]x@rect[1] in the bag."
- }
- sub process-claims( $filename ) {
- my @claims = $filename.IO.lines;
- my %cloth;
- for @claims -> $claim {
- toss-in-bag( %cloth, strip-useless( $claim ) );
- }
- %cloth;
- }
- my %bag = process-claims( "claims.txt" );
- my $duplicate-claims-list = %bag.values.grep: none 1;
- my $num-dups = $duplicate-claims-list.elems;
- say "Located $num-dups duplicate claims using a HASH!";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement