Skip to content

Instantly share code, notes, and snippets.

@briansunter
briansunter / distinct-by.clj
Last active May 15, 2023 22:28
distinct-by clojure transducer
(defn distinct-by
"Returns a lazy sequence of the elements of coll, removing duplicates of (f item).
Returns a stateful transducer when no collection is provided."
{:added "1.0"}
([f]
(fn [rf]
(let [seen (volatile! #{})]
(fn
([] (rf))
([result] result)
### Keybase proof
I hereby claim:
* I am brsunter on github.
* I am bsunter (https://keybase.io/bsunter) on keybase.
* I have a public key whose fingerprint is B645 9886 0C4B 4D32 0808 4F92 6DCA DB61 0750 9E0A
To claim this, I am signing this object:
@briansunter
briansunter / Day7.hs
Created January 19, 2016 05:31
Advent of code Day 7
data Circuit = Signal Word16
| Wire Label
| AndGate Circuit Circuit
| OrGate Circuit Circuit
| LShiftGate Int Circuit
| RShiftGate Int Circuit
| NotGate Circuit deriving (Eq, Show, Ord)
newtype Label = Label String deriving (Show, Ord, Eq)
@briansunter
briansunter / Base10M
Last active August 29, 2015 14:08
Convert Base 10 to Base 1.1 Million
module Base10M
(encode
,decode) where
import Data.List(elemIndex)
import Data.Maybe(fromJust)
unicodes = ['a'..]
numOfUnicodes = toInteger $ length unicodes