1 ! Copyright (c) 2008 Aaron Schaefer.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: kernel math project-euler.common ;
6 ! https://projecteuler.net/index.php?section=problems&id=73
11 ! Consider the fraction, n/d, where n and d are positive integers. If n<d and
12 ! HCF(n,d) = 1, it is called a reduced proper fraction.
14 ! If we list the set of reduced proper fractions for d <= 8 in ascending order of
17 ! 1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7, 3/5, 5/8,
18 ! 2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 7/8
20 ! It can be seen that there are 3 fractions between 1/3 and 1/2.
22 ! How many fractions lie between 1/3 and 1/2 in the sorted set of reduced
23 ! proper fractions for d <= 10,000?
29 ! Use the properties of a Farey sequence and mediants to recursively generate
30 ! the next fraction until the denominator is as close to 1000000 as possible
35 :: (euler073) ( counter limit lo hi -- counter' )
37 m denominator limit <= [
45 : euler073 ( -- answer )
46 0 10000 1/3 1/2 (euler073) ;
48 ! [ euler073 ] 10 ave-time
49 ! 20506 ms ave run time - 937.07 SD (10 trials)