Skip to content

Instantly share code, notes, and snippets.

View Crowbrammer's full-sized avatar
🌎
Grateful

Aaron Bell Crowbrammer

🌎
Grateful
View GitHub Profile
@Crowbrammer
Crowbrammer / roman_numerals_decoder-test.clj
Last active April 25, 2022 20:02
Roman Numerals Decoder
(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)
@Crowbrammer
Crowbrammer / sum_of_intervals_benchmark.clj
Created April 22, 2022 17:24
Benchmark for interval summations
;; 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"
@Crowbrammer
Crowbrammer / sum_of_intervals.clj
Last active April 22, 2022 16:51
Sum of Intervals Solution
(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)
@Crowbrammer
Crowbrammer / eviscerate_sequence.clj
Last active April 20, 2022 12:02
Eviscerate sequences
;; 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)]
@Crowbrammer
Crowbrammer / 1-ttt.txt
Last active December 14, 2021 11:19
Interview Questions
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:
(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")))
@Crowbrammer
Crowbrammer / brave-clojure-ch2-full-outline.txt
Created August 18, 2021 09:29
Full outline for Brave Clojure, Chapter 2
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
@Crowbrammer
Crowbrammer / defmulti.clj
Created April 28, 2021 17:00
Multimethods
(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]
@Crowbrammer
Crowbrammer / infix-macro.clj
Created April 10, 2021 11:33
Multiply with infix notation in Clojure
(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 '*))
(ns whoop.core
(:gen-class))
;; .
;; /'
;; //
;; . //
;; |\//7
;; /' " \
;; . . .