Spirals
InterviewTime limit1sMemory limit128 MB
Place the numbers x through y into a square-ish grid spiraling counter-clockwise outward from x at the center, then print the grid with numbers right-aligned to the width of y.
- Level
Medium4 of 10
- Topics
- Matrix, Simulation, Implementation
- Solved
- No attempts yet
Problem
You are given two positive integers and , both less than . Print the integers from to inclusive, laid out in a spiral. You may assume that the end value is greater than or equal to the start value .
The spiral begins with the first number in the centre. The next number is placed immediately below the first number. From there the numbers keep increasing by , winding outward in a counter-clockwise direction, until the last number has been placed.
Input
The first line contains the start value ; the second line contains the end value . Both are positive integers less than , and .
Output
Print the grid of numbers from to arranged in the spiral. Within each row the numbers are separated by a single space, and every number is right-aligned to the width of the largest number (that is, , by its digit count).