#!/usr/bin/ruby

# See: https://en.wikipedia.org/wiki/Sylvester's_sequence

func sylvesters_sequence(n, code) {

    var x = 1;
    var y = 1;

    {
        y = (x *= y);
        code(x += 1);
    } * n;

    return x;
}

sylvesters_sequence(9, func(n){say n});
