Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =begin plan
- figure out how to parse the db
- figure out how large the cloth is?
- or do it dynamically?
- if i use a baghash i can use standardized coordinate names
- #179 @ 907,336: 26x10
- basically here i'm starting with $x=907 and $y=336
- in the baghash, incr a key 907x336, through to 933x336,
- then 907x337 to 933x337
- ...
- 907x346 to 933x346
- (should probably switch that so i'm mentally thinking about scanning horizontally)
- anything that isn't claimed doesn't exist in the bag
- any coordinate that is claimed is in the bag with a value of at least 1
- then i take the list of values, filter out the 1s, and give the length of the end list
- =end plan
- 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 is rw, @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 BagHash $cloth .= new;
- 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 BAGHASH!";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement