Go Fish/D: Difference between revisions

105 bytes removed ,  10 years ago
Two small improvements in D entry
(Updated comments)
(Two small improvements in D entry)
Line 5:
In D strings are only partially reference types, unlike in Python, so I have used a small class to keep the shared deck. I have also used an abstract class to simplify and reduce the code compared to the Python entry that has some code duplication.
<lang d>import std.stdio, std.random, std.range, std.string, std.array,
std.algorithm, std.exception;
 
alias replicate = std.array.replicate; //
Line 97:
/// Displays current hand, cards separated by spaces.
string displayHand() {
//return " "hand.joinbyPair.map!(key for key{k, valv} in=> hand[k].iteritemsreplicate(v))
return hand.byKey.map!(k => [k].replicate(hand[k]))
// for i in xrange(val))
string[] result .joiner.join(" ");
foreach (key, val; hand)
result ~= [key].replicate(val);
return result.join(" ");
}