Consider a square block of text, N characters wide by N tall, for some odd integer N greater than 1.
As an example let N = 5 and the text be:
MLKJI
NWVUH
OXYTG
PQRSF
ABCDE
Notice that this is the alphabet (besides Z) spiraled around counter-clockwise from the lower left corner. It's kind of like a rolled up carpet.
"Unrolling" the text by one quarter turn clockwise so FGHI
are on the same level as ABCDE
results in:
PONM
QXWL
RYVK
STUJ
ABCDEFGHI
This unrolling can be done 7 more times until the text is a single line:
SRQP
TYXO
UVWN
ABCDEFGHIJKLM
UTS
VYR
WXQ
ABCDEFGHIJKLMNOP
WVU
XYT
ABCDEFGHIJKLMNOPQRS
XW
YV
ABCDEFGHIJKLMNOPQRSTU
YX
ABCDEFGHIJKLMNOPQRSTUVW
Y
ABCDEFGHIJKLMNOPQRSTUVWX
ABCDEFGHIJKLMNOPQRSTUVWXY
Challenge
The challenge is to write a program that is an N×N block of text that outputs the number of times it has "unrolled" by a quarter turn when it is rearranged into the unrolling patterns and run.
There are really two contests here: (hopefully it won't be too messy)
- Do this with the smallest N. (down to a limit of N = 3)
- Do this with the largest N. (no limit)
There will not be an accepted answer but the winner in each of these categories will receive at least 50 bounty rep from me. In case of ties the oldest answers win.
Example
If your code block is
MyP
rog
ram
running it as is should output 0.
Running
rM
oy
ramgP
should output 1.
Running
or
ramgPyM
should output 2.
Running
o
ramgPyMr
should output 3.
Finally, running ramgPyMro
should output 4.
Details
- The output should be printed to stdout (or the closest alternative) by itself. There is no input.
- You may only use printable ASCII (hex codes 20 to 7E, that includes space) in your code.
- Spaces fill the empty space in the unrolling arrangements. (Unless you're unrolling to the left.)
- Only the arrangements from completely square to completely flat need to have valid output. No other arrangements will be run.
- You may not read your own source.
- You may use comments.
- N = 1 is excluded since in many languages the program
0
would work. If desired you may unroll to the left rather than the right. So e.g.
MyP rog ram
becomes
Pg yo Mrram
and so on. No extra spaces are added when rolling this way. The lines just end
(Related: Write a Rectangular Program that Outputs the Number of Times it was Rotated)