Back
Close
  • 48

Statement

 Goal

Queneau Numbers were discovered by the French writer and mathematician Raymond Queneau, while member of the OULIPO.

A Queneau Number is a number N such that the sequence [1..N] can go through a series of spiral permutations (or "snail" permutations) and come back to [1..N] in exactly N iterations. The permutation consists in tracing a spiral from the last number of the sequence, spiraling towards the center. For instance, 5 being a Queneau Number, the permutations will start from the sequence

1,2,3,4,5


And go as follows:

5,1,4,2,3

3,5,2,1,4

4,3,1,5,2

2,4,5,3,1

1,2,3,4,5


The Nth line is always the same as the initial sequence, or else the number is not a Queneau Number.
Input
One number N
Output
N lines: the different steps of permutations, as a comma-separated sequence
OR
IMPOSSIBLE if the number is not a Queneau number.
Constraints
2 ≤ N ≤ 30
Example
Input
3
Output
3,1,2
2,3,1
1,2,3
Solve it

A higher resolution is required to access the IDE

codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants