interview question
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

před 4 roky
před 4 roky
před 4 roky
před 4 roky
před 4 roky
před 4 roky
před 4 roky
před 4 roky
před 4 roky
před 4 roky
před 4 roky
před 4 roky
před 4 roky
před 4 roky
před 4 roky
před 4 roky
před 4 roky
před 4 roky
před 4 roky
12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Spiral
  2. bad attempts at solving interview questions
  3. ## The Problem - Verbatim
  4. Write a small program which:
  5. accepts on the command line an odd number N
  6. outputs a sequence of numbers corresponding to the following steps:
  7. the numbers 1 through N^2 are written in a grid
  8. the first number in the sequence is the number in the center of the grid
  9. the subsequent numbers are found by spiraling out clockwise, starting to the right
  10. For example, for N = 3 we have the grid:
  11. ```
  12. 1 2 3
  13. 4 5 6
  14. 7 8 9
  15. ```
  16. So we start with 5, head right to 6, then down to 9, left through 8 and 7, up through 4 and 1 and finally right through 2 and 3. This gives the output:
  17. 5, 6, 9, 8, 7, 4, 1, 2, 3, end
  18. For N=5 the output should be:
  19. 13, 14, 19, 18, 17, 12, 7, 8, 9, 10, 15, 20, 25, 24, 23, 22, 21, 16, 11, 6, 1, 2, 3, 4, 5, end
  20. IMPORTANT: your solution should not make use of arrays or matrices of numbers. If you are unable to determine a way to solve it without arrays/matrices then a solution with them is better than no solution.
  21. ## Compiling and Running
  22. ```
  23. ghc -O2 -Wall Spiral.hs -o spiral
  24. ./spiral
  25. ```