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
(ns zir.von-neumann-ordinal) | |
(defn- print-ordinals [ordinal] | |
(if (< (count ordinal) 16) | |
(do (println (count ordinal) ordinal) | |
(recur (conj (set ordinal) ordinal))))) | |
(defn -main [& _] (print-ordinals (set nil))) |
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(","))) + "}"; | |
} |
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
typealias VonNeumannOrdinal = Set<Any> | |
operator fun VonNeumannOrdinal.inc() = toMutableSet().also { it.add(this) }.toSet() | |
fun VonNeumannOrdinal.toInt() = this.size | |
fun VonNeumannOrdinal.print() = println("${toInt()} <- $this") | |
fun main() { | |
var ordinal = emptySet<Any>() | |
repeat(16) { | |
ordinal++.print() | |
} |
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.stream.IntStream; | |
public class FizzBuzz { | |
public static void main(final String... args) { | |
//Java 8 FizzBuzz One-Liner | |
IntStream.rangeClosed(1, 100).mapToObj(v -> v % 15 == 0 ? "FizzBuzz" : v % 5 == 0 ? "Buzz" : v % 3 == 0 ? "Fizz" : v).forEach(System.out::println); | |
//Parallel FizzBuzz | |
//IntStream.rangeClosed(1, 100).parallel().mapToObj(v -> v % 15 == 0 ? "FizzBuzz" : v % 5 == 0 ? "Buzz" : v % 3 == 0 ? "Fizz" : v).forEachOrdered(System.out::println); | |
} |