Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View 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