Created
June 17, 2014 04:30
-
-
Save colintheshots/2b630c14684c274a0071 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.octo.android.robospice.sample.retrofit; | |
import java.math.BigInteger; | |
import rx.Observable; | |
import rx.Subscriber; | |
import rx.functions.Action1; | |
/** | |
* Created by colintheshots on 6/16/14. | |
*/ | |
public class RxBigIntegerFibonacci { | |
public static void main(String[] args) { | |
rxFibN(100000).subscribe(new Action1<BigInteger>() { | |
@Override | |
public void call(BigInteger result) { | |
System.out.println(result); | |
} | |
}); | |
} | |
static Observable<BigInteger> rxFibN(final int n) { | |
return Observable.create(new Observable.OnSubscribe<BigInteger>() { | |
@Override | |
public void call(Subscriber<? super BigInteger> subscriber) { | |
BigInteger[] n1 = {BigInteger.ZERO, BigInteger.ONE}; | |
for (int i = 1; i < n; i++) { | |
n1 = new BigInteger[]{n1[1], n1[1].add(n1[0])}; | |
subscriber.onNext(n1[1]); | |
} | |
subscriber.onCompleted(); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment