This file contains hidden or 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 kingdomino.core | |
(:require [instaparse.core :as insta]) | |
(:gen-class)) | |
(def size 100) | |
(def delta-sides 5) | |
(def ncols 2) | |
(def delta-dominos 10) | |
(def colors {:clay "#cc6600" :field "#ffff66" :water "#33ccff" :pasture "#00cc00" :forest "#669900" :mine "#5c5c3d"}) |
This file contains hidden or 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
#include <iostream> | |
#include <tuple> | |
#include <cmath> | |
#include <cstdlib> | |
#include <iterator> | |
#include <vector> | |
#include <algorithm> | |
#include <string> | |
// STEPS=100;for i in $(seq $((3 * $STEPS)) $((8 * $STEPS))); do ./chaos-polygons $(bc -l <<< "scale=2;$i / $STEPS") > generated-cmax-100-$i.pgm; done | |
// for i in generated-cmax-100-*.pgm; do convert $i ${i%.pgm}.png; done |
This file contains hidden or 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 clojr.core | |
(:require [instaparse.core :as insta]) | |
(:import (clojure.lang DynamicClassLoader))) | |
(import '[clojure.asm ClassWriter Type Opcodes] | |
'[clojure.asm.commons Method GeneratorAdapter]) | |
(def parser | |
(insta/parser | |
"prog = expr (<#'[\\n]+'> expr?)* |
This file contains hidden or 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
#include <iostream> | |
#include <iterator> | |
#include <string> | |
#include <tuple> | |
#include <functional> | |
#include "transducers.hxx" | |
#include "tuple_reader.hxx" | |
// usage: seq 1 20 |./FizzBuzz 3 Fizz 5 Buzz |
This file contains hidden or 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
#include <functional> | |
// TODO : monoid | |
template<typename... Fn> struct composer; | |
template<> struct composer<> { | |
template<typename Data> Data operator()(Data d){ return d; } | |
}; | |
template<typename F0, typename... Fn> | |
struct composer<F0, Fn...> : private composer<Fn...> { | |
F0 f; | |
composer(F0 f0, Fn const&... fn): composer<Fn...>(fn...), f(f0){} |
This file contains hidden or 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
#include <array> | |
#include <iostream> | |
#include <numeric> | |
#include <algorithm> | |
#include <tuple> | |
#include <sstream> | |
/* const correctness and pass by value vs const ref, move semantics | |
left as an exercise to the reader. | |
iterator range API prevents a flatmap as the flatmapped function | |
could not either return a value or a range. |
This file contains hidden or 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
Decoding compiled method 0x00007fe951138a90: | |
Code: | |
[Entry Point] | |
[Constants] | |
# {method} '<init>' '(Ljava/net/URLClassLoader;Ljava/lang/String;)V' in 'java/net/URLClassLoader$1' | |
# this: rsi:rsi = 'java/net/URLClassLoader$1' | |
# parm0: rdx:rdx = 'java/net/URLClassLoader' | |
# parm1: rcx:rcx = 'java/lang/String' | |
# [sp+0x20] (sp of caller) | |
0x00007fe951138bc0: mov 0x8(%rsi),%r10d |
This file contains hidden or 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
(defn power [a n op] | |
"Compute a to the (positive int) power n using operator op, using | |
exponentiation by squaring." | |
(let [ power-accumulate-positive (fn [r a n op] | |
(let [r (if (odd? n) (op r a) r)] | |
(if (= 1 n) | |
r | |
(recur r (op a a) (quot n 2) op))))] | |
(if (odd? n) | |
(let [n (quot n 2)] |
This file contains hidden or 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 rxjava-datomic.query | |
(:require [datomic.api :as d]) | |
(:use [clojure.repl :only [pst]]) | |
(:import [rx Observable] | |
datomic.Peer)) | |
(defn query [qry & inputs] | |
(Observable/toObservable | |
(Peer/q qry (object-array inputs)))) |
This file contains hidden or 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
(defn- optimal-plan-ordered [bids] | |
(let [optimal-plan-after (fn [flight] | |
(let [earliest (+ (:DEPART flight) (:DUREE flight)) | |
after (drop-while #(< (:DEPART %) earliest) bids)] | |
(if (empty? after) {:gain 0 :path '()} (optimal-plan-ordered after)))) | |
current-plan (fn [flight] | |
(let [{:keys [gain path]} (optimal-plan-after flight)] | |
{:gain (+ (:PRIX flight) gain) :path (conj path (:VOL flight))}))] | |
(reduce #(if (> (:gain %2) (:gain %1)) %2 %1) (map current-plan bids)))) |