Skip to content

lysenko/test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

test

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

About

Yet another job interview test

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages