Skip to content

Instantly share code, notes, and snippets.

@wlib
Last active February 14, 2017 00:22
Show Gist options
  • Save wlib/5444e6963d4befb33b26d6a6482d94a9 to your computer and use it in GitHub Desktop.
Save wlib/5444e6963d4befb33b26d6a6482d94a9 to your computer and use it in GitHub Desktop.
Calculate E in Ruby
#!/usr/bin/env ruby
# Watch how E changes as n increases
# For good display, I set the cursor off
# To make your cursor appear again, try ``printf "\033[?25h"
def e(rounds)
print "\033[?25l"
for n in 1..rounds do
e = (1 + 1.0 / n) ** n
if n % 10 == 0
print "On round #{n}, E = #{e} \r"
end
end
puts "On round #{n}, E = #{e}"
print "\033[?25h"
end
if ARGV.empty?
print "Calculate to what round? : "
rounds = gets.to_i
else
rounds = ARGV[0].to_i
end
e(rounds)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment