Count stacking sequences

3

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

user1502040

Posted 2018-03-02T16:07:41.633

Reputation: 2 196

Question was closed 2018-03-02T16:18:29.640

Answers

0

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!

HyperNeutrino

Posted 2018-03-02T16:07:41.633

Reputation: 26 575

0

Jelly, 6 bytes

;@S!:/

Try it online!

-7 bytes thanks to Jonathan Allan

HyperNeutrino

Posted 2018-03-02T16:07:41.633

Reputation: 26 575

...and hence 6 bytes

– Jonathan Allan – 2018-03-02T16:29:35.497

@JonathanAllan oh wait there is a mathematical approach lol – HyperNeutrino – 2018-03-02T16:35:09.393

How about one with only ASCII and what looks almost like a list of emoticons? ;@S!:/

– Jonathan Allan – 2018-03-02T16:40:55.660

@JonathanAllan Ooh cool, sure. Thanks! – HyperNeutrino – 2018-03-02T18:12:20.280

Golfier TIO link as well :P – HyperNeutrino – 2018-03-02T18:12:42.660