Skip to content

Instantly share code, notes, and snippets.

@colintheshots
Created June 17, 2014 04:30
Show Gist options
  • Save colintheshots/2b630c14684c274a0071 to your computer and use it in GitHub Desktop.
Save colintheshots/2b630c14684c274a0071 to your computer and use it in GitHub Desktop.
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