From 4e8c8d806887ee71ff62d737aaf703f415b5336d Mon Sep 17 00:00:00 2001 From: "Jan \"Yenya\" Kasprzak" Date: Sat, 3 Dec 2022 06:13:57 +0100 Subject: [PATCH] Day 3: it took too long to write this. --- 2022/05.pl | 20 ++++++++++++++++++++ 2022/06.pl | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 2022/05.pl create mode 100755 2022/06.pl diff --git a/2022/05.pl b/2022/05.pl new file mode 100755 index 0000000..1a78799 --- /dev/null +++ b/2022/05.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl -w + +use v5.36; +use strict; +use experimental 'multidimensional'; + +my $sum; +while (<>) { + chomp; + my $len = length; + my ($l, $r) = (substr($_, 0, $len/2), substr($_, $len/2)); + for my $c (split(//, $l)) { + next if $r !~ /$c/; + $sum += ord($c) - ord('A') + 27 if $c =~ /[A-Z]/; + $sum += ord($c) - ord('a') + 1 if $c =~ /[a-z]/; + say $c; + last; + } +} +say $sum; diff --git a/2022/06.pl b/2022/06.pl new file mode 100755 index 0000000..31b1327 --- /dev/null +++ b/2022/06.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl -w + +use v5.36; +use strict; +use experimental 'multidimensional'; + +my $sum; +chomp (my @bags = <>); + +while (my @a = splice(@bags, 0, 3)) { + for my $c (split(//, $a[0])) { + next if $a[1] !~ /$c/; + next if $a[2] !~ /$c/; + $sum += ord($c) - ord('A') + 27 if $c =~ /[A-Z]/; + $sum += ord($c) - ord('a') + 1 if $c =~ /[a-z]/; + say $c; + last; + } +} +say $sum; -- 2.43.5