Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Fibonacci-sequence/Java/fibonacci-sequence-7.java
Normal file
18
Task/Fibonacci-sequence/Java/fibonacci-sequence-7.java
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import java.util.function.LongUnaryOperator;
|
||||
import java.util.stream.LongStream;
|
||||
|
||||
public class FibUtil {
|
||||
public static LongStream fibStream() {
|
||||
return LongStream.iterate( 1l, new LongUnaryOperator() {
|
||||
private long lastFib = 0;
|
||||
@Override public long applyAsLong( long operand ) {
|
||||
long ret = operand + lastFib;
|
||||
lastFib = operand;
|
||||
return ret;
|
||||
}
|
||||
});
|
||||
}
|
||||
public static long fib(long n) {
|
||||
return fibStream().limit( n ).reduce((prev, last) -> last).getAsLong();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue