From bf16b19b1f6deffd1983efca059db576f3b60ee5 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Mon, 13 Dec 2021 10:40:39 +0300 Subject: 2019, tracking --- 2019/day4/password.pl | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 2019/day4/password.pl (limited to '2019/day4/password.pl') diff --git a/2019/day4/password.pl b/2019/day4/password.pl new file mode 100644 index 0000000..403cf91 --- /dev/null +++ b/2019/day4/password.pl @@ -0,0 +1,29 @@ +use strict; +use warnings; + +use Data::Dumper; + +my $low_bound = 353096; +my $upper_bound = 843212; + +my $count = 0; + +for (my $number = $low_bound; $number < $upper_bound; $number++) { + my @nums = split //, $number; + my @cmp = sort {$a <=> $b} @nums; + if (@nums == @cmp and join ("\0", @nums) eq join ("\0", @cmp)) { + my %digits = (); + foreach (@nums) { + $digits{$_}++; + } + foreach my $reps (values %digits) { + if ($reps == 2) { + print "$number\n"; + $count++; + last; + } + } + } +} + +print ">$count\n"; -- cgit v1.2.3-70-g09d2