CS 145 Lecture 25 – Computer as Factory Worker
Agenda
- what ?s
- a siblings histogram
- arrays
- counting repeated birthdays
TODO
- Start homework 5, which is due before November 13. It uses the ideas we discuss today.
- Prepare a question or two to share before tomorrow’s quiz. New topics we’ve covered since the last quiz include loops and conditional statements. Worth a participation point.
Note
Before we get started today, lean over to your neighbor and discuss this question:
In your own words, what’s an index? What’s it used for?
Our next topic hangs on proper understanding of this term.
With loops added to our repertoire, we’re ready to use them to code up data-intensive processes with relative ease. First, let’s step back for another installment of Program This:
There’s a weird statistical problem that goes something like this: “How many people do you need in a room for it to be probable that at least two people share a birthday? Probable means the chance is greater than 50%.” We’re not going to solve this problem. Instead, let’s solve this one. How do you tell if there’s a shared birthday in a room full of people? What would a human do to determine this?
We’ll implement a solution to this in Java using your own birthday data.
Before that, we’ll look at a slightly more contained example of computing a histogram for the number of siblings that you reported last week.
Code
FileTest.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 `'
Siblingram.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
But instead of saving time
They fit more in it