Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use v5.12;
- use warnings;
- my $regX = 1;
- my $time = 1;
- my $part1 = 0;
- my $display = '#';
- foreach (map { s#^[[:alpha:]]+#0#; reverse split } <>) {
- $display .= (abs($regX - $time % 40) <= 1) ? '#' : ' ';
- $part1 += $time * $regX if (++$time % 40 == 20);
- $regX += $_;
- }
- say "Part 1: $part1";
- say "Part 2:";
- say substr($display, 0, 40, '') while( $display );
Advertisement
Comments
-
- This version assumes that there's no "addx 0", and so we can use 0 for noop and (X, 0) for an addx (ie a set command with a noop to give the 2 cycle timing). This makes things really simple for dc, which this code was the test for.
Add Comment
Please, Sign In to add comment
Advertisement