adventofcode 2023-12-07

Easy task, especially keeping in mind, that sort works on nested vectors, so you don't need any custom complex comparators

πŸ‘ 2

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})))

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.

πŸ™Œ 1
πŸ™ŒπŸ» 1

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

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.

πŸ‘ 2
πŸ™Œ 1

Didn't see the JJJJJ case ahead of time though 🫠

βž• 5

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

@andrey.yallowsack.com I thought about that too, but rediscovered that vector length is compared before first element

πŸ‘ 1

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

3

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.

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

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] ….

Nothing fancy but it works. I learned about max-key though! How useful!