World Cup group stage: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
m (→‎version 2, generated game sets: added comments, changed a literal definition style.)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 1:
{{outtask}}
{{task}}It's World Cup season (or at least it was when this page was created)! The World Cup is an international football/soccer tournament that happens every 4 years. Countries put their international teams together in the years between tournaments and qualify for the tournament based on their performance in other international games. Once a team has qualified they are put into a group with 3 other teams. For the first part of the World Cup tournament the teams play in "group stage" games where each of the four teams in a group [[wp:Round-robin tournament|plays all three other teams once]]. The results of these games determine which teams will move on to the "knockout stage" which is a standard single-elimination tournament. The two teams from each group with the most standings points move on to the knockout stage. Each game can result in a win for one team and a loss for the other team or it can result in a draw/tie for each team. A win is worth three points in the standings. A draw/tie is worth one point. A loss is not worth any points.
 
{{task}}It's World Cup season (or at least it was when this page was created)! The World Cup is an international football/soccer tournament that happens every 4 years. Countries put their international teams together in the years between tournaments and qualify for the tournament based on their performance in other international games. Once a team has qualified they are put into a group with 3 other teams. For the first part of the World Cup tournament the teams play in "group stage" games where each of the four teams in a group [[wp:Round-robin tournament|plays all three other teams once]]. The results of these games determine which teams will move on to the "knockout stage" which is a standard single-elimination tournament. The two teams from each group with the most standings points move on to the knockout stage. Each game can result in a win for one team and a loss for the other team or it can result in a draw/tie for each team. A win is worth three points in the standings. A draw/tie is worth one point. A loss is not worth any points.
 
Generate all possible outcome combinations for the six group stage games. With three possible outcomes for each game there should be 3<sup>6</sup> = 729 of them. Calculate the standings points for each team with each combination of outcomes. Show a histogram (graphical, ASCII art, or straight counts--whichever is easiest/most fun) of the standings points for all four teams over all possible outcomes.
Line 669 ⟶ 671:
$fmt = ('%3d ') x 10 . "\n";
printf $fmt, @$_ for reverse @histo;</lang>
{{out}}
<pre> 0 0 0 1 14 148 152 306 0 108
0 0 4 33 338 172 164 18 0 0
0 18 136 273 290 4 8 0 0 0
108 306 184 125 6 0 0 0 0 0</pre>
 
=={{header|Perl 6}}==
{{Works with|rakudo|2016.12}}
{{trans|Python}}
<lang perl6>constant scoring = 0, 1, 3;
my @histo = [0 xx 10] xx 4;
 
for [X] ^3 xx 6 -> @results {
my @s;
 
for @results Z (^4).combinations(2) -> ($r, @g) {
@s[@g[0]] += scoring[$r];
@s[@g[1]] += scoring[2 - $r];
}
 
for @histo Z @s.sort -> (@h, $v) {
++@h[$v];
}
 
say .fmt('%3d',' ') for @histo.reverse;</lang>
{{out}}
<pre> 0 0 0 1 14 148 152 306 0 108
Line 853 ⟶ 829:
Sack the manager: 0 18 136 273 290 4 8 0 0 0
Sack the team! 108 306 184 125 6 0 0 0 0 0 </pre>
 
=={{header|Perl 6Raku}}==
(formerly Perl 6)
{{Works with|rakudo|2016.12}}
{{trans|Python}}
<lang perl6>constant scoring = 0, 1, 3;
my @histo = [0 xx 10] xx 4;
 
for [X] ^3 xx 6 -> @results {
my @s;
 
for @results Z (^4).combinations(2) -> ($r, @g) {
@s[@g[0]] += scoring[$r];
@s[@g[1]] += scoring[2 - $r];
}
 
for @histo Z @s.sort -> (@h, $v) {
++@h[$v];
}
 
say .fmt('%3d',' ') for @histo.reverse;</lang>
{{out}}
<pre> 0 0 0 1 14 148 152 306 0 108
0 0 4 33 338 172 164 18 0 0
0 18 136 273 290 4 8 0 0 0
108 306 184 125 6 0 0 0 0 0</pre>
 
=={{header|REXX}}==
Line 1,126 ⟶ 1,129:
3 : 0 18 136 273 290 4 8 0 0 0
4 : 108 306 184 125 6 0 0 0 0 0</pre>
 
=={{header|Scala}}==
<lang Scala>object GroupStage extends App { //team left digit vs team right digit
10,333

edits