Created
December 3, 2014 22:24
-
-
Save mdr/3ce8850564e8f707e45b to your computer and use it in GitHub Desktop.
Refuct.java
This file contains hidden or 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
strictfp \u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0063\u006c\u0061\u0073\u0073\u0020\u0052\u0065\u0066\u0075\u0063\u0074\u0020\u007b | |
\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu0020 | |
interface λ<A, B> { | |
public B call(A x); | |
} | |
interface RecursiveFunc<F> extends λ<RecursiveFunc<F>, F> { | |
} | |
private static boolean isDivisibleBy(int n, final int m) { | |
return new RecursiveFunc<λ<Integer, Boolean>>() { | |
public λ<Integer, Boolean> call(final RecursiveFunc<λ<Integer, Boolean>> w) { | |
return new λ<λ<Integer, Boolean>, λ<Integer, Boolean>>() { | |
public λ<Integer, Boolean> call(final λ<Integer, Boolean> f) { | |
return new λ<Integer, Boolean>() { | |
public Boolean call(Integer n) { | |
if (n == 0) | |
return true; | |
else if (n < 0) | |
return false; | |
else | |
return f.call(n - m); | |
} | |
}; | |
} | |
}.call(new λ<Integer, Boolean>() { | |
public Boolean call(Integer x) { | |
return w.call(w).call(x); | |
} | |
}); | |
} | |
}.call(new RecursiveFunc<λ<Integer, Boolean>>() { | |
public λ<Integer, Boolean> call(final RecursiveFunc<λ<Integer, Boolean>> w) { | |
return new λ<λ<Integer, Boolean>, λ<Integer, Boolean>>() { | |
public λ<Integer, Boolean> call(final λ<Integer, Boolean> f) { | |
return new λ<Integer, Boolean>() { | |
public Boolean call(Integer n) { | |
if (n == 0) | |
return true; | |
else if (n < 0) | |
return false; | |
else | |
return f.call(n - m); | |
} | |
}; | |
} | |
}.call(new λ<Integer, Boolean>() { | |
public Boolean call(Integer x) { | |
return w.call(w).call(x); | |
} | |
}); | |
} | |
}).call(n); | |
} | |
public static String buzzword(int n) { | |
if (isDivisibleBy(n, 3) && isDivisibleBy(n, 5)) | |
return "FizzBuzz"; | |
else if (isDivisibleBy(n, 3)) | |
return "Fizz"; | |
else if (isDivisibleBy(n, 5)) | |
return "Buzz"; | |
else | |
return n + ""; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment