Day 7 - Solutions
https://gitlab.com/maximoburrito/advent2023/-/blob/main/src/day07/main.clj
Easy task, especially keeping in mind, that sort works on nested vectors, so you don't need any custom complex comparators
if you thought my day 4 was mind blowing wait till you see my wildcard permutations laughcry
(defn perm [s x]
(let [ks (keys (dissoc strength \J \W))]
(case x
1 (into #{} (for [a ks] (kind (str s a))))
2 (into #{} (for [a ks b ks] (kind (str s a b))))
3 (into #{} (for [a ks b ks c ks] (kind (str s a b c))))
4 (into #{} (for [a ks b ks c ks d ks] (kind (str s a b c d))))
5 #{6})))https://github.com/rjray/advent-2023-clojure/blob/master/src/advent_of_code/day07.clj
Struggled way too much with sorting the hands within their ranks. And, of course, my first run of part 2 errored out for the obvious reason...
Solution: https://github.com/erdos/advent-of-code/blob/master/2023/day07.clj
for me, the trick was to call (comp sort vals frequencies) on the String representation of each hand and it gives a signature that could be used to identify the type of hand.
https://github.com/samcf/advent-of-code/blob/main/2023-07-camel-cards.clj Nothing interesting here, just brute forcing joker combinations. Runs in about 1s
I dont like it, but here's my solution: https://github.com/rmrt1n/advent-of-code-2023-clj/blob/main/src/aoc/day07.clj
frequencies is MVP https://gist.github.com/alexander-yakushev/ff300602825af2d639276df3c456d457
Handling jokers is easy if you recognize that the most useful thing a joker can do is always counting as the other most frequent card in the hand. It is deterministic.
https://github.com/andrewbelo/aoc2023/blob/1a4503fc67fcf1b8b82c6feb13726411db100ce4/src/day_7_camel_cards.clj Also used frequencies
Didn't see the JJJJJ case ahead of time though π«
pretty simple with a little reasoning about how the joker can effect any hand, as @alexyakushev it's deterministic. my solution: https://github.com/Ramblurr/advent-of-code/blob/aad2dfb2db23f3b0689ad2c9d884729da3931448/src/aoc/2023/day07.clj#L61-L73
first frequencies this year! https://github.com/FelipeCortez/advent-of-code/blob/master/2023/07.clj
@andrey.yallowsack.com I thought about that too, but rediscovered that vector length is compared before first element
Encoded cards as hex to sort strings. str/escape is a great tool here. https://github.com/genmeblog/advent-of-code/blob/master/src/advent_of_code_2023/day07.clj
not completely happy with my dissoc dance with the Joker, but:
https://github.com/tschady/advent-of-code/blob/main/src/aoc/2023/d07.clj
Used index-of and type mappings to get scores and then just compare , nothing fancy, but relatively short and working: https://github.com/caseneuve/aoc2023/blob/master/day07/solution.clj
I'm pretty sure you can just use (sort-by first) . compare is not needed here.
Good catch, thanks, @tsulej
Leveraged inherent sorting of vectors in Clojure and made a vector that held [score card-val card-val card-val ...]
https://github.com/bhauman/adv2023/blob/main/src/adv2023/day07/sol.clj
My day 7: https://github.com/rjray/advent-2023-clojure/blob/master/src/advent_of_code/day07.clj Pretty sure my sorting-of-hands could have been cleaner...
My https://github.com/wevre/advent-of-code/blob/f2eecaf5932aabddbc93ef04ffce36990843198f/notes/notes-aoc2023.txt#L132 on my day 7 solution(s).
For me the trick is noticing that the sorted frequency values i.e. [3 1 1] are inherently sortable by the first two entries, no need to categorize further. So if you concat those to a sorted vector of card values [12 12 12 7 2] this gives you a single canonical vector form i.e. [3 1 12 12 12 7 2] and, of course, that vector is automatically comparable to the other vectors. So you get the sorting of hands automatically.
So are you saying, @bhauman, that the first two frequency entries can substitute as the strength of the hand type?
https://github.com/rgm/experiments/blob/master/2023/202312-advent-of-code/07/day_7_2.clj I think that went OK ... a reasonably clean small intervention of reordering the cards and adding one function to get to part 2
@michaeljweaver yes thatβs what Iβm saying π
you do have to pad [5] to [5 0] but all the others sort [4 1] > [3 2] > [3 1] > [2 2] > [2 1] β¦.
Kinda liked this one: https://gitlab.com/mauricioszabo/advent-of-code-2023-clj/-/blob/master/src/advent_2023_clj/day07.clj?ref_type=heads
Nothing fancy but it works. I learned about max-key though! How useful!
Just a thought for mobile, the layout should be all vertical otherwise the columns are quite squished :)