0

Hi, I have an assignment. I need to write code in logic programming language SWI-Prolog.
Its very hard and I am going to appreciate if you help me :D.

This is the assigment:

Print 2D array size of (width x height) in spiral order.

More explanation and example:
You have input, width and height that are integers.
With this input program needs to print a matrix "spiral" of numbers, from 1 to (height x width).
Height is size of column in "spiral" matrix
Width is size of row in "spiral" matrix

This is just an example:

spiralmatrix(w,h). /*w - width, h - height


Input:

?-spiralmatrix(5,4)

Output:

1  2  3  4  5
14 15 16 17 6
13 20 19 18 7
12 11 10 9  8

/* spacing in this matrix doesn't matter
3
Contributors
2
Replies
39
Views
2 Years
Discussion Span
Last Post by pyTony
0

If you don't have it, you should get Clocksin and Mellish's book on Prolog programming. It is the "Prolog Bible"...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.