From 4df9256d63e2b740eda6494892578dc0b013efc6 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sun, 24 Dec 2017 13:10:58 -0500 Subject: [PATCH] part1 --- 23/2.pl | 4 ++-- 23/2b.pl | 41 +++++++++++--------------------------- 24/1.pl | 28 ++++++++++++++++++++++++++ 24/input.txt | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 31 deletions(-) create mode 100644 24/1.pl create mode 100644 24/input.txt diff --git a/23/2.pl b/23/2.pl index d6fa3a1..a72cdd0 100644 --- a/23/2.pl +++ b/23/2.pl @@ -12,9 +12,9 @@ while(<>) { } for ( 1..35 ) { - my @c = $script =~ /(L$_: )/g; + my @c = $script =~ /(L$_[ :])/g; next if @c > 1; - $script =~ s/L$_: //g; + $script =~ s/L$_[ :] *//g; } print $script; diff --git a/23/2b.pl b/23/2b.pl index fb67845..638acf1 100644 --- a/23/2b.pl +++ b/23/2b.pl @@ -1,33 +1,16 @@ -$a = 1; -$b = 79; -$c = $b; +($a,$b,$c) = (1,79,79); goto L5 if $a; goto L9 if 1; L5: $b *= 100; $b -= -100000; -$c = $b; -$c -= -17000; -L9: $f = 1; -$d = 2; -L11: $e = 2; -L12: $g = $d; -$g *= $e; -$g -= $b; -goto L17 if $g; -$f = 0; -L17: $e -= -1; -$g = $e; -$g -= $b; -goto L12 if $g; -$d -= -1; -$g = $d; -$g -= $b; -goto L11 if $g; -goto L27 if $f; -$h -= -1; -L27: $g = $b; -$g -= $c; -goto L31 if $g; -goto if 1; -L31: $b -= -17; -goto L9 if 1; +while() { + warn $b; + ($f,$d) = (1,2); +do { + $e = 2; + $f = 0 if not $b % $d; +} while ++$d - $b; + $h++ unless $f; + die $h if $b == 124900; + $b += 17; +} diff --git a/24/1.pl b/24/1.pl new file mode 100644 index 0000000..ea32e6c --- /dev/null +++ b/24/1.pl @@ -0,0 +1,28 @@ +use 5.20.0; +use experimental qw/ signatures postderef smartmatch /; +use List::AllUtils qw/ sum max first_index /; +my @elements = map { chomp; [ split '/' ] } <>; + +use DDP; + +say build_bridge(0,0,@elements); + +sub build_bridge( $sofar = 0, $connector = 0, @left ) { + # warn scalar @left; +# p @_; +# my $summy = ; + + my $max = $sofar; + + for my $i ( 0..$#left ) { + next unless $connector ~~ $left[$i]->@*; + my @copy = @left; + my $i = splice @copy, $i, 1; + my $next_con = $i->[ 1 - first_index { $_ == $connector } @$i ]; + $max = max $max, build_bridge( $sofar + sum( @$i ), $next_con, @copy ); + } + + return $max; +} + + diff --git a/24/input.txt b/24/input.txt new file mode 100644 index 0000000..234aa1f --- /dev/null +++ b/24/input.txt @@ -0,0 +1,56 @@ +31/13 +34/4 +49/49 +23/37 +47/45 +32/4 +12/35 +37/30 +41/48 +0/47 +32/30 +12/5 +37/31 +7/41 +10/28 +35/4 +28/35 +20/29 +32/20 +31/43 +48/14 +10/11 +27/6 +9/24 +8/28 +45/48 +8/1 +16/19 +45/45 +0/4 +29/33 +2/5 +33/9 +11/7 +32/10 +44/1 +40/32 +2/45 +16/16 +1/18 +38/36 +34/24 +39/44 +32/37 +26/46 +25/33 +9/10 +0/29 +38/8 +33/33 +49/19 +18/20 +49/39 +18/39 +26/13 +19/32