#!/usr/bin/ruby

#
## https://rosettacode.org/wiki/Parallel_calculations
#

func prime_factors(n) {
    var p = 3;
    var out = [];
    return out if (n < 1);
    while (!(n & 1)) {
        n >>= 1;
        out << 2;
    }
    while ((n > 1) && (p*p <= n)) {
        while (n %% p) {
            n /= p;
            out << p;
        }
        p += 2;
    }
    out << n if (n > 1);
    return out;
}

var nums = 10.of { 1e9.irand }

var factors = nums.map {|n| prime_factors.ffork(n) }.map { .wait }
say ((nums ~Z factors)->max_by {|m| m[1][0] })
