in reply to Cube/digit script.

Andrew_Levenson,
This sounds Project Eulerish.
#!/usr/bin/perl use strict; use warnings; use List::Util 'sum'; for (100 .. 999) { print "$_\n" if sum(map {$_ ** 3} split //) == $_; }
Grrrr - after I posted I finished reading japhy's post where he provided an even more succinct solution.

Cheers - L~R

Replies are listed 'Best First'.
Re^2: Cube/digit script.
by Tanktalus (Canon) on Mar 10, 2006 at 21:35 UTC

    To me, this one looks more succinct, if a bit too much on one line ;-) But, to take this a bit further, I look at postfix "if" as "grep" ...

    print map { "$_\n" } grep { $_ == sum map { $_ ** 3 } split // } 100 .. 999
    IMO, both better (more whitespace) and worse (hiding the loops, removal of parenthesis for the sum function). ;-) (I'm sure others have their own opinions of how they compare.)

    Just to make it a bit worse ...

    print "$_\n" for grep { $_ == sum map $_ ** 3, split // } 100 .. 999
    Or is that better? Hmmm...