Shuffling a list in PROLOG

倾然丶 夕夏残阳落幕 提交于 2021-02-11 15:03:26

问题


Simple question, how can I shuffle a list in PROLOG, so that A1 is my new list?

shuffle([1,1,1,2,3,4],A1),

I've tried a few predicates I found on the web but none of them seems to be working. Also found this but apparently it's not available anymore, according to SWI-PROLOG.


回答1:


You can use random_permutation/2. It is available in SWI-Prolog.

?- random_permutation([1,2,3],L).
L = [1, 3, 2].


来源:https://stackoverflow.com/questions/27431281/shuffling-a-list-in-prolog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!