[your code here]
Jos van Uden
user at domain.invalid
Sat Jan 28 07:50:52 PST 2012
On 28-1-2012 16:07, Andrei Alexandrescu wrote:
>> import std.stdio, std.stream, std.string, std.range, std.algorithm;
>>
>> void main() {
>> int countPalindromes;
>> auto infile = new BufferedFile("unixdict.txt");
>> foreach (char[] line; infile) {
>> if (line.walkLength > 1) {
>> line.toLowerInPlace;
>> if (equal(line, retro(line)))
>> countPalindromes++;
>> }
>> }
>> writeln("palindromes found: ", countPalindromes);
>> }
>
> Could you please also compare with code that uses foreach with
> stdin.byLine()?
After having added the upTo param, which is an improvement on both
methods, the infile is (marginally) faster on my system than the byLine.
win7 64-bits i7 2600, dmd 2.057, optimizations enabled: -O -inline -release
--
import std.stdio, std.stream, std.string, std.range, std.algorithm;
void main() {
int countPalindromes;
auto infile = new BufferedFile("ukacd17.txt");
foreach (char[] line; infile) {
if (line.walkLength(2) > 1) {
line.toLowerInPlace;
if (equal(line, retro(line)))
countPalindromes++;
}
}
writeln("palindromes found: ", countPalindromes);
}
More information about the Digitalmars-d
mailing list