Rosetta Code/Tasks without examples: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 157:
sleep 10; # so you have time to read each task...
}</lang>
 
=={{header|Perl 6}}==
{{works with|Rakudo|2017.10}}
 
<lang perl6>use HTTP::UserAgent;
use Gumbo;
 
my $ua = HTTP::UserAgent.new;
my $taskfile = './RC_tasks.html';
 
# Get list of Tasks
say "Updating Programming_Tasks list...";
my $page = "http://rosettacode.org/wiki/Category:Programming_Tasks";
my $html = $ua.get($page).content;
my $xmldoc = parse-html($html, :TAG<div>, :id<mw-pages>);
my @tasks = parse-html($xmldoc[0].Str, :TAG<li>).Str.comb( /'/wiki/' <-["]>+ / )».substr(6); #"
my $f = open("./RC_Programming_Tasks.txt", :w) or die "$!\n";
note "Writing Programming_Tasks file...";
$f.print( @tasks.join("\n") );
$f.close;
 
sleep .5;
 
for 'Programming_Tasks' -> $category
{ # Scrape info from each page.
 
note "Loading $category file...";
note "Retreiving tasks...";
my @entries = "./RC_{$category}.txt".IO.slurp.lines;
 
for @entries -> $title {
note $title;
 
# Get the raw page
my $html = $ua.get: "http://rosettacode.org/wiki/{$title}";
 
# Filter out the actual task description
$html.content ~~ m|'<div id="mw-content-text" lang="en" dir="ltr" class="mw-content-ltr"><div'
.+? 'using any language you may know.</div>' (.+?) '<div id="toc"'|;
 
my $task = cleanup $0.Str;
 
# save to a file
my $fh = $taskfile.IO.open :a;
 
$fh.put: "<hr>\n $title\n<hr>\n$task";
 
$fh.close;
 
sleep 3; # Don't pound the server
}
}
 
sub cleanup ( $string ) {
$string.subst( /^.+ '</div>'/, '' )
}</lang>
{{out|Abridged sample output}}
<div style="border-style: groove; margin: 50px; padding: 25px;">
<hr>
100_doors
<hr>
 
<p>There are 100 doors in a row that are all initially closed.
</p><p>You make 100 <a href="/wiki/Rosetta_Code:Multiple_passes" title="Rosetta Code:Multiple passes">passes</a> by the doors.
</p><p>The first time through, visit every door and &#160;<i>toggle</i>&#160; the door &#160;(if the door is closed, &#160;open it; &#160; if it is open,&#160; close it).
</p><p>The second time, only visit every 2<sup>nd</sup> door &#160; (door #2, #4, #6, ...), &#160; and toggle it.
</p><p>The third time, visit every 3<sup>rd</sup> door &#160; (door #3, #6, #9, ...), etc, &#160; until you only visit the 100<sup>th</sup> door.
</p><p><br />
</p>
<dl><dt>Task</dt>
<dd></dd></dl>
<p>Answer the question: &#160; what state are the doors in after the last pass? &#160; Which are open, which are closed?
</p><p><br />
<b><a href="/wiki/Rosetta_Code:Extra_credit" title="Rosetta Code:Extra credit">Alternate</a>:</b>
As noted in this page's &#160; <a href="/wiki/Talk:100_doors" title="Talk:100 doors">discussion page</a>, &#160; the only doors that remain open are those whose numbers are perfect squares.
</p><p>Opening only those doors is an &#160; <a href="/wiki/Rosetta_Code:Optimization" title="Rosetta Code:Optimization">optimization</a> &#160; that may also be expressed;
however, as should be obvious, this defeats the intent of comparing implementations across programming languages.
<br /><br />
</p>
 
<hr>
15_Puzzle_Game
<hr>
 
<dl><dt>Task</dt>
<dd></dd></dl>
<p>Implement the <a href="http://en.wikipedia.org/wiki/15_puzzle" class="extiw" title="wp:15 puzzle">Fifteen Puzzle Game</a>.
<br /><br />
</p>
<dl><dt>Related Task</dt>
<dd></dd></dl>
<ul><li> <a href="/wiki/15_puzzle_solver" title="15 puzzle solver">15 Puzzle Solver</a></li></ul>
<p><br /><br />
</p>
 
<hr>
15_puzzle_solver
<hr>
 
<p>Your task is to write a program that finds a solution in the fewest single moves (no multimoves) possible to a random <a href="http://en.wikipedia.org/wiki/15_puzzle" class="extiw" title="wp:15 puzzle">Fifteen Puzzle Game</a>.<br />
For this task you will be using the following puzzle:<br />
</p>
<pre>15 14 1 6
9 11 4 12
0 10 7 3
13 8 5 2</pre>
<p><br />
</p>
Solution:<pre> 1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 0
</pre>
<p>The output must show the moves' directions, like so: left, left, left, down, right... and so on.<br />
There are 2 solutions with 52 moves:<br />
rrrulddluuuldrurdddrullulurrrddldluurddlulurruldrdrd<br />
rrruldluuldrurdddluulurrrdlddruldluurddlulurruldrrdd<br />
finding either one, or both is an acceptable result.<br />
see: <a rel="nofollow" class="external text" href="http://www.rosettacode.org/wiki/15_puzzle_solver/Optimal_solution">Pretty Print of Optimal Solution</a>
</p>
<dl><dt>Extra credit.</dt></dl>
<p>Solve the following problem:
</p>
<pre> 0 12 9 13
15 11 10 14
3 7 2 5
4 8 6 1
</pre>
<p><br />
</p>
<dl><dt>Related Task</dt>
<dd></dd></dl>
<ul><li> <a href="/wiki/15_Puzzle_Game" title="15 Puzzle Game">15 puzzle game</a></li></ul>
<p><br /><br /><b>...and so on... </b>
</p>
</div>
 
 
=={{header|Phix}}==
Line 491 ⟶ 354:
?"done"
{} = wait_key()</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2017.10}}
 
