Number reversal game: Difference between revisions

m
m (→‎{{header|Egel}}: updated to new syntax)
m (→‎{{header|Perl 6}}: fix markup)
Line 2,459:
Do-at-least-once loops are fairly rare, but this program wants to have two of them. We use the built-in <tt>.pick(*)</tt> method to shuffle the numbers. We use <tt>.=</tt> to dispatch a mutating method in two spots; the first is just a different way to write <tt>++</tt>, while the second of these reverses an array slice in place. The <tt>[<]</tt> is a reduction operator on less than, so it returns true if the elements of the list are strictly ordered. We also see in the first repeat loop that, although the while condition is not tested till after the loop, the while condition can in fact declare the variable that will be initialized the first time through the loop, which is a neat trick, and not half unreadable once you get used to it.
 
<lang Perl6perl6>repeat while [<] my @jumbled-list {
@jumbled-list = (1..9).pick(*)
}
10,333

edits