Skip to content

Instantly share code, notes, and snippets.

@ruseel
Created October 27, 2013 09:43
Show Gist options
  • Save ruseel/7179721 to your computer and use it in GitHub Desktop.
Save ruseel/7179721 to your computer and use it in GitHub Desktop.
clocksync
switches = [(0,1,2),
(3,7,9,11),
(4,10,14,15),
(0,4,5,6,7),
(6,7,8,10,12),
(0,2,14,15),
(3,14,15),
(4,5,7,14,15),
(1,2,3,4,5),
(3,4,5,9,13)]
def press(switch):
for c in switch:
clocks[c] = (clocks[c]+3) % 12
def is_all_noon():
return all((e == 0 for e in clocks))
def solve(clocks,minpresslst,idx=0,selection=[]):
if idx == len(switches):
return
for i in range(4):
newselection=selection+[(i+1)%4]
press(switches[idx])
if all((e == 0 for e in clocks)):
minpresslst[0]=min(minpresslst[0],sum(newselection))
solve(clocks,minpresslst,idx+1,newselection)
import sys
def readint():
return int(sys.stdin.readline())
def readclocks():
return [int(e)%12 for e in sys.stdin.readline().strip().split(" ")]
if __name__=='__main__':
for case in range(readint()):
cnt=0
minpresslst=[9999]
clocks=readclocks()
solve(clocks,minpresslst)
print(minpresslst[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment