This file contains 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
function overlaps(a: Pin, b: Pin): bool | |
{ | |
print "Check overlap", a,b; | |
if (a$stop <= b$start) | |
return F; | |
if (a$start >= b$stop) | |
return F; | |
return T; | |
} | |
function can_pin(lower: Pin, pins: vector of Pin): bool | |
{ | |
#print lower, "in", pins, "?"; | |
for(p in pins) { | |
#print pins[p]; | |
if(overlaps(lower, pins[p])) { | |
print lower, "overlaps with", p, pins[p]; | |
return T; | |
} | |
} | |
return F; | |
} | |
function try(lock: vector of Lock::Tumbler) { | |
local lower = lock[0]$pins[0]; | |
print lower; | |
for(p in lock) { | |
if (p == 0) next; | |
#print lock[p]; | |
if (!can_pin(lower, lock[p]$pins)) | |
return; | |
} | |
for(p in lock) { | |
print lock[p]; | |
} | |
print "Can solve?!"; | |
print "Spins=", Lock::spins; | |
terminate(); | |
print ""; | |
} | |
event Lock::pick(lock: vector of Lock::Tumbler) { | |
try(lock); | |
#### | |
# | |
# YOU MAY IT USEFUL TO FILL OUT THIS EVENT'S BODY | |
# | |
#### | |
# pick again | |
Lock::ticks += 1msec; | |
schedule 1msec { Lock::pick(lock) }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment