adventofcode

2023-12-07T06:18:32.264359Z

Day 7 - Solutions

Ivana 2023-12-07T06:29:10.151319Z

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

πŸ‘ 2
Sam Ferrell 2023-12-07T06:53:12.762749Z

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

rjray 2023-12-07T06:57:54.339009Z

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

erdos 2023-12-07T07:52:12.912719Z

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
Sam Ferrell 2023-12-07T07:58:27.493899Z

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

Ryan Martin 2023-12-13T13:54:24.950829Z

I dont like it, but here's my solution: https://github.com/rmrt1n/advent-of-code-2023-clj/blob/main/src/aoc/day07.clj

oyakushev 2023-12-07T08:02:49.891739Z

frequencies is MVP https://gist.github.com/alexander-yakushev/ff300602825af2d639276df3c456d457

oyakushev 2023-12-07T08:03:38.249829Z

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
2023-12-07T08:10:27.693149Z

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

βž• 5
Casey 2023-12-07T09:06:52.850159Z

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

Felipe 2023-12-07T10:01:11.488419Z

first frequencies this year! https://github.com/FelipeCortez/advent-of-code/blob/master/2023/07.clj

Felipe 2023-12-07T10:02:27.844589Z

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

πŸ‘ 1
genmeblog 2023-12-07T10:05:38.502529Z

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
tschady 2023-12-07T13:18:04.249369Z

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

2023-12-07T13:46:42.728199Z

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

genmeblog 2023-12-07T14:02:45.634559Z

I'm pretty sure you can just use (sort-by first) . compare is not needed here.

2023-12-07T14:35:20.621079Z

Good catch, thanks, @tsulej

bhauman 2023-12-07T16:57:13.206099Z

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

rjray 2023-12-07T19:00:53.167229Z

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

bhauman 2023-12-07T20:10:28.218239Z

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.

wevrem 2023-12-07T20:35:33.125059Z

So are you saying, @bhauman, that the first two frequency entries can substitute as the strength of the hand type?

rgm 2023-12-07T20:42:31.745249Z

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

bhauman 2023-12-07T23:41:31.631809Z

@michaeljweaver yes that’s what I’m saying πŸ™‚

bhauman 2023-12-07T23:44:35.199949Z

you do have to pad [5] to [5 0] but all the others sort [4 1] > [3 2] > [3 1] > [2 2] > [2 1] ….

alpox 2023-12-08T21:12:58.729889Z

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