Updated Mastermind, Fibonacci.
This commit is contained in:
@@ -36,7 +36,8 @@ class Examples {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A generic list.
|
// A generic list.
|
||||||
interface ILo<A> {}
|
interface ILo<A> {
|
||||||
|
}
|
||||||
|
|
||||||
class Cons<A> implements 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> {
|
interface ISequence<X> {
|
||||||
// Returns the current element in the sequence.
|
// Returns the current element in the sequence.
|
||||||
@@ -78,19 +80,14 @@ class Fibonacci implements ISequence<Integer> {
|
|||||||
public Integer get() {
|
public Integer get() {
|
||||||
int ret; // What to return.
|
int ret; // What to return.
|
||||||
/*
|
/*
|
||||||
|
*
|
||||||
idx pen pre ret
|
* 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
|
||||||
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
|
// 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)
|
else { // F(n) = F(n-1) + F(n-2)
|
||||||
ret = this.pre + this.pen;
|
ret = this.pre + this.pen;
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user