Anonymous user
Towers of Hanoi: Difference between revisions
Better second D version
(Better second D version) |
|||
Line 337:
<lang d>import std.stdio, std.conv, std.typetuple;
void main(immutable string[] args) {
// Code found and then improved by Glenn C. Rhoads,
// then some more by M. Kolar (2000).
Line 346:
printf("\n|");
foreach_reverse (size_t i; 1 .. n+1)
printf(" %
printf("\n|\n|\n");
Line 357:
size_t j = 1;
for (int w = x; !(w & 1); w >>= 1, j <<= 1) {}
// Now j is not the number of the disk to move,
Line 367 ⟶ 365:
}
foreach (immutable(size_t) k; TypeTuple!(0, 1, 2)) {
printf("\n|");
size_t j = 1 << n;
Line 373 ⟶ 371:
j >>= 1;
if (j & p[k])
printf(" %
}
}
|