/advent-of-code-2020-clj

Primary LanguageClojureMIT LicenseMIT

Advent of Code (2020)

Advent of Code in Clojur(Script) and Babashka.

2020 Goals

  • Write Clojure(Script) code that also works with Babashka
  • Use transducers where appropriate

Update: as for the second goal, looks like I’m satisfied to just write a hacky version that works, for now.

These are the same goals I had in 2017. I don’t have much call to use CLJS in my daily work, and I haven’t been using transducers much, so it’s reasonable to set the same goals.

Well, we do have Babashka now, too! 😍

Setup

cp session.netscape.dist session.netscape

Update session.netscape to reflect the session id available in your browser.

Usage

Fetching input

curl -b session.netscape https://adventofcode.com/2020/day/2/input > resources/data/day-02

Run all at once

% bin/run-day day-00
day-00 part-1
clj  [[0 3] [1 2] [2 5]]
cljs [[0 3] [1 2] [2 5]]
bb   [[0 3] [1 2] [2 5]]
day-00 part-2
clj  part-2
cljs part-2
bb   part-2

Clojure

clojure -X com.grzm.advent-of-code.advent-2020.day-00/run :part :part-1
# => [[0 3] [1 2] [2 5]]

Clojure Tests

clojure -M:test
make test
clojure -M:test --watch
make test-watch

ClojureScript

shadow-cljs compile day-00-part-1
node target/day-00-part-1
# => [[0 3] [1 2] [2 5]]

The default make target will build all non-test shadow-cljs builds

make

Babashka

bb --classpath "$(clojure -Spath)" --main com.grzm.advent-of-code.advent-2020.day-00 -- part-1
# => [[0 3] [1 2] [2 5]]
# wrapper script
bin/run-bb day-00 part-1
# => [[0 3] [1 2] [2 5]]

License

Copyright © 2020 Michael Glaesemann

Distributed under the MIT License.