Solve hanging lantern problem: Difference between revisions
Content added Content deleted
(Added solution for Pascal.) |
|||
Line 636: | Line 636: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
==Recursive version== |
|||
<lang python> |
<lang python> |
||
def getLantern(arr): |
def getLantern(arr): |
||
Line 654: | Line 654: | ||
a.append(int(input())) |
a.append(int(input())) |
||
print(getLantern(a)) |
print(getLantern(a)) |
||
</lang> |
|||
==Math solution== |
|||
<lang python> |
|||
import math |
|||
n = int(input()) |
|||
a = [] |
|||
tot = 0 |
|||
for i in range(0, n): |
|||
a.append(int(input())) |
|||
tot += a[i] |
|||
res = math.factorial(tot) |
|||
for i in range(0, n): |
|||
res /= math.factorial(a[i]) |
|||
print(int(res)) |
|||
</lang> |
</lang> |
||