Assignment 9, due Apr 1
Part of
the homework for CS:2820, Spring 2016
|
On every assignment, write your name legibly as it appears on your University ID card! Homework is due on paper at the start of lecture on the day indicated. Exceptions will be made only by advance arrangement (excepting "acts of God"). Late work must be turned in to the TA's mailbox (ask the CS receptionist in 14 MLH for help). Never push homework under someone's door!
synapse - CLOCK COUNT 0.5 7.0
Also recall the formula for voltage as a function of time at a neuron,
v2 = v1et1–t2 + s
and note that you know the time interval t1–t2 and you know that for the counter to eventually fire, v2 must be greater than v1.
A Question: What is the minimum value of the strength of this synapse for which the simulation will terminate. You can, of course, do this empirically if you have a working simulation, but it is also a straightforward math problem at the level of a pre-calculus course. (1 point)
In answering the following, please refer to the code distributed on Mar. 7; this code contains everything relevant to this oversight.
a) What method or initializer in what class has the information needed to correctly add content to these lists? (0.5 points)
b) Give code to add the content to these lists. Write this code so that it could be added at the very end of the method or initializer you identified in part a. (0.5 points)
public static int fromZeroToN( int n ) { int v = stream.nextInt(); if (v < 0) v = -v; return v % n; }
Inn class Random, a significantly more complex method that returns a very similar result is given, nextInt(n).
a) In nextInt(n), there is a very clever trick to detect integers that are powers of two. Give the expression that does this. (This is a scavanger hunt question.) (0.5 points)
b) The code given above is a bit faster than the Java library's nextInt(n), but it delivers a slightly non-uniform result distribution. Suppose you called fromZeroToN(5) repeatedly. Each time you called it, it would return a value from 0 to 4 (inclusive). Why are the different values not equally probable? That is, what is the problem that nextInt(n) is trying to solve? (0.5 points)