3
\$\begingroup\$

This question already has an answer here:

Given a list of stack heights, calculate the number of ways those heights could have been arrived at by stacking blocks one at a time. Shortest code wins.

Test cases:

[2, 2] 6
[3,3,3] 1680
[1,5,9,1] 480480
[] 1
[10] 1
[2,2,2,10] 720720

Reference Python implementation:

def stacking_count(stacks):
     if sum(stacks) == 0:
         return 1
     count = 0
     for i, n in enumerate(stacks):
         if n == 0:
             continue
         stacks[i] -= 1
         count += stacking_count(stacks)
         stacks[i] += 1
     return count
\$\endgroup\$

marked as duplicate by user202729, Community Mar 2 '18 at 16:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0
\$\begingroup\$

Python 3, 85 bytes

f=lambda a:sum(f(a[:i]+[a[i]-1]+a[i+1:])for i in range(len(a))if a[i])if sum(a)else 1

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Jelly, 6 bytes

;@S!:/

Try it online!

-7 bytes thanks to Jonathan Allan

\$\endgroup\$
  • \$\begingroup\$ ...and hence 6 bytes \$\endgroup\$ – Jonathan Allan Mar 2 '18 at 16:29
  • \$\begingroup\$ @JonathanAllan oh wait there is a mathematical approach lol \$\endgroup\$ – HyperNeutrino Mar 2 '18 at 16:35
  • \$\begingroup\$ How about one with only ASCII and what looks almost like a list of emoticons? ;@S!:/ \$\endgroup\$ – Jonathan Allan Mar 2 '18 at 16:40
  • \$\begingroup\$ @JonathanAllan Ooh cool, sure. Thanks! \$\endgroup\$ – HyperNeutrino Mar 2 '18 at 18:12
  • \$\begingroup\$ Golfier TIO link as well :P \$\endgroup\$ – HyperNeutrino Mar 2 '18 at 18:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.