Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Recurring Cycle of Fractions

by steph (Initiate)
on Oct 18, 2012 at 14:17 UTC ( #999743=note: print w/replies, xml ) Need Help??

in reply to Recurring Cycle of Fractions

There you go
#!/usr/bin/perl use strict; use warnings; use bignum ( p => -9999 ); # this is huge, by the way my $limit = shift; # 1000 for project euler my $longest = 1; my $value; for my $val (1..$limit) { my $frac = 1/$val; if (reverse($frac) =~ /(\d+)\1+/) { my $longestSubChain = reverse($1); if ($longestSubChain =~ /(\d+?)\1+/) { if (length($1) > $longest) { $longest = length +($1); $value = $val; } } } } print "d = $value\n"; print "Longest recurring cycle: $longest";

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://999743]
[Discipulus]: oh and dont miss my last poetry!
[marioroy]: Hello all. After several attempts, am able to move forward and will soon release a Parallel:: ForkManager compatible MCE::Hobo:: Manager, also MCE::Hobo::Simple, and refactored MCE::Hobo engine supporting multiple instances. Wait works beautifully.
[marioroy]: MCE::Shared has been refined that it allows sharing Tie::File and hash objects containing {fh} key.

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (11)
As of 2017-05-26 08:22 GMT
Find Nodes?
    Voting Booth?