I require to create a program that provides the solution:
1
3 2
6 5 4
10 9 8 7
using python.
I've been trying out different ideas for over three weeks, and I can't find a solution. All of the code functions/commands that I am permitted to use have been used in the following attempts.
Various attempts include:
The first piece of code shows some promise, but it keeps getting duplicate items in the x list.
#Attempt 1
n=4
l = [0, 1, 2, 3, 4]
x = [0]
for i in range (0, n+1):
k = 0
j = i
while k <= i and j != x[j-1]:
j += l[k]
print (j, end = " ")
x.append(j)
while j != i and j != x[j-1]:
j -= 1
if j > i:
print (j, end = " ")
x.append(j)
print (x)
k+=1
#Attempt 2
n = 4
print (1)
for a in range (2, n):
for i in range (2, n*2, a):
j = i
j+=i-1
print (j, end =" ")
while j>i:
j-=1
print (j, end= " ")
print ()
#Attempt 3
n = 4
l = [1, 2, 3, 4]
for i in range (0, n):
for j in range (0, n*3, l[i]):
while j >= i:
print (j, end = " ")
j-=1
print ()
The output ought to be
1
3 2
6 5 4
10 9 8 7
in some form or the other, but I never get it.