diff options
| author | Yigit Sever | 2021-12-13 10:40:39 +0300 |
|---|---|---|
| committer | Yigit Sever | 2021-12-13 10:40:39 +0300 |
| commit | bf16b19b1f6deffd1983efca059db576f3b60ee5 (patch) | |
| tree | 1262f68d8eb2c326684d395aebcd5a1cc0b0f748 /2019/day4/password.pl | |
| parent | 74b27ccca31bb757c737dd7fdc02f513f57561b2 (diff) | |
| download | aoc-bf16b19b1f6deffd1983efca059db576f3b60ee5.tar.gz aoc-bf16b19b1f6deffd1983efca059db576f3b60ee5.tar.bz2 aoc-bf16b19b1f6deffd1983efca059db576f3b60ee5.zip | |
2019, tracking
Diffstat (limited to '2019/day4/password.pl')
| -rw-r--r-- | 2019/day4/password.pl | 29 |
1 files changed, 29 insertions, 0 deletions
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 @@ | |||
| 1 | use strict; | ||
| 2 | use warnings; | ||
| 3 | |||
| 4 | use Data::Dumper; | ||
| 5 | |||
| 6 | my $low_bound = 353096; | ||
| 7 | my $upper_bound = 843212; | ||
| 8 | |||
| 9 | my $count = 0; | ||
| 10 | |||
| 11 | for (my $number = $low_bound; $number < $upper_bound; $number++) { | ||
| 12 | my @nums = split //, $number; | ||
| 13 | my @cmp = sort {$a <=> $b} @nums; | ||
| 14 | if (@nums == @cmp and join ("\0", @nums) eq join ("\0", @cmp)) { | ||
| 15 | my %digits = (); | ||
| 16 | foreach (@nums) { | ||
| 17 | $digits{$_}++; | ||
| 18 | } | ||
| 19 | foreach my $reps (values %digits) { | ||
| 20 | if ($reps == 2) { | ||
| 21 | print "$number\n"; | ||
| 22 | $count++; | ||
| 23 | last; | ||
| 24 | } | ||
| 25 | } | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | print ">$count\n"; | ||
