Updated Mastermind, Fibonacci.
This commit is contained in:
@@ -36,7 +36,8 @@ class Examples {
|
||||
}
|
||||
|
||||
// A generic list.
|
||||
interface ILo<A> {}
|
||||
interface ILo<A> {
|
||||
}
|
||||
|
||||
class Cons<A> implements ILo<A> {
|
||||
|
||||
@@ -49,7 +50,8 @@ class Cons<A> implements ILo<A> {
|
||||
}
|
||||
}
|
||||
|
||||
class Mt<A> implements ILo<A> {}
|
||||
class Mt<A> implements ILo<A> {
|
||||
}
|
||||
|
||||
interface ISequence<X> {
|
||||
// Returns the current element in the sequence.
|
||||
@@ -78,19 +80,14 @@ class Fibonacci implements ISequence<Integer> {
|
||||
public Integer get() {
|
||||
int ret; // What to return.
|
||||
/*
|
||||
|
||||
idx pen pre ret
|
||||
0 0 1 0
|
||||
1 0 1 1
|
||||
2 1 1 2
|
||||
3 1 2 3
|
||||
4 2 3 5
|
||||
5 3 5 8
|
||||
|
||||
*/
|
||||
*
|
||||
* idx pen pre ret 0 0 1 0 1 0 1 1 2 1 1 2 3 1 2 3 4 2 3 5 5 3 5 8
|
||||
*
|
||||
*/
|
||||
|
||||
// F(0) = 0; F(1) = 1
|
||||
if (this.idx <= 1) ret = this.idx;
|
||||
if (this.idx <= 1)
|
||||
ret = this.idx;
|
||||
else { // F(n) = F(n-1) + F(n-2)
|
||||
ret = this.pre + this.pen;
|
||||
|
||||
|
Reference in New Issue
Block a user