Skip to content

Instantly share code, notes, and snippets.

@wyukawa
Created August 13, 2012 13:01
Show Gist options
  • Save wyukawa/3340447 to your computer and use it in GitHub Desktop.
Save wyukawa/3340447 to your computer and use it in GitHub Desktop.
くじびき問題
def solve(m, k):
for i1 in k:
for i2 in k:
for i3 in k:
for i4 in k:
if i1+i2+i3+i4 == m:
print "Yes %d+%d+%d+%d=%d" % (i1, i2, i3, i4, m)
break
else:
continue
break
else:
continue
break
else:
continue
break
else:
print "No"
solve(10, [1, 3, 5])
solve(9, [1, 3, 5])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment