How to resolve the algorithm 100 prisoners step by step in the Arturo programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm 100 prisoners step by step in the Arturo 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 Arturo programming language

Source code in the arturo programming language

unplanned: function [][
    drawers: shuffle @1..100
    every? 1..100 'x -> some? 1..50 => [x = sample drawers]
]

planned: function [][
    drawers: shuffle @1..100
    every? 1..100 'x [
        next: x
        some? 1..50 => [x = next: <= drawers\[next-1]]
    ]
]

test: function [f][
    count: enumerate 10000 => [call f []]
    print [f ~"|mul fdiv count 10000 100|%"]
]

test 'unplanned
test 'planned


  

You may also check:How to resolve the algorithm Walk a directory/Recursively step by step in the Lua programming language
You may also check:How to resolve the algorithm Variadic function step by step in the Quackery programming language
You may also check:How to resolve the algorithm Append a record to the end of a text file step by step in the PowerShell programming language
You may also check:How to resolve the algorithm Smith numbers step by step in the PL/M programming language
You may also check:How to resolve the algorithm Modular exponentiation step by step in the Raku programming language