Created
May 21, 2019 21:05
-
-
Save Tok/93be630a1449d454a4714d08711db191 to your computer and use it in GitHub Desktop.
Von Neumann Ordinals as Java HashSets
This file contains 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
import java.util.HashSet; | |
import java.util.Set; | |
import java.util.stream.Collectors; | |
public class VonNeumannOrdinal extends HashSet<Set> { | |
private int toInt() { return size(); } | |
@Override public String toString() { | |
return "{" + (isEmpty() ? "" : stream().map(Object::toString) | |
.collect(Collectors.joining(","))) + "}"; | |
} | |
private VonNeumannOrdinal increment() { | |
var next = new VonNeumannOrdinal(); | |
next.addAll(this); | |
next.add(this); | |
return next; | |
} | |
public static void main(final String... args) { | |
var ordinal = new VonNeumannOrdinal(); | |
while (ordinal.toInt() < 16) { | |
System.out.println(ordinal.toInt() + ": " + ordinal); | |
ordinal = ordinal.increment(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment