(0) Obligation:
Clauses:
test_snake(Pattern, C, R) :- ','(s2l(C, Cols), ','(s2l(R, Rows), snake(Pattern, Cols, Rows))).
s2l(0, []).
s2l(s(X), .(X1, Y)) :- s2l(X, Y).
snake(Pattern, Cols, Rows) :- ','(infinite_snake(Pattern, InfSnake, InfSnake), ','(produce_snake(Rows, Cols, InfSnake, Snake), coil_it(Snake, odd))).
infinite_snake([], S, S).
infinite_snake(.(A, R), .(A, T), S) :- infinite_snake(R, T, S).
produce_snake([], X2, X3, []).
produce_snake(.(X4, Rows), Cols, InfSnake, .(Part, Tail)) :- ','(part_of_snake(Cols, InfSnake, NewInfSnake, Part), produce_snake(Rows, Cols, NewInfSnake, Tail)).
part_of_snake([], RestSnake, RestSnake, []).
part_of_snake(.(X5, R), .(Ring, Rings), RestSnake, .(Ring, RestRings)) :- part_of_snake(R, Rings, RestSnake, RestRings).
coil_it([], X6).
coil_it(.(Line, Lines), odd) :- coil_it(Lines, even).
coil_it(.(Line, Lines), even) :- ','(reverse2(Line, Line1), coil_it(Lines, odd)).
reverse2(List, Reversed) :- reverse(List, [], Reversed).
reverse([], Reversed, Reversed).
reverse(.(Head, Tail), SoFar, Reversed) :- reverse(Tail, .(Head, SoFar), Reversed).
Queries:
test_snake(g,g,g).