且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

实现计数器序言

更新时间:2023-12-02 16:18:46

我检查了@Otrebor 提供的链接,并想出了一个很好的解决方案.我忘记了绑定时无法更改变量的小"细节,因此我添加了一个额外的.这是它的外观:

I examined the link which @Otrebor provided and I came up with a fine solution. I forgot the "little" detail that when bound, a variable can't be changed, thus I added an extra one. Here's how it looks:

printBoard([], _).
printBoard([Head|Tail], Counter) :-
        Index is Counter + 1,
        write('    '), write(Index), write('  |'), write(' '),
        printRow(Head),
        printBoard(Tail, Index).

main :- printBoard(Board, 0).