in reply to Cube/digit script.

#!/usr/bin/perl use warnings; for my $a ( 1 .. 9 ) { for my $b ( 0 .. 9 ) { for my $c ( 0 .. 9 ) { my $num = $a.$b.$c; my $sum = ( $a ** 3 ) + ( $b ** 3 ) + ( $c ** 3 ); print "$num\n" if $num == $sum; } } }

Replies are listed 'Best First'.
Re^2: Cube/digit script.
by ptum (Priest) on Mar 10, 2006 at 14:36 UTC

    A minor quibble: I would avoid using $a and $b in this context, since they are global sort variables -- it has the potential to confuse a casual reader of your code. How 'bout $c, $d and $e instead? :)


    No good deed goes unpunished. -- (attributed to) Oscar Wilde