Bulls and cows: Difference between revisions

Improved the D code
(Improved the D code)
Line 651:
cows bulls)))))))</lang>
=={{header|D}}==
<lang d>import std.stdio, std.random, std.string, std.algorithm;
 
void main() {
enum int size = 4;
char[] digits = "123456789".dup;
char[] chosen = digits.dup;
Line 671:
guess = readln().strip();
if (guess.length == size &&
countchars(guess, digits.idup) == size &&
guess.dup.sort.idup.squeeze().length == size)
break;
writefln("I need %d unique digits from 1 to 9, no spaces", size);
Line 686:
if (guess[i] == chosen[i])
bulls++;
else if (indexOfcanFind(chosen, guess[i]) != -1)
cows++;
}
Anonymous user