-
-
Save wlib/5444e6963d4befb33b26d6a6482d94a9 to your computer and use it in GitHub Desktop.
Calculate E in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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