Skip to content

Instantly share code, notes, and snippets.

import itertools, re, sys
ops = (lambda x, y: x + y, lambda x, y: x - y, lambda x, y: x * y, lambda x, y: x / y)
def recurse(so_far, operands, desired):
if not operands:
return '' if so_far == desired else None
for op, op_char in itertools.izip(ops, '+-*/'):
expr = recurse(op(so_far, operands[0]), operands[1:], desired)
if isinstance(expr, basestring):
# look, it's art. okay? it's art about how functional programming in Python is sometimes ugly
#
# it just so happens this art has a terrible worst-case complexity.
#
from itertools import chain, izip_longest, product, permutations
import operator
import sys
operators = (operator.add, operator.sub, operator.mul, operator.truediv)
import fileinput
from itertools import permutations, combinations_with_replacement
def challenge(challenge_str):
the_split = challenge_str.strip().split(' ')
if len(the_split) < 2:
print 'Invalid'
return
for d in the_split: