Find the missing permutation: Difference between revisions
Content deleted Content added
→{{header|Racket}}: Bit vector is more appropriate type for parities. |
Replaced the two D entries with one, updated |
||
Line 346:
=={{header|D}}==
<lang d>import std.stdio, std.string, std.algorithm
alias sum = reduce!q{a + b};
do {▼
} while (p.nextPermutation());▼
void main() {
const perms = "ABCD CABD ACDB DACB BCDA ACBD ADCB CDAB DABC
BCAD CADB CDBA CBAD ABDC ADBC BDCA DCBA BACD
BADC BDAC CBDA DBCA DCAB".split
// Version 1:
const permsSet = perms.zip(0.repeat).assocArray;
// flushed out; based on Perl 6 (via Go)▼
auto perm = cast(ubyte[
▲ do {
foreach (perm; perms)▼
writeln(cast(char[])b);▼
// Version 2
char[len] b =
write(cast(char)(sumr - to!int(sumc) % sumr));▼
// Version 3 : Sum ASCII values.
immutable rowSum = perms[0].sum;
foreach (immutable i; 0 .. len) {▼
immutable sumCols = sum(0, perms.transversal(i));
// See how much it falls short.
}
writeln
// Version
//
immutable maxCode = reduce!q{a * b}(len - 1, iota(3, len + 1));
▲ foreach (i; 0 .. len) {
▲ code += perms[0].countUntil(p[i]);
//
}
}</lang>
{{out}}
<pre>DBAC
DBAC
DBAC
DBAC</pre>
|