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

Recommended Answers

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

Jump to Post

All 2 Replies

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.