Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Egyptian fractions (Golf Anyone?)

by shmem (Chancellor)
on Aug 26, 2006 at 01:53 UTC ( [id://569764]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use Junk;do
    
  2. or download this
    #!/usr/bin/perl -l
    pop=~m|/|;($f,$g)=($`,$');sub d{int($_[1]/$_[0]+1)}sub
    ...
    for($p,$l){$_/=$g};($p,$l)}while($f>1){push@o,"1/".d(#
    $f,$g);($f,$g)=re($f,$g,1,d($f,$g));}print join' + ',#
    @o,"$f/$g";# ungolfed and thus not for production use!
    
  3. or download this
    ($z,$n)=($_=pop)=~/(.+)\/(.+)/;$s='==';for(;;){$m=int($n/$z+1);$_
    .=" $s 1/".($z==1?$n:$m);$z<=1&&last;($z,$n)=($z*$m-$n,$m*$n);($x
    ,$y)=($z,$n);($x,$y)=($y,$x%$y)while$y;$z/=$x;$n/=$x;$s='+'}print
    
  4. or download this
    qwurx [shmem] ~> perl -l egy.pl 2355/12344
    2355/12344 == 1/6 + 1/42 + 1/3282 + 1/15755059 + 1/744665636525384
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://569764]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-25 10:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found