Created
July 22, 2021 23:38
-
-
Save abeham/211d62e29e228e58fd66d5edd4461e02 to your computer and use it in GitHub Desktop.
MiniZinc code that solves the password riddle of https://twitter.com/kareem_carr/status/1418235288137216002?s=20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Use this editor as a MiniZinc scratch book | |
array[1..3] of var 0..9: code; | |
% count(code, X, c) says X must be part of code c times | |
% count_leq(code, X, c) says X must be part of code at least c times | |
% Either 6 is correct and there isn't 8 nor 2 or ... | |
constraint (code[1] == 6 /\ count(code, 8, 0) /\ count(code, 2, 0)) | |
\/ (count(code, 6, 0) /\ code[2] == 8 /\ count(code, 2, 0)) | |
\/ (count(code, 6, 0) /\ count(code, 8, 0) /\ code[3] == 2); | |
% Either 6 is correct, but not in current position and there isn't 1 nor 4 or ... | |
constraint (code[1] != 6 /\ count_leq(code, 6, 1) /\ count(code, 1, 0) /\ count(code, 4, 0)) | |
\/ (code[2] != 1 /\ count_leq(code, 1, 1) /\ count(code, 6, 0) /\ count(code, 4, 0)) | |
\/ (code[3] != 4 /\ count_leq(code, 4, 1) /\ count(code, 6, 0) /\ count(code, 1, 0)); | |
% Either 2 and 0 are correct, but not in current position and there's no 6 or ... | |
constraint code[1] != 2 /\ count_leq(code, 2, 1) /\ code[2] != 0 /\ count_leq(code, 0, 1) /\ count(code, 6, 0) | |
\/ code[1] != 2 /\ count_leq(code, 2, 1) /\ code[3] != 6 /\ count_leq(code, 6, 1) /\ count(code, 0, 0) | |
\/ code[2] != 0 /\ count_leq(code, 0, 1) /\ code[3] != 6 /\ count_leq(code, 6, 1) /\ count(code, 2, 0); | |
solve satisfy; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment