summaryrefslogtreecommitdiffstats
path: root/2019/day4/password.pl
diff options
context:
space:
mode:
Diffstat (limited to '2019/day4/password.pl')
-rw-r--r--2019/day4/password.pl29
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 @@
1use strict;
2use warnings;
3
4use Data::Dumper;
5
6my $low_bound = 353096;
7my $upper_bound = 843212;
8
9my $count = 0;
10
11for (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
29print ">$count\n";