-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathMemento.js
38 lines (35 loc) · 1.25 KB
/
Memento.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var Westeros;
(function (Westeros) {
(function (Mathmatics) {
var Fibonacci = (function () {
function Fibonacci() {
this.memorizedValues = [];
}
Fibonacci.prototype.NaieveFib = function (n) {
if (n == 0)
return 0;
if (n <= 2)
return 1;
return this.NaieveFib(n - 1) + this.NaieveFib(n - 2);
};
Fibonacci.prototype.MemetoFib = function (n) {
if (n == 0)
return 0;
if (n <= 2)
return 1;
if (!this.memorizedValues[n])
this.memorizedValues[n] = this.MemetoFib(n - 1) + this.MemetoFib(n - 2);
return this.memorizedValues[n];
};
return Fibonacci;
})();
Mathmatics.Fibonacci = Fibonacci;
})(Westeros.Mathmatics || (Westeros.Mathmatics = {}));
var Mathmatics = Westeros.Mathmatics;
})(Westeros || (Westeros = {}));
var fib = new Westeros.Mathmatics.Fibonacci();
start = new Date();
console.log(fib.NaieveFib(140));
console.log(fib.memorizedValues.length);
end = new Date();
console.log(end-start);