Skip to content

Instantly share code, notes, and snippets.

@copyninja
Created March 28, 2014 05:39
Show Gist options
  • Save copyninja/9826084 to your computer and use it in GitHub Desktop.
Save copyninja/9826084 to your computer and use it in GitHub Desktop.
Code jam Affrical qualification round
def process(credits, nitem, items, case):
for i in range(nitem-1):
for j in range(i+1,nitem):
if int(items [i]) + int(items [j]) == credits:
return "Case #{}: {} {}".format(case, i+1, j+1)
def credit_difference(credits, items):
for item in items:
yield int(item), credits - int(item)
def main():
with open("A-large-practice.in") as fd:
content = fd.read()
lines = content.split('\n')
n = int(lines[0])
lines = lines[1:]
i = 0
for c in range(0,n):
credits = int(lines[i])
nitems = int(lines[i+1])
items = list(map(int, lines [i+2].split (' ')))
print(process(credits, nitems, items, c+1))
# credit_gen = credit_difference(credits, items)
# for item, diff in credit_gen:
# if diff in items:
# print("Case #{}: {} {}".format(c+1, items.index(item)+1,
# items.index(diff)+1))
# break
i += 3
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment