#!/usr/bin/ruby

#
## http://rosettacode.org/wiki/Fibonacci_n-step_number_sequences
#

func fib(n, xs=[1]) {
    xs.clone!;

    loop {
        var len = xs.len;
        len >= 20 && break;
        xs.append(xs.ft(0.max(len - n), len-1).sum);
    }

    xs;
}

range(2, 10).each { |i|
    say fib(i).join(' ')
}
say fib(2, [2, 1]).join(' ')
