Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
45
Task/100-prisoners/Pointless/100-prisoners.pointless
Normal file
45
Task/100-prisoners/Pointless/100-prisoners.pointless
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
optimalSeq(drawers, n) =
|
||||
iterate(ind => drawers[ind - 1], n)
|
||||
|> takeUntil(ind => drawers[ind - 1] == n)
|
||||
|
||||
optimalTrial(drawers) =
|
||||
range(1, 100)
|
||||
|> map(optimalSeq(drawers))
|
||||
|
||||
randomSeq(drawers, n) =
|
||||
iterate(ind => randRange(1, 100), randRange(1, 100))
|
||||
|> takeUntil(ind => drawers[ind - 1] == n)
|
||||
|
||||
randomTrial(drawers) =
|
||||
range(1, 100)
|
||||
|> map(randomSeq(drawers))
|
||||
|
||||
checkLength(seq) =
|
||||
length(take(51, seq)) <= 50
|
||||
|
||||
numTrials = 3000
|
||||
|
||||
runTrials(trialFunc) =
|
||||
for t in range(1, numTrials)
|
||||
yield
|
||||
range(1, 100)
|
||||
|> shuffle
|
||||
|> toArray
|
||||
|> trialFunc
|
||||
|> map(checkLength)
|
||||
|> all
|
||||
|
||||
countSuccess(trialFunc) =
|
||||
runTrials(trialFunc)
|
||||
|> filter(id)
|
||||
|> length
|
||||
|
||||
optimalCount = countSuccess(optimalTrial)
|
||||
randomCount = countSuccess(randomTrial)
|
||||
|
||||
output =
|
||||
format("optimal: {} / {} = {} prob\nrandom: {} / {} = {} prob", [
|
||||
optimalCount, numTrials, optimalCount / numTrials,
|
||||
randomCount, numTrials, randomCount / numTrials,
|
||||
])
|
||||
|> println
|
||||
Loading…
Add table
Add a link
Reference in a new issue