Skip to content

Instantly share code, notes, and snippets.

@ignaciobll
Created December 4, 2019 10:39
Show Gist options
  • Save ignaciobll/68afad139adafbe95459a9495144bd0b to your computer and use it in GitHub Desktop.
Save ignaciobll/68afad139adafbe95459a9495144bd0b to your computer and use it in GitHub Desktop.
Solution to Advent Of Code Day 04 with MiniZinc (CLP)
array [1..6] of var 0..9: pass;
int:lower = 264793;
int:upper = 803935;
predicate in_range(array [1..6] of var 0..9: a) =
let {
var int: n = a[1] * 100000 +
a[2] * 10000 +
a[3] * 1000 +
a[4] * 100 +
a[5] * 10 +
a[6];
} in (lower <= n /\ n <= upper) == true;
constraint exists([pass[i] == pass[j] | i,j in 1..6 where i=j+1]);
constraint forall([pass[i] >= pass[j] | i,j in 1..6 where i=j+1]);
constraint in_range(pass);
solve satisfy;
% To obtain all answers execute with flag '-a'
% $> minizinc --solver gecode -a day04.mzn | grep pass | wc -l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment