in reply to Egyptian fractions
Golfing with strictures and warnings is a handicap so (146):use Math::Pari 'lcm';my($n,$d)=split/\//,shift;sub p{print"1/$_[0] "}w +hile(1){my $u=int$d/$n+1;p$u;my $l=lcm$d,$u;$n=$n*$l/$d-$l/$u;$d=$l;p($d),die$/if +$n==1}
Since I am not a golfer either, anyone interested in the starting code can use it to improve things.($n,$d)=split/\//,shift;sub p{print"1/$_[0] "}while(1){use Math::Pari lcm;$u=int$d/$n+1;p$u;$l=lcm$d,$u;$n=$n*$l/$d-$l/$u;$d=$l;p($d),die$/i +f$n==1}
Cheers - L~R
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Egyptian fractions (Golf Anyone?)
by liverpole (Monsignor) on Aug 25, 2006 at 15:37 UTC | |
by tadman (Prior) on Aug 25, 2006 at 17:13 UTC | |
Re^2: Egyptian fractions (Golf Anyone?)
by blokhead (Monsignor) on Aug 25, 2006 at 16:43 UTC | |
Re^2: Egyptian fractions (Golf Anyone?)
by shmem (Chancellor) on Aug 26, 2006 at 01:53 UTC | |
by dewey (Pilgrim) on Aug 26, 2006 at 03:04 UTC |