Skip to content

Instantly share code, notes, and snippets.

import java.util.function.Function;
public class Main {
static <T> Function<T, T> ycomb(Function<Function, Function<T,T>> le) {
return ((Function<Function, Function>) (f) -> (Function) ((Function) f).apply(f) )
.apply(((f) -> (le.apply( (x) -> ( (Function) (((Function) f).apply(f))).apply(x) ))));
}
public static void main(String[] args) {
import java.util.function.Function;
public class Main {
static Function ycomb(Function<Function, Function> le) {
return ((Function<Function, Function>) (f) -> (Function) ((Function) f).apply(f) )
.apply(((f) -> (le.apply( (x) -> ( (Function) (((Function) f).apply(f))).apply(x) ))));
}
// Using the y-combinator to make Factorials.
@alexchow
alexchow / gist:7228746
Last active December 26, 2015 23:09
This is in response to another [gist](https://gist.github.com/igor47/7228586) for a supposed solution to the [water levels question](https://news.ycombinator.com/item?id=6639839). The solution doesn't work if there is more than 1 "puddle". Example: `[2,5,1,2,3,4,7,7,6,3,5]` should return 12.
#!/usr/bin/python
def water(levels):
# state machine
filling = False
h = 0
total = 0
cur = 0
for i in xrange(1, len(levels)):