| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- (*
- adapted to Oberon-07 by 0CodErr, KolibriOS team
- *)
- (*
- Produce a spiral array.
- A spiral array is a square arrangement of the first (Width * Height) natural numbers,
- where the numbers increase sequentially as you go around the edges of the array spiraling inwards.
- *)
- MODULE SpiralMatrix;
- IMPORT In, Out, Console;
- VAR
- Width, Height: INTEGER;
- PROCEDURE spiral(w, h, x, y: INTEGER): INTEGER;
- VAR
- res: INTEGER;
- BEGIN
- IF y # 0 THEN
- res := w + spiral(h - 1, w, y - 1, w - x - 1)
- ELSE
- res := x
- END
- RETURN res
- END spiral;
- PROCEDURE print_spiral(w, h: INTEGER);
- VAR
- i, j: INTEGER;
- BEGIN
- FOR i := 0 TO h - 1 DO
- FOR j := 0 TO w - 1 DO
- Out.Int(spiral(w, h, j, i), 4)
- END;
- Out.Ln
- END
- END print_spiral;
- BEGIN
- Console.open;
- Out.String("Input width of matrix(1, 2, 3, ...):"); In.Int(Width);
- Out.String("Input height of matrix:(1, 2, 3, ...)"); In.Int(Height);
- print_spiral(Width, Height);
- In.Ln;
- Console.exit(TRUE)
- END SpiralMatrix.
|