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
pub fn task2_linear() { | |
let input = utils::read_file("input/day02.txt"); | |
// first order of business: create a tree where each input line is sorted | |
// into every nodes same_prefix, if the path leading from the root to that | |
// has that prefix. | |
let mut root = Node::default(); | |
for id in input.lines() { | |
add_id_to_tree(&mut root, &id); |
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 foo.dice-roll-comparison) | |
(def roll-1d20 (for [i (range 1 21)] i)) | |
(def roll-median-3d20 (for [a (range 1 21) b (range 1 21) c (range 1 21)] (second (sort (list a b c))))) | |
(def roll-sum-3d6 (for [a (range 1 7) b (range 1 7) c (range 1 7)] (+ a b c))) | |
(def roll-sum-2d10 (for [a (range 1 11) b (range 1 11)] (+ a b))) | |
(defn probabilities [values] (into (sorted-map) (update-vals (frequencies values) (fn [i] (/ (* i 100.0) (count values)))))) | |
(doseq [[x y] (seq (probabilities roll1d20))] (println x y)) |