diff options
| author | Thomas Voss <thomas.voss@humanwave.nl> | 2025-12-10 16:45:27 +0100 |
|---|---|---|
| committer | Thomas Voss <thomas.voss@humanwave.nl> | 2025-12-10 16:45:27 +0100 |
| commit | b4431851ea5b0a9b82c38e13fcbe0301d4a42e0d (patch) | |
| tree | cf6074fe857a14d32f809bd6d34087669f52407c /2018/02/puzzle-1.pl | |
| parent | 73872ba08420a1f679e767b7bc68ed404d099c77 (diff) | |
Add 2018 day 2 part 1 solution
Diffstat (limited to '2018/02/puzzle-1.pl')
| -rwxr-xr-x | 2018/02/puzzle-1.pl | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/2018/02/puzzle-1.pl b/2018/02/puzzle-1.pl new file mode 100755 index 0000000..85a533b --- /dev/null +++ b/2018/02/puzzle-1.pl @@ -0,0 +1,19 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +my $file = "input"; +open my $in, "<", $file or die "Failed to open ‘$file’: $!"; + +my ($x, $y) = (0) x 2; +while (<$in>) { + chomp; + my %freq; + $freq{$_}++ for split //; + $x++ if grep { $_ == 2 } values %freq; + $y++ if grep { $_ == 3 } values %freq; +} + +close $in; +printf "%d\n", $x * $y; |