Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
54
Task/Topswops/Potion/topswops.potion
Normal file
54
Task/Topswops/Potion/topswops.potion
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
range = (a, b):
|
||||
i = 0, l = list(b-a+1)
|
||||
while (a + i <= b):
|
||||
l (i) = a + i++.
|
||||
l.
|
||||
|
||||
fannkuch = (n):
|
||||
flips = 0, maxf = 0, k = 0, m = n - 1, r = n
|
||||
perml = range(0, n), count = list(n), perm = list(n)
|
||||
|
||||
loop:
|
||||
while (r != 1):
|
||||
count (r-1) = r
|
||||
r--.
|
||||
|
||||
if (perml (0) != 0 and perml (m) != m):
|
||||
flips = 0, i = 1
|
||||
while (i < n):
|
||||
perm (i) = perml (i)
|
||||
i++.
|
||||
k = perml (0)
|
||||
loop:
|
||||
i = 1, j = k - 1
|
||||
while (i < j):
|
||||
t = perm (i), perm (i) = perm (j), perm (j) = t
|
||||
i++, j--.
|
||||
flips++
|
||||
j = perm (k), perm (k) = k, k = j
|
||||
if (k == 0): break.
|
||||
.
|
||||
if (flips > maxf): maxf = flips.
|
||||
.
|
||||
|
||||
loop:
|
||||
if (r == n):
|
||||
(n, maxf) say
|
||||
return (maxf).
|
||||
|
||||
i = 0, j = perml (0)
|
||||
while (i < r):
|
||||
k = i + 1
|
||||
perml (i) = perml (k)
|
||||
i = k.
|
||||
perml (r) = j
|
||||
|
||||
j = count (r) - 1
|
||||
count (r) = j
|
||||
if (j > 0): break.
|
||||
r++
|
||||
_ n
|
||||
|
||||
n = argv(1) number
|
||||
if (n<1): n=10.
|
||||
fannkuch(n)
|
||||
Loading…
Add table
Add a link
Reference in a new issue