Skip to content

Commit

Permalink
day 1: add a visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
narimiran committed Dec 1, 2024
1 parent 390f7a3 commit 0dd6b4c
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions clojure/day01.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
(ns day01
{:nextjournal.clerk/auto-expand-results? true
:nextjournal.clerk/toc :collapsed}
(:require aoc))
(:require
aoc
[nextjournal.clerk :as clerk]))


;; # Day 1: Historian Hysteria
Expand Down Expand Up @@ -188,22 +190,44 @@




;; ## Visualization
;;
;; Let's see if we can plot the distribution of the values in the right column.
;;
(let [right-freqs (frequencies (second columns))]
(clerk/plotly
{:config {:displayModeBar false}
:data [{:x (map key right-freqs)
:y (map val right-freqs)
:type :bar}]
:layout {:margin {:l 20 :r 0 :t 0 :b 20}}}))

;; As expected, most of the elements have one occurrence, with few exceptions
;; easily visible in the graph.\
;; The winner is `77689` with 20 occurrences.






;; ## Conclusion
;;
;; Much easier Day 1 than we had last year.
;; And I like that.
;; These first days should be about having fun, not about chasing some edge
;; cases (_hello `oneight` my old friend..._).
;;
;; Faster tasks mean more time for writing this "blog" and exploring
;; different solutions.
;; Faster tasks mean more time for writing this "blog", exploring
;; different solutions, making visualizations, etc.
;; I hope this will continue in the next days too.
;;
;; Today's highlights:
;;
;; - `aoc/transpose` - get a list of columns from a list of rows
;; - `comp` - compose two functions
;; - `frequencies` - count appearances of items
;; - `frequencies` - count the number of appearances of items



Expand Down

0 comments on commit 0dd6b4c

Please sign in to comment.