Skip to content

Instantly share code, notes, and snippets.

@waleedsamy
Last active August 29, 2015 14:17
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 waleedsamy/e1cf29d362f5ca3f59d7 to your computer and use it in GitHub Desktop.
Save waleedsamy/e1cf29d362f5ca3f59d7 to your computer and use it in GitHub Desktop.
codaility chlorum2014 challenge
# https://codility.com/programmers/custom_challenge/chlorum2014
# not pass yet
# SAMPLE DATA
# C=[1, 3, 0, 3, 2, 4, 4]
# D=[6, 2, 7, 5, 6, 5, 2]
# K=5
C=[1,3,0,3,2,4,4]
D=[6,2,7,5,6,5,2]
K=2
def solution(K, C, D):
Top_D=sorted(D,reverse=True)[:K]
Top_city_index_in_C = [idx for idx,val in enumerate(D) if val in Top_D]
Visit=[x for x in Top_city_index_in_C for y in Top_city_index_in_C if x!=y and connected(C[x],C[y],C)]
return len(set(Visit))
def connected(P, Q ,C):
return True if(C[P] == Q and P != Q) else False
if __name__ == '__main__':
print 'you can visit : ' , solution(K,C,D)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment