World Cup group stage: Difference between revisions

m
→‎version 2, generated game sets: added/changed whitespace, changed some comments.
m (→‎version 2, generated game sets: added/changed whitespace, changed some comments.)
Line 883:
{{trans|Java}}
{{trans|REXX}}
 
 
This REXX version allows the number of teams to be specified to be used in the calculations,   and
Line 933 ⟶ 932:
z= 1; setLimit= copies(2, sets) /*Z: max length of any number shown. */
say teams ' teams, ' sets " game sets: " gs /*display what's being used for calcs. */
results = copies(0, sets); say say /*start with left-most teams all losing*/
points. = 0 /*zero all the team's point. */
do until \nextResult(results); @.= 0
do j=1 for sets; r= substr( results, j, 1)
parse var games.j A +1 B /*get the A and B teams*/
if r==0 then @.B= @.B + win /*win for right─most team.*/
Line 943 ⟶ 942:
end /*j*/
call sort teams
do t=1 for teams; tm= t - 1; _= @.t
points.tm._ = points.tm._ + 1; z= max(z, length( points.tm._) )
end /*t*/
end /*until*/
$.=
do j=0 for teams+6
do k=0 for teams; $.k= $.k || right( points.k.j, z)'│ '; end /*k*/
end /*j*/
say; /* [↓] build grid line for the box*/
L= length($.1) -2; $$= translate( translate( left($.1, L), , 0123456789), '─', " ")
say left('', 15) center('points', L) /*display the boxed title. */
say left('', 15) "╔"translate($$, '═╤', "─│")'╗' /*display the bottom sep for title.*/
p= 0
do m=teams-1 by -1 for teams; p = p+1
say right('('th(p) "place)", 14) " ║"left($.m, L)'║'
if m>0 then say right(' ', 14) " ╟"translate($$, '┼', "│")'╢'
end /*m*/
say left('', 15) "╚"translate( $$, '═╧', "─│")'╝' /*display the bottom sep for title.*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
nextResult: if results==setLimit then return 0 /* [↓] do arithmetic in base three. */
res= 0; do k=1 for sets; res= res * 3 + substr( results, k, /* [↓] do arithmetic in base three.*/1)
do k=1 for sets; res= res * 3 + substr(results, k, 1)
end /*j*/
results=; res= res + 1
do sets; results= res // 3 || results; res= res % 3
end /*sets*/; return 1
return 1
/*──────────────────────────────────────────────────────────────────────────────────────*/
sort: procedure expose @.; arg #; do j=1 for #-1 /*a bubble sort, ascending order.*/