Re: Advent of Code, another way of practicing programming skills.

Indeed! We are on day 7! My bad for not checking this earlier, but I solved this one myself not too long ago
I stored the bag rules by using a dictionary and just parsing the bags to look like something like the following:

rules = {
  "bright white bag": ["shiny gold bag", "pink bag", "brown bag"],
  "shiny gold bag", [], # No bags
  "pink bag": ["gray bag", "blue bag", "black bag"],
  #...
}

Doing it on 523 lines of input is kind of slow, though. I'm sure that there is a better way of doing this, but I couldn't figure it out... perhaps make the bag colors all integers? But then you would have to keep track of all the seen bags, and I feel like that'd be a mess and generally more trouble than its worth.
Another thing you could try is cache the already done bags. You could then just retrieve the results from the dictionary to build your remaining rules (I know for a fact that multiple bags can eventually contain duplicate patterns). Again, seems overkill.
I suppose you could build a graph-like structure, where you have nodes leading to other nodes, and that should work, but I don't know. I feel like it's an overkill, even though it was my first solution to the problem.
I really enjoyed this one, though, took me a bit to think of how to approach it.
Let me know if you need more help.



-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : bhanuponguru via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : JayJay via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Kyleman123 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Kyleman123 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector

Reply via email to