Skip to content

Instantly share code, notes, and snippets.

@zahlman
Created December 8, 2011 09:19
Show Gist options
  • Select an option

  • Save zahlman/1446540 to your computer and use it in GitHub Desktop.

Select an option

Save zahlman/1446540 to your computer and use it in GitHub Desktop.
from itertools import combinations, product
from operator import mul, div, add, sub
def intersperse(values, operations):
result = values[0]
for v, o in zip(values[1:], operations): result = o(result, v)
return result
def results(*values):
count = len(values)
return sorted(set(
intersperse(vs, os)
for vs in combinations(values, count)
for os in product(*[[mul, div, add, sub]]*(count - 1))
))
results(22,71,13,1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment