/* Passcode question in Picat. Presh Talwalkar ("MindYourDecision") "Even Teachers Are Stumped By This One" https://www.youtube.com/watch?v=eY3AgclKBIA&feature=youtu.be """ How many 4 digit passcodes are there if you cannot have the digit 1 followed by the digit 3? """ Note: I assume first that "followed by" means "immediately followed by". Perhaps that's wrong, though... The problem is clarified later, i.e. it mean "immediately followed by": """ A smartphone uses a four-digit passcode, like 0131. San wants to reset the passcode such that the new passcode cannot have the digit 1 followed by the digit 3. How many different passcodes can be formed? (To be precise, the passcode should not have 1 and 3 as consecutive digits. It is okay to have 1 and then a 3 later in the code, like 1030). """ This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. import cp. main => go. % % "1 followed by 3" == "1 immediately followed by 3" % Number of passcodes: 9701. % go => N = 4, X = new_list(N), X :: 0..9, foreach(I in 1..N-1) X[I] #= 1 #=> X[I+1] #!= 3 end, All=solve_all(X), foreach(A in All) println(A) end, println(len=All.len), nl. % % "1 followed by 3" == "1 followed by 3 in any place" % Number of passcodes: 9477 % go2 => N = 4, X = new_list(N), X :: 0..9, foreach(I in 1..N-1) X[I] #= 1 #=> sum([X[J] #= 3 : J in I+1..N]) #= 0 end, All=solve_all(X), foreach(A in All) println(A) end, println(len=All.len), nl.