Rosetta Code/Tasks without examples: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Raku}}: New URL for relocated site) |
m (→{{header|Wren}}: Updated site URL and output.) |
||
Line 937: | Line 937: | ||
} |
} |
||
var url = " |
var url = "https://rosettacode.org/wiki/Category:Programming_Tasks" |
||
var content = getContent.call(url) |
var content = getContent.call(url) |
||
var p1 = Pattern.new("<li><a href/=\"//wiki//[+1^\"]\"") |
var p1 = Pattern.new("<li><a href/=\"//wiki//[+1^\"]\"") |
||
Line 944: | Line 944: | ||
var tasks = matches.map { |m| m.capsText[0] }.toList |
var tasks = matches.map { |m| m.capsText[0] }.toList |
||
for (task in tasks.take(3)) { // just show the first 3 say |
for (task in tasks.take(3)) { // just show the first 3 say |
||
var taskUrl = " |
var taskUrl = "https://rosettacode.org/wiki/" + task |
||
var html = getContent.call(taskUrl) |
var html = getContent.call(taskUrl) |
||
var text = "using any language you may know.</div>" |
var text = "using any language you may know.</div>" |
||
Line 1,154: | Line 1,154: | ||
****** 100 doors ****** |
****** 100 doors ****** |
||
There are 100 doors in a row that are all initially closed. |
There are 100 doors in a row that are all initially closed. |
||
You make 100 passes by the doors. |
You make 100 passes by the doors. |
||
The first time through, visit every door and toggle the door (if the door is closed, open it; if it is open, close it). |
The first time through, visit every door and toggle the door (if the door is closed, open it; if it is open, close it). |
||
The second time, only visit every 2nd door (door #2, #4, #6, ...), and toggle it. |
The second time, only visit every 2nd door (door #2, #4, #6, ...), and toggle it. |
||
The third time, visit every 3rd door (door #3, #6, #9, ...), etc, until you only visit the 100th door. |
The third time, visit every 3rd door (door #3, #6, #9, ...), etc, until you only visit the 100th door. |
||
Line 1,165: | Line 1,165: | ||
Answer the question: what state are the doors in after the last pass? Which are open, which are closed? |
Answer the question: what state are the doors in after the last pass? Which are open, which are closed? |
||
Alternate: |
Alternate: |
||
As noted in this page's discussion page, the only doors that remain open are those whose numbers are perfect squares. |
As noted in this page's discussion page, the only doors that remain open are those whose numbers are perfect squares. |
||
Opening only those doors is an optimization that may also be expressed; |
Opening only those doors is an optimization that may also be expressed; |
||
however, as should be obvious, this defeats the intent of comparing implementations across programming languages. |
however, as should be obvious, this defeats the intent of comparing implementations across programming languages. |
||
Line 1,174: | Line 1,174: | ||
The Problem |
The Problem |
||
100 prisoners are individually numbered 1 to 100 |
|||
A room having a cupboard of 100 opaque drawers numbered 1 to 100, that cannot be seen from outside. |
|||
Cards numbered 1 to 100 are placed randomly, one to a drawer, and the drawers all closed; at the start. |
|||
Prisoners start outside the room |
|||
They can decide some strategy before any enter the room. |
|||
Prisoners enter the room one by one, can open a drawer, inspect the card number in the drawer, then close the drawer. |
|||
A prisoner can open no more than 50 drawers. |
|||
A prisoner tries to find his own number. |
|||
A prisoner finding his own number is then held apart from the others. |
|||
If all 100 prisoners find their own numbers then they will all be pardoned. If any don't then all sentences stand. |
|||
The task |
The task |
||
Simulate several thousand instances of the game where the prisoners randomly open drawers |
|||
Simulate several thousand instances of the game where the prisoners use the optimal strategy mentioned in the Wikipedia article, of: |
|||
First opening the drawer whose outside number is his prisoner number. |
|||
If the card within has his number then he succeeds otherwise he opens the drawer with the same number as that of the revealed card. (until he opens his maximum). |
|||
Show and compare the computed probabilities of success for the two strategies, here, on this page. |
Show and compare the computed probabilities of success for the two strategies, here, on this page. |
||
Line 1,198: | Line 1,198: | ||
References |
References |
||
The unbelievable solution to the 100 prisoner puzzle standupmaths (Video). |
|||
wp:100 prisoners problem |
|||
100 Prisoners Escape Puzzle DataGenetics. |
|||
Random permutation statistics#One hundred prisoners on Wikipedia. |
|||
****** 15 puzzle game ****** |
****** 15 puzzle game ****** |
||
Line 1,209: | Line 1,209: | ||
Implement the Fifteen Puzzle Game. |
Implement the Fifteen Puzzle Game. |
||
The 15-puzzle is also known as: |
The 15-puzzle is also known as: |
||
Fifteen Puzzle |
|||
Gem Puzzle |
|||
Boss Puzzle |
|||
Game of Fifteen |
|||
Mystic Square |
|||
14-15 Puzzle |
|||
and some others. |
|||
Related Tasks |
Related Tasks |
||
15 Puzzle Solver |
|||
16 Puzzle Game |
|||
</pre> |
</pre> |
||