Number reversal game: Difference between revisions
Content added Content deleted
(Mathematica) |
(Updated D entry) |
||
Line 704: | Line 704: | ||
=={{header|D}}== |
=={{header|D}}== |
||
<lang d>import std.stdio, std.random, std.string, std.conv, std.algorithm |
<lang d>import std.stdio, std.random, std.string, std.conv, std.algorithm, |
||
std.range; |
|||
void main() { |
void main() { |
||
auto data = |
auto data = iota(1, 10).array(); |
||
do randomShuffle( |
do data.randomShuffle(); |
||
while (isSorted( |
while (data.isSorted()); |
||
int trial; |
int trial; |
||
while (!isSorted( |
while (!data.isSorted()) { |
||
writef("%d: %s How many numbers to flip? ", ++trial, data); |
writef("%d: %s How many numbers to flip? ", ++trial, data); |
||
data[0 .. |
data[0 .. readln().strip().to!size_t()].reverse(); |
||
} |
} |
||
writefln("\nYou took %d attempts.", trial); |
writefln("\nYou took %d attempts.", trial); |