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 11 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
Weekend puzzles are always harder, mostly because it's harder to find quiet computer time with family around.

I found today quite fiddly, and resulted in quite fiddly code. Thankfully part 2 was a small edit on top of part 1.

Part 1.


Part 2

 
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
Today it was just "get it done". I have no doubts it could be refactored to no end. I'll see if I have enough Energy  to do it later in the evening.
[UPDATE: did a first round of refactoring]

But for now, here is me, dumbo,  have solved it this way:

Main

Energy

Location
 
Liutauras Vilda
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

Tim Cooke wrote:


Actually that's quite cool. I don't think I ever come across this method. I always iterate with forEach or similar... Nice to know it, it seems from couple of my solutions I could remove 2 methods from each.
 
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
That was courtesy of IntelliJ. I had written a standard iteration solution and it reckoned it could do better, and it did. I have since realised that it can be simplified even further.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic