Skip to content

Instantly share code, notes, and snippets.

@codekansas
Last active April 30, 2020 17:45
Show Gist options
  • Save codekansas/70fd13a052c96404b0e4884720d1dcc2 to your computer and use it in GitHub Desktop.
Save codekansas/70fd13a052c96404b0e4884720d1dcc2 to your computer and use it in GitHub Desktop.
/*
A combination for a lock has 3 wheels, X, Y, and Z, each of which
can be set to eight different positions. The lock is broken and when
any two wheels of the lock are in the correct position, the lock
will open. Thus, anyone can open the lock after 64 tries (let A and
B run through all possible permutations). However, the safe can be
opened in fewer tries! What is the minimum number of tries that can
be guaranteed to open the lock?
*/
module dot(x, y, z) {
color([1, 1, 1, 0.4])
translate([x, y, z])
cube([1, 1, 1]);
echo(x, y, z);
}
module sol(N, X, Y, Z) {
color([0, 0, 1])
translate([X, Y, 1])
cube([1, 1, N]);
color([0, 1, 0])
translate([X, 1, Z])
cube([1, N, 1]);
color([1, 0, 0])
translate([1, Y, Z])
cube([N, 1, 1]);
M = floor(N / 2);
for (i = [1 : M])
for (j = [1 : M])
dot(i, j, (j + i - 1) % M + 1);
for (i = [1 : M])
for (j = [1 : M])
dot(M + i, M + j, M + (j + i - 1) % M + 1);
}
sol(16, 3, 5, 1);
@codekansas
Copy link
Author

codekansas commented Apr 30, 2020

Combinations for N = 8

ECHO: 1, 1, 2
ECHO: 1, 2, 3
ECHO: 1, 3, 4
ECHO: 1, 4, 1
ECHO: 2, 1, 3
ECHO: 2, 2, 4
ECHO: 2, 3, 1
ECHO: 2, 4, 2
ECHO: 3, 1, 4
ECHO: 3, 2, 1
ECHO: 3, 3, 2
ECHO: 3, 4, 3
ECHO: 4, 1, 1
ECHO: 4, 2, 2
ECHO: 4, 3, 3
ECHO: 4, 4, 4
ECHO: 5, 5, 6
ECHO: 5, 6, 7
ECHO: 5, 7, 8
ECHO: 5, 8, 5
ECHO: 6, 5, 7
ECHO: 6, 6, 8
ECHO: 6, 7, 5
ECHO: 6, 8, 6
ECHO: 7, 5, 8
ECHO: 7, 6, 5
ECHO: 7, 7, 6
ECHO: 7, 8, 7
ECHO: 8, 5, 5
ECHO: 8, 6, 6
ECHO: 8, 7, 7
ECHO: 8, 8, 8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment