41 lines
586 B
Plaintext
41 lines
586 B
Plaintext
defint a-z
|
|
option base 1
|
|
input "n=",n
|
|
dim a(n), s(n), u(4*n-2)
|
|
for i=1 to n: a(i)=i: next
|
|
for i=1 to 4*n-2: u(i)=0: next
|
|
m=0
|
|
i=1
|
|
r=2*n-1
|
|
goto 20
|
|
10 s(i)=j
|
|
u(p)=1
|
|
u(q+r)=1
|
|
incr i
|
|
20 if i>n goto 60
|
|
j=i
|
|
30 z=a(i)
|
|
y=a(j)
|
|
p=i-y+n
|
|
q=i+y-1
|
|
a(i)=y
|
|
a(j)=z
|
|
if u(p)=0 and u(q+r)=0 goto 10
|
|
40 incr j
|
|
if j<=n goto 30
|
|
50 decr j
|
|
if j=i goto 70
|
|
swap a(i),a(j)
|
|
goto 50
|
|
60 incr m
|
|
for k=1 to n: print a(k);: next: print
|
|
70 decr i
|
|
if i=0 goto 80
|
|
p=i-a(i)+n
|
|
q=i+a(i)-1
|
|
j=s(i)
|
|
u(p)=0
|
|
u(q+r)=0
|
|
goto 40
|
|
80 print m
|