summaryrefslogtreecommitdiffstats
path: root/2019/day4
diff options
context:
space:
mode:
Diffstat (limited to '2019/day4')
-rw-r--r--2019/day4/password.lp17
-rw-r--r--2019/day4/password.pl29
2 files changed, 46 insertions, 0 deletions
diff --git a/2019/day4/password.lp b/2019/day4/password.lp
new file mode 100644
index 0000000..b9a1f1a
--- /dev/null
+++ b/2019/day4/password.lp
@@ -0,0 +1,17 @@
1%353096-843212
2digit(X) :- X = 0..9.
3place(N) :- N = 1..6.
4
51 {pass(Q,X) : digit(X)} 1 :- place(Q).
6value(N) :- N = A + B * 10 + C * 100 + D * 1000 + E * 10000 + F * 100000, pass(6,A), pass(5,B), pass(4,C), pass(3,D), pass(2,E), pass(1,F).
7
8:- value(N), N < 353096.
9:- value(N), N > 843212.
10
11:- pass(Q,X), pass(Q', Y), Q' = Q + 1, X > Y.
12%:- pass(Q,X), pass(Q', Y), pass(QQ, Z), Q' = Q + 1, QQ = Q' + 1, X = Y, Y = Z. % I couldn't figure out this so I did 581 - 2
13
14%1 {target(X,Y,XX,YY) : dir(DX,DY), XX-X = DX*S, YY-Y = DY*S, size(S), area(XX,YY,_)} 1 :- number(X,Y,_).
15
16#show pass/2.
17#show value/1.
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";