Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
37
Task/100-prisoners/Transd/100-prisoners.transd
Normal file
37
Task/100-prisoners/Transd/100-prisoners.transd
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#lang transd
|
||||
|
||||
MainModule: {
|
||||
simRandom: (λ numPris Int() nRuns Int()
|
||||
locals: nSucc 0.0
|
||||
(for n in Range(nRuns) do
|
||||
(with draws (for i in Range(numPris) project i) succ 1
|
||||
(for prisN in Range(numPris) do
|
||||
(shuffle draws)
|
||||
(if (not (is-el Range(in: draws 0 (/ numPris 2)) prisN))
|
||||
(= succ 0) break))
|
||||
(+= nSucc succ)
|
||||
) )
|
||||
(ret (* (/ nSucc nRuns) 100))
|
||||
),
|
||||
|
||||
simOptimal: (λ numPris Int() nRuns Int()
|
||||
locals: nSucc 0.0
|
||||
(for n in Range(nRuns) do
|
||||
(with draws (for i in Range(numPris) project i) succ 0 nextDraw 0
|
||||
(shuffle draws)
|
||||
(for prisN in Range(numPris) do (= nextDraw prisN) (= succ 0)
|
||||
(for i in Range( (/ numPris 2)) do
|
||||
(= nextDraw (get draws nextDraw))
|
||||
(if (== nextDraw prisN) (= succ 1) break))
|
||||
(if (not succ) break))
|
||||
(+= nSucc succ)
|
||||
) )
|
||||
(ret (* (/ nSucc nRuns) 100))
|
||||
),
|
||||
|
||||
_start: (λ
|
||||
(lout prec: 4 :fixed "Random play: " (simRandom 100 10000) "% of wins")
|
||||
(lout "Strategic play: " (simOptimal 100 10000) "% of wins")
|
||||
(lout "Check random play: " (simRandom 10 100000) "% of wins")
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue