World Cup group stage: Difference between revisions

Content added Content deleted
Line 216: Line 216:
{{trans|Java}}
{{trans|Java}}
ELENA 3.4 :
ELENA 3.4 :
<lang elena>import system'routines.
<lang elena>import system'routines;
import extensions.
import extensions;
public program =
public singleton program
{
{
static games := ("12", "13", "14", "23", "24", "34").
static games := new string[]{"12", "13", "14", "23", "24", "34"};
static results := "000000".
static results := "000000";
nextResult
nextResult()
[
{
if (results=="222222") [ ^ false ].
if (results=="222222") { ^ false };
results := (results toInt(3) + 1) toLiteral(3); padLeft($48, 6).
results := (results.toInt(3) + 1).toString(3).padLeft($48, 6);
^ true
^ true
]
}
closure
closure()
[
{
var points := IntMatrix new(4, 10).
var points := new IntMatrix(4, 10);

doUntil(program.nextResult().Inverted)
{
var records := new int[](4);
for(int i := 0, i < 6, i += 1)
[
var records := IntArray new(4).
{
var r := results[i];
r =>
"2" { records[games[i][0].toInt() - 49] += 3 }
"1" {
records[games[i][0].toInt() - 49] += 1;
records[games[i][1].toInt() - 49] += 1
}
"0" { records[games[i][1].toInt() - 49] += 3 };
};
0 till:6 do(:i)
records := records.ascendant();
[
(results[i]) =>
"2" [ records[games[i][0] toInt - 49] += 3 ];
"1" [
records[games[i][0] toInt - 49] += 1.
records[games[i][1] toInt - 49] += 1
];
"0" [ records[games[i][1] toInt - 49] += 3 ].
].
records := records ascendant.
for(int i := 0, i <= 3, i += 1) { points[i][records[i]] += 1 }
};
new Range(0, 4).zipForEach(new string[]{"1st", "2nd", "3rd", "4th"}, (i,l)
0 to:3 do(:i)[ (points[i][records[i]]) += 1 ].
{
console.printLine(l,": ", points[3 - i].toArray())
] repeatWhile:$(self nextResult).
});
}
0 repeatTill:4; zip:("1st", "2nd", "3rd", "4th") forEach(:i:l)
}</lang>
[
arrayConvertorEx convert(points[3 - i]).
console printLine(l,": ", points[3 - i] toArray)
].
]
}.</lang>
{{out}}
{{out}}
<pre>
<pre>