Skip to content

Instantly share code, notes, and snippets.

@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
@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)
### 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 / 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)
@briansunter
briansunter / reddit.clj
Created September 8, 2016 06:02
Infinite reddit post channel
(defn get-posts
[ch]
(go-loop [a nil]
(let [res (get-posts-page a)
posts (res :children)
after (res :after)]
(do
(doseq [p posts]
(>! ch p))
(recur after)))))
### Keybase proof
I hereby claim:
* I am brsunter on github.
* I am bsunter (https://keybase.io/bsunter) on keybase.
* I have a public key ASBzjQ_kiOqWsGQwMPjxucWSWfX4cUoBNTfvhQ0Aaw2Vggo
To claim this, I am signing this object:
@briansunter
briansunter / clojure-protocol-redux.md
Created January 24, 2017 08:16
clojure spec multimethods as a better protocol

How can we extend functionality in Clojure without modifying the orignal source?

Let's say we want to computer the area of some Shape types like Square and Circle

We have multiple shapes all of which have an area function

We may have some function called sum-areas that takes a list of Shape , calls area on each of them, and sums them up. We don't have access to the original source, but want the ability to add new shapes.

@briansunter
briansunter / anagrams.clj
Created April 6, 2017 01:26
Hacker Rank: Making Anagrams
;; https://www.hackerrank.com/challenges/ctci-making-anagrams
(defn char-frequencies
[x]
(reduce #(update %1 %2 (fnil inc 0)) {} x))
(let [a (read-line)
b (read-line)
a-freq (char-frequencies a)
b-freq (char-frequencies b)

Keybase proof

I hereby claim:

  • I am briansunter on github.
  • I am bsunter (https://keybase.io/bsunter) on keybase.
  • I have a public key ASBVOoYHoBuiOUESsbkQWkzNtgWfyBubrPz-MUrL_DaC6Qo

To claim this, I am signing this object:

@briansunter
briansunter / top500songsrollingstones.csv
Created September 3, 2020 07:03
Top 500 Songs Rolling Stones
Song Artist
Like a Rolling Stone Bob Dylan
(I Can't Get No) Satisfaction The Rolling Stones
Imagine John Lennon
What's Going On Marvin Gaye
Respect Aretha Franklin
Good Vibrations The Beach Boys
Johnny B. Goode Chuck Berry
Hey Jude The Beatles
Smells Like Teen Spirit Nirvana