16
2
Your task is to create a plain hunt (a bell ringing pattern) with n bells. An example with 6 bells:
123456
214365
241635
426153
462513
645231
654321
563412
536142
351624
315264
132546
123456
Each number "bounces" off the side of the grid. From Wikipedia:
Each bell moves one position at each succeeding change, unless they reach the first or last position, when they remain there for two changes then proceed to the other end of the sequence.
In other words, you swap the bells in adjacent pairs, alternating between taking pairs starting from the the first bell and from the second bell. (Thanks to @xnor for this explanation.) You finish in the same order as the start.
This rule be applied to any number of bells, taken as input. Standard loopholes are forbidden.
Test Cases
6
123456
214365
241635
426153
462513
645231
654321
563412
536142
351624
315264
132546
123456
3
123
213
231
321
312
132
123
2
12
21
21
12
1
1
0: Falls in to "I don't care" situation.
2Is the starting row always
1 ... n
or can it be in any order (e.g.2314
for n=4)? – nimi – 2019-10-16T19:09:12.357@nimi Always
1 ... n
– gadzooks02 – 2019-10-16T19:11:45.10071 is a special case since it doesn’t have separate start and end rows both equal to 1. Would it be permissible to return
1, 1
for the input of 1? – Nick Kennedy – 2019-10-16T19:54:23.7772Can I print in list form, like
[1,2,3,4]
or something similar? – Embodiment of Ignorance – 2019-10-16T20:12:51.373Can you add a test case for
n>9
? – Night2 – 2019-10-16T22:19:58.3074As a bell-ringer, having anything other than
2n
changes for plain hunt onn
triggers me... – Neil – 2019-10-16T23:12:55.0001Can we use 0..n-1 instead of 1..n? – Jonah – 2019-10-16T23:56:24.037
8
I agree that the
– xnor – 2019-10-17T02:13:12.447n=1
test case having one entry seems out of place. For all the rest, we only checking if we've returned to the start after the first change, since otherwise the first line of course equals itself and we'd stop immediately. So, that would gives[[1], [1]]
You could also consider puttingn=1
under "don't care" to avoid a potential edge case.