>>>>> "KG" == Kenneth Graves <[EMAIL PROTECTED]> writes:
KG> 1 2 3 4 5 6 7 8 9 = 2002
KG> The problem is to add any number of addition & multiplication
KG> operations wherever you'd like on the left such that in the end
KG> you have a valid equation. So for example if it gets you to a
KG> solution you can have:
minor golf improvements.
KG> eval($_)==2002 && print "$_\n"
KG> for build(qw(1 2 3 4 5 6 7 8 9));
build 1 .. 9
KG> sub build {
KG> $n = shift;
KG> return $n unless @_;
KG> return map {("$n$_","$n+$_","$n*$_")} build(@_);
return @_ unless @_ > 1;
$n = shift;
return map {"$n$_","$n+$_","$n*$_"} build(@_);
this is almost one line now.
perl -le'sub b{my $n=pop;@_?map{("$_$n","$_+$n","$_*$n")}b(@_):$n}eval==2002&&print
for b 1..9'
uri
--
Uri Guttman ------ [EMAIL PROTECTED] -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm