Solve hanging lantern problem

From Rosetta Code
Revision as of 11:40, 22 May 2022 by Fzh2003 (talk | contribs) (Initialize)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Task
Solve hanging lantern problem
You are encouraged to solve this task according to the task description, using any language you may know.

There are some groups of lantern hanging on the ceil. Each group contais one or more lanterns. Each time you can fetch one lantern. Now you need to get all these lanterns down, but you can only fetch the one in the bottom of the group. The qustion is how many ways are there to do this.

For example, there are some lanterns hanging like this:
🏮 🏮 🏮

   🏮 🏮
      🏮

Number these lanterns:
1 2 4

  3 5
    6

You can take like this: [6,3,5,2,4,1] or [3,1,6,5,2,4]
But not: [6,3,2,4,5,1] because at that time 5 is under 4.

There are 60 ways to take them down.


Task

Input:
First an integer (n): the number of groups.
Then n integers: the number of lanterns each group has.
Output:
An integer: the number of sequences.

For example, the input of the example above could be:
3

1

2

3

And the output is:
60


Optional task

Output all the sequences using this format:
[a,b,c,…]

[b,a,c,…]

……