小编kat*_*her的帖子

第一个更大(常见)的lisp程序 - >'随机'不按预期工作

为了好玩,我在Python中编写了一个关于"monty hall问题"的模拟.后来我尝试了Lua,并决定再次在Lua中编写它,看看它的外观如何.这是一个非常有趣的体验,即使程序看起来非常相似(Lua版本略短).最近我开始用CL进行表演,并希望再次做同样的事情.但是当我运行它时,它的行为并不像预期的那样.出于某种原因,不稳定的球员(谁应该获得66%的获胜机会)与天真球员的得分几乎相同(有50%的几率获胜).

有人可以给我一个暗示出了什么问题吗?这不是一个家庭作业或类似的东西,只是我第一次尝试用CL写一个更大的程序.除了上述问题的提示外,我还欢迎有关如何改进我的风格的建议.我猜它仍然是Python-ish(它或多或少是直接翻译).

(defun choose-one (l)
  "Ramdomly chooses one element of the given list"
  (nth (random (length l)) l))

(defun remove-one (l)
  "Randomly removes one element of the given list"
  (remove (choose-one l) l))

(defun naive-player (initial-choice possible-choices)
  "The naive player randomly picks one choice. Should have a 50% chance to win."
  initial-choice ;keep compiler happy
  (choose-one possible-choices))

(defun stubborn-player (initial-choice possible-choices)
  "The stubborn player sticks with his initial choice. Should have a 33% chance to win."
  possible-choices …
Run Code Online (Sandbox Code Playgroud)

lisp clisp sbcl common-lisp

1
推荐指数
1
解决办法
231
查看次数

标签 统计

clisp ×1

common-lisp ×1

lisp ×1

sbcl ×1