Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

AoC 2021 - Day 10 Solutions (Spoilers!)

 
Marshal
Posts: 5222
323
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nice puzzle today. It's not often I have cause to use a Stack data structure, so this was fun.

Part 1

Part 2 looked like it was going to be difficult, but then it dawned on me that the missing characters were whatever was left in the stack at the end of the line. From then it was easy.
 
Marshal
Posts: 8209
585
Mac OS X VI Editor BSD Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Solved it too. My solution is bunch of SWITCH cases, so nothing special to share.

Every single AoC we face a similar puzzle with some slight modifications.
Staff note (Liutauras Vilda) :

I'm sharing my solutions on GitHub: https://github.com/liutaurasvilda/aoc-2021

 
Tim Cooke
Marshal
Posts: 5222
323
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your solution is very similar to mine Liutauras, although for part 2 I notice you had the good sense to only go through the input lines once where I do it twice for no good reason. My first pass removed the corrupted lines, then a second pass to figure out the missing bits for the remaining non-corrupted lines, where I could have worked the non-corrupted lines first time around.

Nice to see and learn from how others do it.
 
Tim Cooke
Marshal
Posts: 5222
323
IntelliJ IDE Python Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Having taken some inspiration from Liutauras, I've refactored part 2 to only do a single pass on the input.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic