extern crate time;

extern crate rayon;

use time::PreciseTime;

use rayon::prelude::*;

type T = usize;

fn skynet(levels: T, children: T) -> T {

fn sky(levels: T, children: T, position: T) -> T {

match levels {

0 => position,

_ => (0..children).into_par_iter()

.map(|cn| sky(levels - 1, children, position * children + cn)).sum()

}

}

sky(levels, children, 0)

}

fn main() {

let start = PreciseTime::now();

let result = skynet(6, 10);

let end = PreciseTime::now();

println!("Result: {} in {} ms", result, start.to(end).num_milliseconds());

}