teaching machines

CS 145 Lecture 24 – Accumulation

October 30, 2015 by . Filed under cs145, fall 2015, lectures.

Agenda

Note

We continue our discussion of common patterns we see with loops. Today we visit the accumulation pattern, where a loop iterates through a collection and accumulates values in some variable of larger scope. Accumulations tend to look like this:

initialize soFar
for each item
  integrate item into soFar
end
use soFar to some other end

We’ll look at an example of calculating a linear approximation of a dataset.

Code

Regression.java

/usr/lib/ruby/vendor_ruby/rubygems/dependency.rb:315:in `to_specs': Could not find 'coderay' (>= 0) among 94 total gem(s) (Gem::MissingSpecError)
Checked in 'GEM_PATH=/var/www/.local/share/gem/ruby/3.2.0:/var/lib/gems/3.2.0:/usr/local/lib/ruby/gems/3.2.0:/usr/lib/ruby/gems/3.2.0:/usr/lib/x86_64-linux-gnu/ruby/gems/3.2.0:/usr/share/rubygems-integration/3.2.0:/usr/share/rubygems-integration/all:/usr/lib/x86_64-linux-gnu/rubygems-integration/3.2.0:/home/johnch/.gems' , execute `gem env` for more information
	from /usr/lib/ruby/vendor_ruby/rubygems/dependency.rb:327:in `to_spec'
	from /usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_gem.rb:57:in `gem'
	from ./coderay:24:in `
'

Haiku

To accumulate:
while the bag is not empty
  eat you some candy