<lang perl6>use HTTP::UserAgent;
use Gumbo;
 
my $ua = HTTP::UserAgent.new;
my $taskfile = './RC_tasks.html';
 
# Get list of Tasks
say "Updating Programming_Tasks list...";
my $page = "http://rosettacode.org/wiki/Category:Programming_Tasks";
my $html = $ua.get($page).content;
my $xmldoc = parse-html($html, :TAG<div>, :id<mw-pages>);
my @tasks = parse-html($xmldoc[0].Str, :TAG<li>).Str.comb( /'/wiki/' <-["]>+ / )».substr(6); #"
my $f = open("./RC_Programming_Tasks.txt", :w) or die "$!\n";
note "Writing Programming_Tasks file...";
$f.print( @tasks.join("\n") );
$f.close;
 
sleep .5;
 
for 'Programming_Tasks' -> $category
{ # Scrape info from each page.
 
note "Loading $category file...";
note "Retreiving tasks...";
my @entries = "./RC_{$category}.txt".IO.slurp.lines;
 
for @entries -> $title {
note $title;
 
# Get the raw page
my $html = $ua.get: "http://rosettacode.org/wiki/{$title}";
 
# Filter out the actual task description
$html.content ~~ m|'<div id="mw-content-text" lang="en" dir="ltr" class="mw-content-ltr"><div'
.+? 'using any language you may know.</div>' (.+?) '<div id="toc"'|;
 
my $task = cleanup $0.Str;
 
# save to a file
my $fh = $taskfile.IO.open :a;
 
$fh.put: "<hr>\n $title\n<hr>\n$task";
 
$fh.close;
 
sleep 3; # Don't pound the server
}
}
 
sub cleanup ( $string ) {
$string.subst( /^.+ '</div>'/, '' )
}</lang>
{{out|Abridged sample output}}
<div style="border-style: groove; margin: 50px; padding: 25px;">
<hr>
100_doors
<hr>
 
<p>There are 100 doors in a row that are all initially closed.
</p><p>You make 100 <a href="/wiki/Rosetta_Code:Multiple_passes" title="Rosetta Code:Multiple passes">passes</a> by the doors.
</p><p>The first time through, visit every door and &#160;<i>toggle</i>&#160; the door &#160;(if the door is closed, &#160;open it; &#160; if it is open,&#160; close it).
</p><p>The second time, only visit every 2<sup>nd</sup> door &#160; (door #2, #4, #6, ...), &#160; and toggle it.
</p><p>The third time, visit every 3<sup>rd</sup> door &#160; (door #3, #6, #9, ...), etc, &#160; until you only visit the 100<sup>th</sup> door.
</p><p><br />
</p>
<dl><dt>Task</dt>
<dd></dd></dl>
<p>Answer the question: &#160; what state are the doors in after the last pass? &#160; Which are open, which are closed?
</p><p><br />
<b><a href="/wiki/Rosetta_Code:Extra_credit" title="Rosetta Code:Extra credit">Alternate</a>:</b>
As noted in this page's &#160; <a href="/wiki/Talk:100_doors" title="Talk:100 doors">discussion page</a>, &#160; the only doors that remain open are those whose numbers are perfect squares.
</p><p>Opening only those doors is an &#160; <a href="/wiki/Rosetta_Code:Optimization" title="Rosetta Code:Optimization">optimization</a> &#160; that may also be expressed;
however, as should be obvious, this defeats the intent of comparing implementations across programming languages.
<br /><br />
</p>
 
<hr>
15_Puzzle_Game
<hr>
 
<dl><dt>Task</dt>
<dd></dd></dl>
<p>Implement the <a href="http://en.wikipedia.org/wiki/15_puzzle" class="extiw" title="wp:15 puzzle">Fifteen Puzzle Game</a>.
<br /><br />
</p>
<dl><dt>Related Task</dt>
<dd></dd></dl>
<ul><li> <a href="/wiki/15_puzzle_solver" title="15 puzzle solver">15 Puzzle Solver</a></li></ul>
<p><br /><br />
</p>
 
<hr>
15_puzzle_solver
<hr>
 
<p>Your task is to write a program that finds a solution in the fewest single moves (no multimoves) possible to a random <a href="http://en.wikipedia.org/wiki/15_puzzle" class="extiw" title="wp:15 puzzle">Fifteen Puzzle Game</a>.<br />
For this task you will be using the following puzzle:<br />
</p>
<pre>15 14 1 6
9 11 4 12
0 10 7 3
13 8 5 2</pre>
<p><br />
</p>
Solution:<pre> 1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 0
</pre>
<p>The output must show the moves' directions, like so: left, left, left, down, right... and so on.<br />
There are 2 solutions with 52 moves:<br />
rrrulddluuuldrurdddrullulurrrddldluurddlulurruldrdrd<br />
rrruldluuldrurdddluulurrrdlddruldluurddlulurruldrrdd<br />
finding either one, or both is an acceptable result.<br />
see: <a rel="nofollow" class="external text" href="http://www.rosettacode.org/wiki/15_puzzle_solver/Optimal_solution">Pretty Print of Optimal Solution</a>
</p>
<dl><dt>Extra credit.</dt></dl>
<p>Solve the following problem:
</p>
<pre> 0 12 9 13
15 11 10 14
3 7 2 5
4 8 6 1
</pre>
<p><br />
</p>
<dl><dt>Related Task</dt>
<dd></dd></dl>
<ul><li> <a href="/wiki/15_Puzzle_Game" title="15 Puzzle Game">15 puzzle game</a></li></ul>
<p><br /><br /><b>...and so on... </b>
</p>
</div>
 
=={{header|VBScript}}==
10,327

edits