Tuesday, November 12, 2013

Problem 63 - Dart

Dart is a programming language that plans on replacing Javascript...maybe it will be able to that, it has a lot of engineers from Google trying to make that happen. But either way, it makes a nice language to solve a Project Euler problem in. I discovered the language through http://helloworldquiz.com/, which a friend showed me, and which had surprisingly many languages which I had yet to consider for this challenge. Solution runs in about 44ms on my machine.

import "dart:math";

main() {
    num ans = 0;
    num j = 1;
    num b = 1;
    while (b < 10) {
        for (num i = b; i <= 9; ++i) {
            num pdigs = (log(pow(i,j)) / LN10 + 1).floor();
            if (pdigs == j) {
                ++ans;
            } else {
                b = (i + 1);
            }
        }
        ++j;
    }
    print(ans);
}

No comments:

Post a Comment