Skip to content

Instantly share code, notes, and snippets.

@geekdinazor
Created November 19, 2015 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geekdinazor/36d719f88e3ec8f7cde7 to your computer and use it in GitHub Desktop.
Save geekdinazor/36d719f88e3ec8f7cde7 to your computer and use it in GitHub Desktop.
Hacettepe BBM103 Assigment III Part II
A,B,C,D,E,F,G,H,I,J,K,L,M,N,O
B:C D F G A M N O
C:E G H
D:F H J N O
F:G M
G:A M
A:K N O
L:N
H:I A M
I:K M N
J:K
E:A K O
K:N O
def mapFileParse():
f = open('paths.txt', 'r')
for line in f:
map = []
for l in line[2:].replace('\r\n','').replace(' ',''):
map.append(l)
paths.update({line[0]:map})
f.close()
def ThreeSome(path):
dests = set()
for key in paths[path]:
dests.add(key)
if key in paths:
dests.update(ThreeSome(key))
return list(dests)
if __name__ == '__main__':
paths = {}
results = {}
mapFileParse()
for key in paths:
results.update({key : ThreeSome(key)})
f = open('commandsP2.txt','r')
for city in f.read().split(','):
if city in paths:
print city + ":" + str(results[city])
else:
print "City '%s' has no reachable neighbour" % (city)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment