Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Solution to Google Treasure Hunt 2008 - Task 2

The program below can be used to solve a particular instance of the task presented at (Task 2, 2008). The input to countLines calls would probably have to change, otherwise it should work by executing as this:


And the source code is as follows (put into Public Domain by Lars Ivar Igesund):

module googlehunt;

import tango.text.Util;
import tango.text.convert.Integer;

void main(char[][] args)
    if (args.length < 2)

    auto archive = new ZipFolder(args[1]);
    auto info = archive.tree;

    ulong countLines(char[] ext, char[] pattern, int ln) {

        bool googleFilter(VfsInfo info) {
            if (info.path.containsPattern(pattern) ||
                if ([$-ext.length..$] == ext)
                    return true;

            return false;

        ulong sum;
        foreach (file; info.catalog(&googleFilter)) {
            foreach (idx, line; new LineIterator!(char) (file.input))
                if (idx == ln)
                    if (line.length > 0)
                        sum += toInt(line);

        return sum;

    ulong sum1, sum2;
    sum1 = countLines(".xml", "BCD", 4);
    sum2 = countLines(".js", "stu", 3);

    Stdout ("Sum 1 = ")(sum1)(", sum 2 = ")(sum2).newline;
    Stdout ("Result is: ")(sum1 * sum2).newline;