Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit 1e88bad

Browse files
authored
Update usacotools.java
1 parent 4e9ad02 commit 1e88bad

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

usacotools.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,29 @@ public static int classify(char x,char off,char on) {
289289
}
290290

291291
}
292-
292+
public static long slowfib(long num){
293+
if(num<=1) {
294+
return num;
295+
}
296+
297+
return slowfib(num-1)+slowfib(num-2);
298+
}
299+
public static ArrayList<Long> fibmem=new ArrayList<Long>();
300+
public static long ffib(long n){
301+
if(n<=1) {
302+
return n;
303+
}
304+
305+
if(fibmem.size()>n) {
306+
return fibmem.get((int) n-1)+fibmem.get((int) n-2);
307+
}else {
308+
fibmem.add(ffib(n-1)+ffib(n-2));
309+
return fibmem.get((int) n);
310+
}
311+
}
312+
public static void setupfib() {
313+
fibmem.add((long) 0);fibmem.add((long)1);fibmem.add((long)1);fibmem.add((long)2);
314+
}
293315
public static void main(String[] args) throws Exception{
294316
/*
295317
* Short demo of stuff

0 commit comments

Comments
 (0)