39
Reading a book is easy, but printing a book can be a bit tricky. When printing a booklet, the printer needs to have the pages arranged in a certain manner in order to be read from left to right. The way this is done is using a pattern like below
n, 1, 2, n-1, n-2, 3, 4, n-3, n-4, 5, 6, n-5, n-6, 7, 8, n-7, n-8, 9, 10, n-9, n-10, 11, 12, n-11…
Test Cases
4 page booklet: 4, 1, 2, 3
8 page booklet: 8,1,2,7,6,3,4,5
12 page booklet: 12,1,2,11,10,3,4,9,8,5,6,7
16 page booklet: 16,1,2,15,14,3,4,13,12,5,6,11,10,7,8,9
20 page booklet: 20,1,2,19,18,3,4,17,16,5,6,15,14,7,8,13,12,9,10,11
Task
Your task is to, given an integer n
that is a multiple of 4, display an array of numbers that could be used to print a book of n
pages.
Note: As long as the output generates the correct numbers, whether delimited by spaces, commas, hyphens, or parenthesis, any method to getting to a solution can be used
This is a code-golf question so answers will be scored in bytes, with the fewest bytes winning.
Are we guaranteed that input will always be divisible by 4 or even an even number? Either way, could you add a few more test cases, please? And welcome to PPCG :) – Shaggy – 2017-08-06T23:51:47.507
8
Welcome to PPCG and nice first challenge! Note that we recommend proposing new challenges in the sandbox before posting them.
– Oliver Ni – 2017-08-06T23:57:39.1371Your input needs to be a multiple of 4 – tisaconundrum – 2017-08-06T23:57:59.430
Can I have a trailing comma in the output? – TheLethalCoder – 2017-08-07T10:14:34.853
1Would be nice (but maybe trivial) to support any value, filling with blank pages if needed (another challenge, maybe?) – Barranka – 2017-08-07T14:56:20.370
1Can we delimit the array with a space, hyphen, or other delimiter instead of a comma? – TehPers – 2017-08-07T20:01:57.223
Can we create a function to generate this sequence, or does the final result need to print to standard output? That is, are we allowed to create a function instead so that when you call the function and print its output, it will show the correct sequence? I see a lot of answers doing that already (including one of my answers), but it is not explicitly said we can in the objectives. – rayryeng - Reinstate Monica – 2017-08-08T13:06:16.930
Smallest byte wins and method to getting there can be used, as long as the output generates the correct numbers, whether delimited by spaces, commas, hyphens, or parenthesis. – tisaconundrum – 2017-08-08T20:40:39.130