func is_perfect(n) { n.sigma ==2*n}for n in (1..10000) { say n if is_perfect(n)}
Alternatively, a more efficient check for even perfect numbers:
func is_even_perfect(n) { var square = (8*n +1) square.is_square ||returnfalse var t = ((square.isqrt +1) /2) t.is_smooth(2) ||returnfalse t-1-> is_prime}for n in (1..10000) { say n if is_even_perfect(n)}