Exercises from Chapter 10
One Billion Seconds!
(Found here.)
Find out the exact second you were born, or as close as you can get. Figure out when you’ll turn (or perhaps when you did turn) one billion seconds old.
How You Could Do It
Well, I don’t know your birthday, so I don’t know how you’d do it.
How I Would Do It
1: | # I don't know what second I was born. |
2: | puts(Time.utc(1976, 8, 3, 13, 31) + 10**9) |
3: | |
4: | # And yes, I had a party. It was awesome! |
<= | 2008-04-11 15:17:40 UTC |
Happy Birthday!
(Found here.)
Ask what year a person was born, then the month, and then the day. Figure out how old they are, and give them a ☺ (smiley emoji) for each birthday they’ve had.
How You Could Do It
1: | puts "What year were you born?" |
- | b_year = gets. ... |
Get Learn to Program, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.