From b34285bcf9629c8cd78e0f71a28680eb23f65c70 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Thu, 14 Dec 2017 14:41:37 -0500 Subject: [PATCH] 2015-23 --- 2015/23/1.pl | 40 ++++++++++++++++++++++++++++++++++++++ 2015/23/2.pl | 40 ++++++++++++++++++++++++++++++++++++++ 2015/23/input.txt | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 2015/23/1.pl create mode 100644 2015/23/2.pl create mode 100644 2015/23/input.txt diff --git a/2015/23/1.pl b/2015/23/1.pl new file mode 100644 index 0000000..53492c6 --- /dev/null +++ b/2015/23/1.pl @@ -0,0 +1,40 @@ +use 5.20.0; + +my @code = <>; + +my $i = 0; + +my %t; +while( $i < @code ) { + warn join ' ', $i, $t{a}, $t{b}, $code[$i]; +# my $dummy = <>; + if( $code[$i] =~ /inc (.)/ ) { + $t{$1}++; + $i++; + } + elsif( $code[$i] =~ /tpl (.)/ ) { + $t{$1} *= 3; + $i++; + } + elsif( $code[$i] =~ /hlf (.)/ ) { + $t{$1} /= 2; + warn $t{$1}; + $i++; + } + elsif( $code[$i] =~ /jmp ([+-]\d+)/ ) { + $i+=$1; + } + elsif( $code[$i] =~ /jie (.), ([+-]\d+)/ ) { + $i+= ($t{$1} % 2) ? 1 : $2; + } + elsif( $code[$i] =~ /jio (.), ([+-]\d+)/ ) { + $i+= ($t{$1} != 1) ? 1 : $2; + warn $i; + } + +} + +use DDP; +p %t; + + diff --git a/2015/23/2.pl b/2015/23/2.pl new file mode 100644 index 0000000..ecf926e --- /dev/null +++ b/2015/23/2.pl @@ -0,0 +1,40 @@ +use 5.20.0; + +my @code = <>; + +my $i = 0; + +my %t = ( a => 1 ); +while( $i < @code ) { + warn join ' ', $i, $t{a}, $t{b}, $code[$i]; +# my $dummy = <>; + if( $code[$i] =~ /inc (.)/ ) { + $t{$1}++; + $i++; + } + elsif( $code[$i] =~ /tpl (.)/ ) { + $t{$1} *= 3; + $i++; + } + elsif( $code[$i] =~ /hlf (.)/ ) { + $t{$1} /= 2; + warn $t{$1}; + $i++; + } + elsif( $code[$i] =~ /jmp ([+-]\d+)/ ) { + $i+=$1; + } + elsif( $code[$i] =~ /jie (.), ([+-]\d+)/ ) { + $i+= ($t{$1} % 2) ? 1 : $2; + } + elsif( $code[$i] =~ /jio (.), ([+-]\d+)/ ) { + $i+= ($t{$1} != 1) ? 1 : $2; + warn $i; + } + +} + +use DDP; +p %t; + + diff --git a/2015/23/input.txt b/2015/23/input.txt new file mode 100644 index 0000000..07b1c76 --- /dev/null +++ b/2015/23/input.txt @@ -0,0 +1,49 @@ +jio a, +19 +inc a +tpl a +inc a +tpl a +inc a +tpl a +tpl a +inc a +inc a +tpl a +tpl a +inc a +inc a +tpl a +inc a +inc a +tpl a +jmp +23 +tpl a +tpl a +inc a +inc a +tpl a +inc a +inc a +tpl a +inc a +tpl a +inc a +tpl a +inc a +tpl a +inc a +inc a +tpl a +inc a +inc a +tpl a +tpl a +inc a +jio a, +8 +inc b +jie a, +4 +tpl a +inc a +jmp +2 +hlf a +jmp -7