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 translate-roman-numerals.test | |
(require [clojure.test :refer :all] | |
[translate-roman-numerals.core :refer :all])) | |
(deftest give-values-test | |
(are [given-value calculated-value] (= given-value calculated-value) | |
2 (letters-value \I 2) | |
2 (letters-value \I 4) | |
10 (letters-value \V 2) | |
10 (letters-value \V 2) |
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
;; tldr | |
;; distinct, slow | |
;; "Elapsed time: 84.1618 msecs" | |
;; set | |
;; "Elapsed time: 32.7301 msecs" | |
;; non-overlapping | |
;; "Elapsed time: 1.6902 msecs" | |
;; transducers | |
;; "Elapsed time: 0.5955 msecs" |
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
(defn sum-intervals | |
"c describes parts of a sequence. Some parts overlap. | |
Give a sum of all the unique items in the sequence." | |
[c] | |
;; Build the items | |
;; Pour 'em all into a single collection | |
;; (Implementation: Is range inclusive or exclusive? Doesn't matter. If i) | |
;; Set 'em | |
;; Count 'em. | |
(->> (map #(range %1 %2) c) |
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
;; drop-take | |
(defn eviscerate-sequence | |
([c i] (eviscerate-sequence c i i)) | |
([c st end] (concat (take st c) (drop (inc end) c)))) | |
;; loop-recur | |
(defn eviscerate-sequence | |
([c i] (eviscerate-sequence c i i)) | |
([c start end] | |
(let [c (apply list c)] |
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
Tic Tac Toe Code Review | |
1. What is the code trying to accomplish? | |
Show who won on a completed tic-tac-toe board. Return nil if a draw. | |
2. Describe at a high level how it works. | |
It transforms the tic toe board, a vector of vectors, three times: |
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
(defn fizzbuzz | |
"If div by 3, fizz; if by div by 5, buzz; | |
if div by both, fizzbuzz" | |
[num] | |
(if (zero? (mod num 3)) | |
(if (zero? (mod num 5)) | |
"fizzbuzz" | |
"fizz") | |
(when (zero? (mod num 5)) | |
"buzz"))) |
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
From Clojure for the Brave and True | |
Chapter 2 | |
https://www.braveclojure.com/basic-emacs/ | |
How to wield emacs | |
Important part is the feedback loop, set up a REPL | |
Install and configure | |
Different install options per OS | |
Different exes for MacOS | |
`sudo apt` instructions at launchpad |
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 amazing-defmulti) | |
(defmulti needs-food | |
(fn [person] (:is-hungry person))) | |
(defmethod needs-food true [person] "This person needs food.") | |
(defmethod needs-food false [person] "This person is well fed.") | |
(def steve {:is-hungry true}) | |
(def joe {:is-hungry false}) | |
(defn needs-food-if [person] |
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
(defn pem-helper [sq symb] | |
(loop [tail sq i 0] | |
(if (seq tail) | |
(if (= (first tail) symb) | |
i | |
(recur (rest tail) (inc i))) | |
nil))) | |
(defn pem-mult-i [sq] | |
(pem-helper sq '*)) |
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 whoop.core | |
(:gen-class)) | |
;; . | |
;; /' | |
;; // | |
;; . // | |
;; |\//7 | |
;; /' " \ | |
;; . . . |