Skip to content

Instantly share code, notes, and snippets.

@ordnungswidrig
Last active December 4, 2021 17:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ordnungswidrig/21224314590b871456cd4ccb2633ca8e to your computer and use it in GitHub Desktop.
Save ordnungswidrig/21224314590b871456cd4ccb2633ca8e to your computer and use it in GitHub Desktop.
AoC-2021 - pointfree - threading
# part one
pbpaste | bb -I -e '(->> (-> *input* (#(vector % %)) (update 1 rest)) (apply map <) (filter true?) count)'
# part two
pbpaste | bb -I -e ' (->> *input* (iterate rest) (take 3) (apply map +) (#(vector % %)) (#(update % 1 rest)) (apply map <) (filter true?) count)'
# part one
pbpaste | bb -I -e '(->> *input* (partition 2) (reduce (fn [[x y] [c v]] (case (keyword (name c)) :forward [(+ x v) y] :down [x (+ y v)] :up [x (- y v)])) [0 0]) (apply *))'
# part two
pbpaste | bb -I -e '(->> *input* (partition 2) (reduce (fn [[x y a] [c v]] (case (keyword (name c)) :forward [(+ x v) (+ y (* a v)) a] :down [x y (+ a v)] :up [x y (- a v)])) [0 0 0]) butlast (apply *))'
# part one
pbpaste | bb -i -e ' (->> (-> (->> *input* (apply map (fn [& s] (->> s (map #(->> % {\0 1 \1 -1})) (reduce + 0) (#(/ % (Math/abs %))) (+ 1) (#(/ % 2)))))) (#(vector % %)) (update 1 (fn [x] (->> x (map #(- 1 %)))))) (map #(Integer/parseInt (apply str (map str %)) 2)) (apply *))'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment