Yet another job interview test.
Write a program in Ruby that takes one command line argument (referred to going forward as n). If n is not a perfect square print an appropriate error message and exit. If n is a perfect square then create a sequence from 1 to n and build a matrix from the sequence by walking in counter-clockwise spiral order. Examples below illustrate this for n=1,4,9,16 but your solution should work for any n that is a perfect square. Once you have built the matrix print it, ensuring even column widths as in examples below and then exit.
Input: 1 Output: 1
Input: 4 Output: 4 3 1 2
Input: 9 Output: 5 4 3 6 1 2 7 8 9
Input: 16 Output: 16 15 14 13 5 4 3 12 6 1 2 11 7 8 9 10