From 1cf528262ba29cb08751c6fb75b70a8f7256d01a Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Thu, 28 Dec 2017 12:12:10 -0500 Subject: [PATCH] day 25 --- 25/1.pl | 34 +++++++++++++++++++++++++++++ 25/input.yaml | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 25/1.pl create mode 100644 25/input.yaml diff --git a/25/1.pl b/25/1.pl new file mode 100644 index 0000000..237b221 --- /dev/null +++ b/25/1.pl @@ -0,0 +1,34 @@ +use 5.20.0; + +my $state = 'A'; + +use experimental qw/ smartmatch /; +use List::AllUtils qw/ sum /; + +my $iteration; + +my @ribbon; +my $ri = 0; + +my %chain = ( + A => [ [ 1, 1, 'B' ], [ 0, -1, 'C' ] ], + B => [ [ 1, -1, 'A' ], [ 1, 1, 'D' ] ], + C => [ [ 0, -1, 'B' ], [ 0, -1, 'E' ] ], + D => [ [ 1, 1, 'A' ], [ 0, 1, 'B' ] ], + E => [ [ 1, -1, 'F' ], [ 1, -1, 'C' ] ], + F => [ [ 1, 1, 'D' ], [ 1, 1, 'A' ] ], +); + +while( $iteration++ <= 1_2481_997 ) { + say $iteration unless $iteration % 100_000; + my $change = $chain{$state}[ $ribbon[$ri] ]; + $ribbon[$ri] = $change->[0]; + $ri += $change->[1]; + if( $ri == -1 ) { + unshift @ribbon, 0; + $ri = 0; + } + $state = $change->[2]; +} + +say sum @ribbon; diff --git a/25/input.yaml b/25/input.yaml new file mode 100644 index 0000000..1e6415c --- /dev/null +++ b/25/input.yaml @@ -0,0 +1,59 @@ +In state A: + If the current value is 0: + - Write the value 1. + - Move one slot to the right. + - Continue with state B. + If the current value is 1: + - Write the value 0. + - Move one slot to the left. + - Continue with state C. + +In state B: + If the current value is 0: + - Write the value 1. + - Move one slot to the left. + - Continue with state A. + If the current value is 1: + - Write the value 1. + - Move one slot to the right. + - Continue with state D. + +In state C: + If the current value is 0: + - Write the value 0. + - Move one slot to the left. + - Continue with state B. + If the current value is 1: + - Write the value 0. + - Move one slot to the left. + - Continue with state E. + +In state D: + If the current value is 0: + - Write the value 1. + - Move one slot to the right. + - Continue with state A. + If the current value is 1: + - Write the value 0. + - Move one slot to the right. + - Continue with state B. + +In state E: + If the current value is 0: + - Write the value 1. + - Move one slot to the left. + - Continue with state F. + If the current value is 1: + - Write the value 1. + - Move one slot to the left. + - Continue with state C. + +In state F: + If the current value is 0: + - Write the value 1. + - Move one slot to the right. + - Continue with state D. + If the current value is 1: + - Write the value 1. + - Move one slot to the right. + - Continue with state A.