![]() |
|
There's more than one way to do things | |
PerlMonks |
Re: Recurring Cycle of Fractionsby Sidhekin (Priest) |
on Sep 09, 2007 at 01:34 UTC ( #637884=note: print w/replies, xml ) | Need Help?? |
Actually, every rational number has a recurring cycle in a positional representation ... it's just that for some numbers it is a trivial "0" cycle. But that's just a quibble. Assuming that the provided string is long enough for two cycles to appear gets boring pretty quickly ... on my system that assumption fails already for 1/17, unless I use bignum. So I'll do that. And, true to habit, I'll use a regex to solve the problem. :) (Pass an argument to the program to get the cycle for the inverse of more (or less) than the default 99 first natural numbers:)
Thank you — that was an interesting distraction. :) Update: Made the leeway big enough that we get the cycle sequence as it first appears, and not some arbitrary cycling of it, no matter how long the sequence.
print "Just another Perl ${\(trickster and hacker)},"
In Section
Seekers of Perl Wisdom
|
|