Exercises from Chapter 2

Hours in a Year

How you could do it:

puts 24*365
8760

How I would do it:

# depends on if it's a leap year
puts 24*365
puts ​"(or ​#{24*366}​ on occasion)"
8760
(or 8784 on occasion)

Minutes in a Decade

How you could do it:

puts 60*24*(365*10 + 2)
5258880

How I would do it:

# depends on how many leap years in that decade
puts ​"​#{60*24*(365*10 + 2)}​ or ​#{60*24*(365*10 + 3)}​"
5258880 or 5260320

Your Age in Seconds

How you could do it:

puts 60*60*24*365*36
1135296000

How I would do it:

puts(Time.new - Time.gm(1976, 8, 3, 13, 31))
1204369530.403

Our Dear Author’s Age

How you could do it:

puts 1160000000/(60*60*24*365)
36

And that’s pretty much how I would do it, too.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.51.77