3 ms·
Farey Sequence
- 40four 6y agoI found out about this concept when I was tasked with improving a portion of an app that converted decimals to fractions. I'm not exactly up to speed on the actual math of it, but I found an implementation online that was perfect for my task. It allowed me to pass in a decimal and the largest denominator to use, and it spits out the closest fraction, with the lowest possible denominator (https://stackoverflow.com/a/14940739/8953064 https://stackoverflow.com/a/14940739/8953064). The old way we did it, used only continued fractions. It would output '33/100' for '.33', or '40/100' for '.4', but adding the Farey sequence you get '1/3' and '2/5' just like you'd expect. Fantastic!