#!/usr/bin/ruby

#
## http://rosettacode.org/wiki/Non-continuous_subsequences
#

func non_continuous(min, max, subseq=[], has_gap=false) {

    static current = [];

    range(min, max).each { |i|
        current.push(i);
        has_gap && subseq.append([current...]);
        i < max && non_continuous(i.inc, max, subseq, has_gap);
        current.pop;
        has_gap = current.len;
    }

    subseq;
}

assert_eq(non_continuous(1, 3), [[1, 3]]);
assert_eq(non_continuous(1, 4), [[1, 2, 4], [1, 3], [1, 3, 4], [1, 4], [2, 4]]);
assert_eq(non_continuous("a", "d"), [["a", "b", "d"], ["a", "c"], ["a", "c", "d"], ["a", "d"], ["b", "d"]]);
assert_eq(non_continuous(1, 4), [[1, 2, 4], [1, 3], [1, 3, 4], [1, 4], [2, 4]]);

say "** Test passed!";
