A.rs;ò©n∍9ÝΩ®DnαLʒ®%Ā}<Ωǝ®ô»¹Éi.º.∊ëº∊
+11个字节可将数字固定在随机位置,同时对于奇数输入仍要牢记规则3。
-2个字节感谢@MagicOctopusUrn更改îï
为,ò
并更改了位置»
。
可以在线进行的核实一些测试案例。
旧的(29 27字节)回答数字始终位于角落的位置:
A.rs;ò©n∍¦9ÝΩì®ô»¹Éi.º.∊ëº∊
在线尝试或验证更多测试用例。
说明:
A # Take the lowercase alphabet
.r # Randomly shuffle it
# i.e. "abcdefghijklmnopqrstuvwxyz" → "uovqxrcijfgyzlbpmhatnkwsed"
s # Swap so the (implicit) input is at the top of the stack
; # Halve the input
# i.e. 7 → 3.5
ò # Bankers rounding to the nearest integer
# i.e. 3.5 → 4
© # And save this number in the register
n # Take its square
# i.e. 4 → 16
∍ # Shorten the shuffled alphabet to that length
# i.e. "uovqxrcijfgyzlbpmhatnkwsed" and 16 → "uovqxrcijfgyzlbp"
9ÝΩ # Take a random digit in the range [0,9]
# i.e. 3
®Dnα # Take the difference between the saved number and its square:
# i.e. 4 and 16 → 12
L # Create a list in the range [1,n]
# i.e. 12 → [1,2,3,4,5,6,7,8,9,10,11,12]
ʒ } # Filter this list by:
®%Ā # Remove any number that's divisible by the number we've saved
# i.e. [1,2,3,4,5,6,7,8,9,10,11,12] and 4 → [1,2,3,5,6,7,9,10,11]
< # Decrease each by 1 (to make it 0-indexed)
# i.e. [1,2,3,5,6,7,9,10,11] → [0,1,2,3,5,6,7,9,10]
Ω # Take a random item from this list
# i.e. [0,1,2,3,5,6,7,9,10] → 6
ǝ # Replace the character at this (0-indexed) position with the digit
# i.e. "uovqxrcijfgyzlbp" and 3 and 6 → "uovqxr3ijfgyzlbp"
®ô # Split the string into parts of length equal to the number we've saved
# i.e. "uovqxr3ijfgyzlbp" and 4 → ["uovq","xr3i","jfgy","zlbp"]
» # Join them by new-lines (this is done implicitly in the legacy version)
# i.e. ["uovq","xr3i","jfgy","zlbp"] → "uovq\nxr3i\njfgy\nzlbp"
¹Éi # If the input is odd:
# i.e. 7 → 1 (truthy)
.º # Intersect mirror the individual items
# i.e. "uovq\nxr3i\njfgy\nzlbp"
# → "uovqvou\nxr3i3rx\njfgygfj\nzlbpblz"
.∊ # And intersect vertically mirror the whole thing
# i.e. "uovqvou\nxr3i3rx\njfgygfj\nzlbpblz"
# → "uovqvou\nxr3i3rx\njfgygfj\nzlbpblz\njfgygfj\nxr3i3rx\nuovqvou"
ë # Else (input was even):
º∊ # Do the same, but with non-intersecting mirrors