in reply to Re^2: Recurring Cycle of Fractions
in thread Recurring Cycle of Fractions
Try your attempt with 17 and 19...
I do. Since there aren't enough digits, Math::BigFloat to the rescue:
#!/usr/bin/perl use Math::BigFloat; Math::BigFloat->div_scale(50); my @values = map { my $i = Math::BigFloat->new( 1 ); scalar $i->bdiv( $_ ); } (2,3,6,7,9,11,13,14,17,19,23); for (@values) { /\.\d*?(\d+?)\1/; print "$_: $1\n" } __END__ 0.5: 0.33333333333333333333333333333333333333333333333333: 3 0.16666666666666666666666666666666666666666666666667: 6 0.14285714285714285714285714285714285714285714285714: 142857 0.11111111111111111111111111111111111111111111111111: 1 0.090909090909090909090909090909090909090909090909091: 09 0.076923076923076923076923076923076923076923076923077: 076923 0.071428571428571428571428571428571428571428571428571: 714285 0.058823529411764705882352941176470588235294117647059: 058823529411764 +7 0.052631578947368421052631578947368421052631578947368: 052631578947368 +421 0.043478260869565217391304347826086956521739130434783: 043478260869565 +2173913
The regex is the same, though. Still missing something?
update: Oh, I see. "try with 170..." :-)
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Recurring Cycle of Fractions
by Sidhekin (Priest) on Sep 09, 2007 at 19:53 UTC | |
Re^4: Recurring Cycle of Fractions
by Skeeve (Parson) on Sep 10, 2007 at 11:05 UTC |