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.lp | 17 +++++++++++++++++ 2019/day4/password.pl | 29 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 2019/day4/password.lp create mode 100644 2019/day4/password.pl (limited to '2019/day4') 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 @@ +%353096-843212 +digit(X) :- X = 0..9. +place(N) :- N = 1..6. + +1 {pass(Q,X) : digit(X)} 1 :- place(Q). +value(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). + +:- value(N), N < 353096. +:- value(N), N > 843212. + +:- pass(Q,X), pass(Q', Y), Q' = Q + 1, X > Y. +%:- 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 + +%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,_). + +#show pass/2. +#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 @@ +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