You are reading a single comment by @Greenbank and its replies. Click here to read the full conversation.
  • I chomp off the line feeds when reading in lines as a matter of habit, but I would have been saved if I hadn't by suitable checking:-

    sub tree {
            my ( $x, $y ) = @_;
            my $rx = $x % $mx;
            return 0 if( $m[$y][$rx] eq "." );
            return 1 if( $m[$y][$rx] eq "#" );
            print "ARGH: $x, $y -> $rx, $y [".$m[$y][$rx]."]\n"; exit;
    }
    

    If it's a . then return 0, if it's a # then return 1, otherwise bail with an error message (ARGH is my general term for "one of my assumptions was wrong"). If I'd failed to remove the line feed that would have found it (on the slope = 1,1 answer for sure, probably on the others too).

    Eric has been really evil in the past, he's often designed the example inputs and part 1 in such a way that you get the same answer if you did parse the file correctly as if you didn't parse it correctly and didn't remove the carriage returns. It's these types of puzzles that are maddening as you get the right answer for all of the test cases (which have been cunningly crafted like that) but it fails on your personal input.

About

Avatar for Greenbank @Greenbank started