#!/usr/bin/ruby

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

func happy(n) is cached {
    static seen = Hash();

    return true  if n.is_one;
    return false if seen.has_key(n);

    seen{n} = 1;
    happy(n.digits »**» 2 -> sum)
}

var count = 0;
{ |i|
    happy(i) ? say i : next;
    ++count == 8 && break;
} * Inf;