MojoでProject Euler 52

https://projecteuler.net/problem=52

各数字が何個あるかを4ビットで表します。

import sys


#################### process ####################

fn count_digits(owned n: Int) -> Int:
    var c = 0
    while n > 0:
        var d = n % 10
        c += 1 << (d * 4)
        n //= 10
    return c

fn f(N: Int) -> Int:
    for E in range(1, 11):
        for x in range(10**(E-1), 10**E//N):
            var c1 = count_digits(x)
            for f in range(2, N+1):
                var c = count_digits(x * f)
                if c1 != c:
                    break
            else:
                return x
    return 0

fn main() raises:
    var args = sys.argv()
    var N = atol(args[1])
    print(f(N))