// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.function.IntFunction;

public class ALGrow {
    public static void comp(IntFunction<Integer> alg1, IntFunction<Integer> alg2) {
        for(int i = 2; i < 10; i++) {
            if(alg1.apply(i) != alg2.apply(i)) {
                System.out.printf("%d : %d != %d\n", i, alg1.apply(i), alg2.apply(i));
            }
        }
    }
    public static void test(IntFunction<Integer> alg) {
        long t1 = System.currentTimeMillis();
        for(int i = 2; i < Integer.MAX_VALUE; i++) {
            int res = alg.apply(i);
            if(res < i) {
                long t2 = System.currentTimeMillis();
                System.out.printf("%d in %d ms\n", i, t2-t1);
                break;
            }
        }
    }
    public static void main(String[] args) {
        IntFunction<Integer> oldalg = n -> (n * 3) / 2 + 1;
        IntFunction<Integer> newalg = n -> n + (n >> 1);
        comp(oldalg, newalg);
        test(oldalg);
        test(newalg);
    }
}
