How to resolve the algorithm 100 prisoners step by step in the Pointless programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm 100 prisoners step by step in the Pointless programming language
Table of Contents
Problem Statement
Show and compare the computed probabilities of success for the two strategies, here, on this page.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm 100 prisoners step by step in the Pointless programming language
Source code in the pointless programming language
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
You may also check:How to resolve the algorithm Luhn test of credit card numbers step by step in the ABAP programming language
You may also check:How to resolve the algorithm Quine step by step in the PowerShell programming language
You may also check:How to resolve the algorithm Idiomatically determine all the lowercase and uppercase letters step by step in the Raku programming language
You may also check:How to resolve the algorithm Inheritance/Multiple step by step in the Clojure programming language
You may also check:How to resolve the algorithm Check that file exists step by step in the Pop11 programming language