Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package badcode;
- import java.util.LinkedHashSet;
- public class Ord extends LinkedHashSet<Ord> {
- private static final Ord EMPTY_SET = new Ord();
- private static final Ord SINGLETON_OF_THE_VOID = EMPTY_SET.inc();
- private Ord() { }
- private Ord(Ord n) { add(n); addAll(n); }
- public static void main(final String... args) {
- System.out.println(EMPTY_SET.inc().inc().inc().inc().inc().inc().inc()
- .inc().inc().inc().inc().inc().inc().inc().inc().inc().inc()
- .inc().inc().inc().fibonacci().hashCode());
- }
- private Ord fibonacci() {
- return equals(EMPTY_SET) || equals(SINGLETON_OF_THE_VOID) ?
- this : dec().dec().fibonacci().plus(dec().fibonacci());
- }
- private Ord inc() { return new Ord(this); }
- private Ord dec() { return stream().findFirst().orElse(EMPTY_SET); }
- private Ord plus(Ord other) {
- return equals(EMPTY_SET) ? other : dec().plus(other.inc());
- }
- @Override public int hashCode() { return size(); }
- @Override public boolean equals(Object other) {
- return other instanceof Ord && hashCode() == other.hashCode();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment