Advertisement
musifter

AoC 2022 day 10 (perl-dc)

Dec 10th, 2022 (edited)
1,605
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.40 KB | Source Code | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use v5.12;
  4. use warnings;
  5.  
  6. my $regX  = 1;
  7. my $time  = 1;
  8.  
  9. my $part1 = 0;
  10. my $display = '#';
  11.  
  12. foreach (map { s#^[[:alpha:]]+#0#; reverse split } <>) {
  13.     $display .= (abs($regX - $time % 40) <= 1) ? '#' : ' ';
  14.     $part1 += $time * $regX  if (++$time % 40 == 20);
  15.     $regX  += $_;
  16. }
  17.  
  18. say "Part 1: $part1";
  19.  
  20. say "Part 2:";
  21. say substr($display, 0, 40, '')  while( $display );
  22.  
Advertisement
Comments
  • musifter
    1 year
    # text 0.23 KB | 0 0
    1. 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