Skip to content

Instantly share code, notes, and snippets.

@jamesdabbs
Created March 15, 2015 14:52
Show Gist options
  • Select an option

  • Save jamesdabbs/0e6f6c7d69dcc3ced3d1 to your computer and use it in GitHub Desktop.

Select an option

Save jamesdabbs/0e6f6c7d69dcc3ced3d1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
def s n
Math.sqrt n
end
approxes = [
"3",
"s(7 + s(6 + s(5)))",
"(63 * (17 + 15 * s(5))) / (25 * (7 + 15 * s(5)))",
"339 / 108.0",
"s(15) - s(3) + 1",
"(7.0 ** 7) / (4.0 ** 9)",
"355 / 113.0",
"3 + 8/60.0 + 29/(60.0 ** 2) + 44/(60.0 ** 3)",
"3927 / 1250.0",
"377.0 / 120",
"25.0 / 8",
"22.0 / 7",
"s(2) + s(3)",
"(2143.0 / 22) ** (0.25)",
"31 ** (1 / 3.0)",
"9.0/5 + s(9.0/5)"
]
vals = approxes.map { |a| [a, eval(a)] }.sort_by { |k,v| (Math::PI - v).abs }
puts vals
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment