Skip to content

Instantly share code, notes, and snippets.

Lukas Steiger Tok

Block or report user

Report or block Tok

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Tok
Tok / von_neumann_ordinal.clj
Created May 21, 2019
Von Neuman ordinals as Clojure sets.
View von_neumann_ordinal.clj
(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)))
@Tok
Tok / VonNeumannOrdinal.java
Created May 21, 2019
Von Neumann Ordinals as Java HashSets
View VonNeumannOrdinal.java
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(","))) + "}";
}
@Tok
Tok / gist:ab5bcc92fb67a122e9d23c7683d2cfe2
Created May 20, 2019
Von Neumann ordinals as Kotlin Sets
View gist:ab5bcc92fb67a122e9d23c7683d2cfe2
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()
}
@Tok
Tok / gist:9792289
Created Mar 26, 2014
Java 8 FizzBuzz One-Liner
View gist:9792289
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);
}
You can’t perform that action at this time.