CS 145 Lecture 26 – Birthdays
Agenda
- what ?s
- loop until fixed
- repeated birthdays
TODO
- For an extra credit participation point, check out tryruby.org and work through at least level 5. Write down 2-3 questions, observations, or comparisons to Java or other languages you know.
Note
Today we introduce an idiom we can use to support a “try again” when an exception happens. I call this the loop until fixed pattern:
isValid = false
while not isValid
try
attempt the dangerous
isValid = true
catch
issue warning message
end
Let’s use this pattern as we attempt the problem we introduced last time: figuring out which of your birthdays repeat. I hope you realize in all our examples are the pieces of the solutions to many of the problems you will encounter. We teachers are always torn between teaching concepts in a decontextualized way or a contextualized way. I prefer contextualized, but the danger is that when we talk about ideas situated inside a particular example, you don’t carry the ideas out to other situations.
So, what do we need to do to find our repeated birthdays?
Code
Bepeats.java
/usr/lib/ruby/2.7.0/rubygems/dependency.rb:311:in `to_specs': Could not find 'coderay' (>= 0) among 56 total gem(s) (Gem::MissingSpecError) Checked in 'GEM_PATH=/.gem/ruby/2.7.0:/var/lib/gems/2.7.0:/usr/lib/ruby/gems/2.7.0:/usr/share/rubygems-integration/2.7.0:/usr/share/rubygems-integration/all:/usr/lib/x86_64-linux-gnu/rubygems-integration/2.7.0:/home/johnch/.gems', execute `gem env` for more information from /usr/lib/ruby/2.7.0/rubygems/dependency.rb:323:in `to_spec' from /usr/lib/ruby/2.7.0/rubygems/core_ext/kernel_gem.rb:62:in `gem' from ./coderay:24:in `'
Haiku
All start at 0
Only hard work moves us up
Work times privilege
Only hard work moves us up
Work times privilege