Friday, February 27, 2009
Been a while since last post. Busy with studying for an Automata midterm we had last night. Wasn't too bad though. I going to begin working on the SMP project today after class. I also think I'm going to stay in classroom and sit it on Prof Downing's next class (in the same room) which is mainly about c++ (I think?) Sam convinced me to do, and I know it would greatly help me for 354 (Graphics) because everyone in there knows C++ (better than I do, anyway). Anyway, once I get into this project I will post some more SMP-specific stuff. So for now...
Wednesday, February 18, 2009
Australian Voting
Adam and I have started working on our current project, Australian Voting. We've created 3 classes: a candidate, ballot, and testcase class. These three will be used to implement our method of counting votes. We feel we have a good solution in adding the testcase class, because all of our computation will be done inside this class, using the classes candidate and ballot to communicate that a certain candidate is out, etc. Many groups have used just the two, candidate and ballot. So we'll see if we've dug ourselves a hole. We aren't done yet. Updates pending.
Sunday, February 15, 2009
We had our first test on Friday, the 13th. I think I did fine on the programming questions but the questions about the reading get me. I haven't the slightest clue what a spike solution is. I thought the test was fair and we had ample time to code our answers, test, and double-check. List comprehension "unrolling" was probably the toughest question.
Anyway, my partner (Adam M) and I will start working on Project 3 today. Looking at the problem, perhaps creating a sort of "candidate" class would simplify this problem. I'll see what it's like one we dive in.
Anyway, my partner (Adam M) and I will start working on Project 3 today. Looking at the problem, perhaps creating a sort of "candidate" class would simplify this problem. I'll see what it's like one we dive in.
Saturday, February 7, 2009
Summation of Four Primes
Here's a different algorithm for our current project, Summation of Four Primes.
If you could write a next_lowest_prime(n) method, you might use it to find n's next lowest prime (if n is prime, return n).
Then you could do it again, this time calling the method with next_lowest_prime(n - [the "previous" next lowest prime]). If you do that 4 times, you'll get 4 primes that add up to your n. But say n = 20.
next_lowest_prime(20) = 19. So, 19 is one.
n' = 20 - 19 = 1. Obviously we have a problem. But there is a simple solution to fix this. Declare a variable, r = 6.
Why 6?
We'll always be able to obtain the first prime, but in cases such as the one above, the next lowest prime is one (or zero, two, or three...) below n. So we must have a way to guarantee that there are 3 spaces for the minimum prime, 2. So 2x3=6.
Then:
four_primes[i] = next_lowest_prime(n' - r)
n' = n - four_primes[i]
r -= 2
guarantees you will obtain a prime that leaves enough room for the rest of the 4 primes. Run the algorithm for n = 20, again.
N.L.P(20 - 6) = 13
N.L.P(7 - 4) = 3
N.L.P(4 - 2) = 2
N.L.P(2 - 0) = 2
If you could write a next_lowest_prime(n) method, you might use it to find n's next lowest prime (if n is prime, return n).
Then you could do it again, this time calling the method with next_lowest_prime(n - [the "previous" next lowest prime]). If you do that 4 times, you'll get 4 primes that add up to your n. But say n = 20.
next_lowest_prime(20) = 19. So, 19 is one.
n' = 20 - 19 = 1. Obviously we have a problem. But there is a simple solution to fix this. Declare a variable, r = 6.
Why 6?
We'll always be able to obtain the first prime, but in cases such as the one above, the next lowest prime is one (or zero, two, or three...) below n. So we must have a way to guarantee that there are 3 spaces for the minimum prime, 2. So 2x3=6.
Then:
four_primes[i] = next_lowest_prime(n' - r)
n' = n - four_primes[i]
r -= 2
guarantees you will obtain a prime that leaves enough room for the rest of the 4 primes. Run the algorithm for n = 20, again.
N.L.P(20 - 6) = 13
N.L.P(7 - 4) = 3
N.L.P(4 - 2) = 2
N.L.P(2 - 0) = 2
Subscribe to:
Posts (Atom)