aoc2022

Advent of Code 2022 solutions in Perl.
git clone git://git.samirparikh.com/aoc2022
Log | Files | Refs | README

commit 5465ac915815f35941c8e54d017aa587e109f251
parent 08fae86a1d3713e0a8414d816016ed758d7a78ab
Author: Samir Parikh <noreply@samirparikh.com>
Date:   Thu, 29 Dec 2022 23:47:33 +0000

start to solve part 1 of day10

Diffstat:
Aday10/day10.pl | 32++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+), 0 deletions(-)

diff --git a/day10/day10.pl b/day10/day10.pl @@ -0,0 +1,32 @@ +#!/usr/local/bin/perl +# day 2022-10 + +use strict; +use warnings; +use v5.32; + +@ARGV = "input" unless @ARGV; +chomp( my $input = do { local $/; <> } ); + +my @x; +my $cycle = 0; +$x[ $cycle ] = 1; +my $ADDX_CYCLE = 2; +my $NOOP_CYCLE = 1; + +foreach ( split /\n/, $input ) { + #say $_; + my ( $instruction, $value ) = m/(noop|addx)\s?(-?\d+)?/; + print "$instruction "; + print $value if $value; + say ''; + $cycle++; + if ( $instruction eq 'noop' ) { + $x[ $cycle ] = $x[ $cycle - 1 ]; + } else { + $x[ $cycle ] = $x[ $cycle - 1 ]; + $cycle++; + $x[ $cycle ] = $x[ $cycle -1 ] + $value; + } + say "after cycle $cycle, X is $x[$cycle]"; +}