2018-11-04 11:06:09 +00:00
|
|
|
import java.lang.Integer;
|
|
|
|
|
2024-03-14 12:50:56 +00:00
|
|
|
public class Y {
|
2018-11-04 11:06:09 +00:00
|
|
|
y;
|
2024-03-14 12:50:56 +00:00
|
|
|
public Y() {
|
2024-08-06 10:42:09 +00:00
|
|
|
y = f -> t -> f.apply(y.apply(f)).apply(t);
|
2019-09-19 11:57:49 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-22 14:44:38 +00:00
|
|
|
|
2024-08-06 10:42:09 +00:00
|
|
|
public class Fac1 {
|
|
|
|
public factorial;
|
|
|
|
public Fac1() {
|
2018-11-04 11:06:09 +00:00
|
|
|
var y;
|
2024-08-06 10:42:09 +00:00
|
|
|
var tmp = new Y<>(); // TODO Having new Y<>().y on one line doesn't work, see FIXME in StatementGenerator
|
|
|
|
y = tmp.y;
|
2018-11-04 11:06:09 +00:00
|
|
|
factorial = y.apply(f -> n -> { if (n == 0) return 1; else return n * f.apply(n - 1); });
|
|
|
|
}
|
2024-08-06 10:42:09 +00:00
|
|
|
|
|
|
|
public fac(v) {
|
|
|
|
return factorial.apply(v);
|
2018-11-04 11:06:09 +00:00
|
|
|
}
|
2024-08-06 10:42:09 +00:00
|
|
|
}
|