Created
February 23, 2016 07:04
-
-
Save codevbus/820fc1518269200a8e9a to your computer and use it in GitHub Desktop.
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
#!/bin/python | |
switchFile = 'switches.txt' | |
with open(switchFile, 'r') as f: | |
lines = f.readlines() | |
numSwitch = int(lines[0]) | |
switches = range(0, numSwitch) | |
switchGrid = {switch: 'off' for switch in switches} | |
def getrange(l): | |
x, y = [int(x) for x in l.split()] | |
if y > x: | |
return range(x, y) | |
else: | |
return range(y, x) | |
r = map(getrange, lines[1:]) | |
for x in r: | |
for i in list(x): | |
if switchGrid[i] == 'off': | |
switchGrid[i] = 'on' | |
else: | |
switchGrid[i] = 'off' | |
def countSwitch(): | |
onswitch = 0 | |
for i in switchGrid: | |
if switchGrid[i] == 'on': | |
onswitch += 1 | |
print(onswitch) | |
countSwitch() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment