Caching and Pattern matching - Day 12 - Advent of Code

Sdílet
Vložit
  • čas přidán 11. 12. 2023
  • In this episode, we walk through solving day 12 of Advent of Code 2023, called "Hot Springs". The challenge involves parsing records of hot springs, some of which are damaged (#) or operational (.), along with checksums indicating groups of damaged springs.
    First, we set up some test cases and write a parse method to process the input. Then we implement a count method using recursion and pattern matching to count all valid arrangements of springs that match the checksums. Key cases include:
    - Encountering a "?" which represents variable springs
    - Incrementing "group size" when we hit pound signs to track damaged groups
    - Checking that group sizes match checksums when we reach periods
    - Caching results to speed things up
    For part 2, we expand the strings by duplicating parts and joining them to make the problem more complex. More optimizations like collapsing multiple dots and returning early based on string lengths are added.
    In the end, we arrive at a working solution that passes the test cases and puzzle input!
    Advent of Code: adventofcode.com/
    My Solutions: gist.github.com/cjavdev/d15a2...
    Playlist • Advent of Code
    #adventofcode #ruby
  • Jak na to + styl

Komentáře • 3

  • @pnazzy
    @pnazzy Před 5 měsíci

    Thank you SO MUCH for making this. I'm new to both Ruby and AOC and part 2 of this problem has been the only one that's stumped me so far! Watching you work through it made it seem so much simpler and I picked up some new Ruby syntax!
    If you have a moment, I have a couple slightly off topic questions:
    1) I've been using Minitest for my AOC problems and with Rails. Is Rspec generally more preferred, or is there any reason to use one over the other?
    2) I'm in my last semester of college and so far I love Ruby and Rails enough to know that I'd definitely prefer working with Ruby. Any good tips for landing a job working with Ruby? My only work experience is from the military, so I'm coming into the field with a degree and no tech experience.
    Thanks again!

    • @cjav_dev
      @cjav_dev  Před 5 měsíci

      Glad to hear! I also use mini test with rails at work. Both are good to know, but it’s more important to learn the general patterns for testing and then using either tool to apply those patterns.
      One tip for landing a job is to work on your personal Ruby and rails projects in public. Blog or tweet about what you’re learning, share your projects on github, find places online where other Rubyists are: discord channels, sub reddits, etc. and help other folks. :)

  • @piotrtalarczyk8987
    @piotrtalarczyk8987 Před 5 měsíci

    OK. 1st part was hard for me, 2nd part defeated me.