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 @event = (0);
- my $time = 0;
- my $part1 = 0;
- my $display;
- my @input = <>;
- while ($_ = shift @input) {
- if (m#^addx (.*)#) {
- push( @event, $1 );
- unshift( @input, "noop" );
- } else { # noop
- push( @event, 0 );
- }
- $display .= (abs($regX - $time % 40) <= 1) ? '#' : ' ';
- $part1 += $time * $regX if (++$time % 40 == 20);
- $regX += shift @event;
- }
- say "Part 1: $part1";
- say "Part 2:";
- say substr($display, 0, 40, '') while( $display );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement