查看: 1302|回复: 4
|
PROLOG 高手请看这边!!紧急!
[复制链接]
|
|
想问看PROLOG高手,以下题目应该要怎样写code?
?- show(5).
++++1
+++12
++123
+1234
12345
谢谢高手!
|
|
|
|
|
|
|
|
发表于 15-11-2013 05:48 PM
|
显示全部楼层
- show(0).
- show(N) :- N > 0, Plusno is N-1, Max is N-Plusno, writePlus(Plusno), writeDigit(Max), C is Max+1, nl, showAux(N, C). /*recursive call*/
- showAux(N, M) :- P is N-M, writePlus(P), writeDigit(M), C is M+1, nl, showAux(N, C).
- writeDigit(0).
- writeDigit(A) :- A > 0, write(A), B is A-1, writeDigit(B).
- writePlus(0).
- writePlus(M) :- M > 0, write('+'), N is M-1, writePlus(N).
复制代码 逻辑上,这个应该works on Sictus Prolog. Sorry, I don't have Sictus Prolog on my computer now. I can't test if it works.
The code is only for your reference. Just a reminder, plagiarism is a serious offense. :p
本帖最后由 Less-Wronger 于 15-11-2013 06:36 PM 编辑
|
|
|
|
|
|
|
|

楼主 |
发表于 15-11-2013 06:56 PM
|
显示全部楼层
Less-Wronger 发表于 15-11-2013 05:48 PM 
逻辑上,这个应该works on Sictus Prolog. Sorry, I don't have Sictus Prolog on my computer now. I can' ...
哈哈哈~
没有抄袭啦~
也已经随便做交上去了~~
我是使用 LPA Prolog 的
anyway~ 谢谢你! |
|
|
|
|
|
|
|
发表于 16-11-2013 10:17 PM
|
显示全部楼层
janet92 发表于 15-11-2013 06:56 PM 
哈哈哈~
没有抄袭啦~
也已经随便做交上去了~~
你的功课比我的看起来更有趣;虽然我的Prolog功课比较困难,we had to program stack/turing machine.
Qing Wen LPA有 write function ma?
Sorry, using google translate, some words couldn't translate properly, so I use han yu pin ying.
|
|
|
|
|
|
|
|

楼主 |
发表于 22-11-2013 11:44 AM
|
显示全部楼层
Less-Wronger 发表于 16-11-2013 10:17 PM 
你的功课比我的看起来更有趣;虽然我的Prolog功课比较困难,we had to program stack/turing machine.
...
抱歉哦~迟回复
写fact和rules罢了咯~ 有function的东西?
p/s: 你电脑没有install华语吗?
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|