# Reversed Iota's

I didn't invent this challenge, but I find it very interesting to solve.

For every input number, e.g.:

4


Generate a range from 1 to that number:

[1 2 3 4]


And then, for every item in that list, generate a list from 1 to that number:

[[1] [1 2] [1 2 3] [1 2 3 4]]


Then, reverse every item of that list.

[[1] [2 1] [3 2 1] [4 3 2 1]]


## Notes:

• 1 being a loose item is allowed, since flattening will not matter with this anyway.
• To preserve the spirit of the challenge, the range has to be 1-indexed.
• You may flatten the list if your platform doesn't support the concept of nested lists.
• what just happened to the original poster??
– RGS
Feb 11, 2020 at 17:21
• @RGS Anonymization. Feb 11, 2020 at 18:43
• may we output as a sequence of numbers (1 2 1 3 2 1 4 3 2 1), say, if a platform doesn't have a concept of multi-dimensional array/list? Feb 11, 2020 at 20:01
• @S.S.Anne in what sense? And what would be a plausible reason?
– RGS
Feb 11, 2020 at 21:37
• @RGS The user has been disassociated from the question for some reason, probably because they didn't want to take credit for it. It's not been made Community Wiki so the answerers will still get reputation. Or, maybe the user deleted their account right after they posted this (since copying the number into /users/ doesn't work). Feb 11, 2020 at 21:38

# Burlesque, 9 bytes

riroq<-pa


Try it online!

ri  # Read int
ro  # Range [1,N]
q<- # Boxed reverse
pa  # Operate over ((1), (1 2), (1 2 3),...)


Alternative 9 byter, but this also has an empty list as the first element:

riroiT)<-


# T-SQL, 145 bytes

WITH a(n)as(SELECT number FROM spt_values
WHERE'p'=type)SELECT string_agg(@+1-a.n,' ')FROM
a,a b WHERE a.n<=@ and b.n<a.n
GROUP BY b.n ORDER BY 1


Try it online

# Stax, 6 bytes

RmRr|u


Run and debug it

# Pyth, 5 bytes

_MSMS


Try it online!

# Japt, 4 bytes

õ!õ1


Try it here

# Charcoal, 9 bytes

ＩＥＮ⮌Ｅ⊕ι⊕μ


Try it online! Link is to verbose version of code. Explanation:

  Ｎ         Input as a number
Ｅ          Map over implicit 0-indexed range
ι     Current index
⊕      Incremented
Ｅ       Map over implicit 0-indexed range
μ   Inner index
⊕    Incremented
⮌        Reversed
Ｉ           Cast to string for implicit print


There are other ways of getting the inner range such as InclusiveRange(1, Incremented(i)) and Range(1, Plus(2, i)) for the same byte count.

# Clojure, 36 bytes

#(for[i(range %)](range(inc i)0 -1))


Try it online!

# Kotlin, 37 bytes

{(1..it).map{(it downTo 1).toList()}}


Try it online!

# Java (JDK), 98 bytes

n->{int a[][]=new int[n][],i=0,j;for(;i<n;)for(a[i]=new int[j=++i];j>0;)a[i-1][--j]=i-j;return a;}


Try it online!

# Zsh, 22 bytes

eval echo {{1..$1}..1}  Try it online! {{1..$1}..1} -> {1..1} {2..1} {3..1} {4..1} ...

eval echo {1..1} {2..1} {3..1} ... -> echo 1 2 1 3 2 1 ...

If the sublists must be delimited, then 25 bytes for , or 26 bytes for newline.