320 [Easy] Spiral Ascension - mmattioli/reddit-dailyprogrammer GitHub Wiki

Challenge details

Description

The user enters a number. Make a spiral that begins with 1 and starts from the top left, going towards the right, and ends with the square of that number.

Input description

Let the user enter a number.

Output description

Note the proper spacing in the below example. You'll need to know the number of digits in the biggest number. You may go for a CLI version or GUI version.

Challenge input

5

4

Challenge output

 1  2  3  4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9



 1  2  3  4 
12 13 14  5
11 16 15  6
10  9  8  7

Bonus

As a bonus, the code could take a parameter and make a clockwise or counter-clockwise spiral.

Credit

This challenge was suggested by /u/MasterAgent47 (with a bonus suggested by /u/JakDrako), many thanks to them both. If you would like, submit to /r/dailyprogrammer_ideas if you have any challenge ideas!


Notes, ideas, additional information

Reddit page