#!/usr/bin/perl -w use strict; #purpose: find simple fractions that are close to percentages... #divisions, tolerance my $div = 1000; my $tol = 0.005; my $high = 25; my $file = 'tolerance.txt'; my $last = ''; #no duplicate fractions in output open FILE, ">$file" or die; DIV:for (1 .. $div) { my $val = $_ / $div; #0.001, for example for ( 1 .. $high) { my $den = $_; #denominator for (1 .. $den) { #numerator my $here = $_/$den; #number #check for within tolerance of value if (($val-$tol <= $here) and ($here <= $val + $tol)) { my $test = "$_/$den"; #string if ($last ne $test) { #unique fractions only $last = $test; print FILE "$val:\t$test\n"; } next DIV; #avoid 1/1, .. 5/5 for 1.000 } } } } close FILE; #### 0.035: 1/25 0.037: 1/24 0.039: 1/23 0.041: 1/22 0.043: 1/21 0.046: 1/20 0.048: 1/19