Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from itertools import product
- from functools import reduce
- def ilen(iterable):
- return reduce(lambda sum, element: sum + 1, iterable, 0)
- def proditer(xs):
- for i in product(*map(lambda x: range(x + 1), xs)):
- yield i
- def is_valid(ds):
- if sum(ds) == 0:
- return False
- elif ((True in map(lambda x: x >= 2, ds)) and (ilen(filter(lambda x: x > 0, ds)) < 2)):
- return False
- else:
- return True
- def is_zero(ds):
- return sum(ds) == 0
- def pts(xs, prt=[]):
- if is_zero(xs):
- return 0
- out = 0
- for ds in proditer(xs):
- if not is_valid(ds):
- continue
- dff = [x - d for x, d in zip(xs, ds)]
- if sorted(prt + [ds]) != prt + [ds]:
- continue
- if is_zero(dff):
- q = prt + [ds]
- print(q)
- continue
- else:
- out += pts(dff, prt + [ds])
- return out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement