From: Jan "Yenya" Kasprzak Date: Fri, 1 Dec 2023 06:03:46 +0000 (+0100) Subject: 2023 day 1: spelling errors X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?p=aoc.git;a=commitdiff_plain;h=9267829e6732c6950ece1b335d6554cd511e6e3f 2023 day 1: spelling errors --- diff --git a/2023/01.pl b/2023/01.pl new file mode 100755 index 0000000..fed7feb --- /dev/null +++ b/2023/01.pl @@ -0,0 +1,16 @@ +#!/usr/bin/perl -w + +use v5.38; +use strict; +use experimental 'multidimensional', 'for_list', 'builtin'; + +my $sum; + +while (<>) { + my ($first) = /(\d)/; + my ($last) = /.*(\d)/; + $sum += "$first$last"; + # say "$first $last."; +} + +say $sum; diff --git a/2023/02.pl b/2023/02.pl new file mode 100755 index 0000000..56e0c26 --- /dev/null +++ b/2023/02.pl @@ -0,0 +1,30 @@ +#!/usr/bin/perl -w + +use v5.38; +use strict; +use experimental 'multidimensional', 'for_list', 'builtin'; + +my $sum; + +my %map = ( + one => 1, + two => 2, + three => 3, + four => 4, + five => 5, + six => 6, + seven => 7, + eight => 8, + nine => 9, +); + +while (<>) { + my ($first) = /(\d|one|two|three|four|five|six|seven|eight|nine)/; + my ($last) = /(?:.*)(\d|one|two|three|four|five|six|seven|eight|nine)/; + $first = $map{$first} if exists $map{$first}; + $last = $map{$last} if exists $map{$last}; + $sum += "$first$last"; + # say "$_ $first $last."; +} + +say $sum;