This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |