• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Advent of Code 2022

 
Sheriff
Posts: 8988
652
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
https://adventofcode.com/

Tim C. I have problems with patience.

Are we going to have usual suspects?
 
Bartender
Posts: 15737
368
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
https://adventofcode.com/2022/leaderboard/private/view/60807

I'm already in 11th place!

There is also Al Hobbs' leaderboard: https://adventofcode.com/2022/leaderboard/private/view/554112
 
Marshal
Posts: 5792
368
IntelliJ IDE Python TypeScript Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You hardly need to ask if I'm in Liutauras, it's a given. I've already started to plant the seed with my team at work to get involved again, although again not much persuasion is required.

My leaderboard is a bit of a hodgepodge of folks from past work teams and coderanch friends. Happy to keep using it of course and it does have the added challenge of trying to stay ahead of Sree who has historically dominated.
 
Sheriff
Posts: 17734
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just completed Day 1. Doing it in Kotlin again. I need a refresher. Too many calories in my Kotlin program
 
Tim Cooke
Marshal
Posts: 5792
368
IntelliJ IDE Python TypeScript Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Firmly in the comfy seat of Java. I'm just enjoying the ride while it lasts, which if past form is any indicator will be up until about day 15.
 
Stephan van Hulst
Bartender
Posts: 15737
368
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MAYBE this year I'll finally get round to using Rust, but knowing me I'll just stick with Java.

Had a slow start today because I didn't have internet all day. The correct answer was sitting in the input field, I just had to hit submit.
 
Liutauras Vilda
Sheriff
Posts: 8988
652
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm doing it in Racket (Lisp) again, like the very first time I did in AoC back in 2017 which were most successful to me, so who could deny this time will be even more better.

And the actual reason being, that my least optimum solutions could be elegantly hidden in between the parentheses (a lot of them).
 
Bartender
Posts: 5584
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But don't you risk a StackOverflowException, with all these ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((( et cetera)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))?
 
Master Rancher
Posts: 5116
82
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kotlin again for me.  Though maybe it is time to try something new.
 
Liutauras Vilda
Sheriff
Posts: 8988
652
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Piet Souris wrote:But don't you risk a StackOverflowException, with all these ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((( et cetera)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))?


Problems to me normally start way before that. When it gets too messy, to get opening and closing brackets intact become much harder than the puzzle itself. Once I counted on fingers.
 
Junilu Lacar
Sheriff
Posts: 17734
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Simmons wrote:Kotlin again for me.  Though maybe it is time to try something new.


Me, too.

I'm putting my solutions up on GitHub: https://github.com/jlacar/adventofcode2022-kotlin/tree/main/untitled/src/main/kotlin

It's fun revisiting Kotlin although I suspect I might be doing some things very Java-ishly.

If you get a chance, please post some comments on how I'm doing things. The Good, the Bad, the Ugly, all's good.
 
Junilu Lacar
Sheriff
Posts: 17734
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Day 3, Part 1 solved. Did I say Kotlin is sweet yet? Kotlin is sweet.
 
Junilu Lacar
Sheriff
Posts: 17734
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Day 3, Part 2 solved.  

It's sweet when prior refactoring for part 1 makes solving part 2 a lot easier.
 
Piet Souris
Bartender
Posts: 5584
213
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Day 3 solved. Sofar things have been easy.
 
Tim Cooke
Marshal
Posts: 5792
368
IntelliJ IDE Python TypeScript Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yea so far so good. Early days yet though and plenty of time for the wheels to come off.
 
Liutauras Vilda
Sheriff
Posts: 8988
652
Mac OS X Spring VI Editor BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Racket is beautiful. I said multiple times over the time, there are languages you work with, and there are languages you love. Racket is the latter.

Mostly it is used in academia these days to teach functional programming. And once you get into that mindset, you can find it very succinct and to the point.

Also solved Day 3.
 
Junilu Lacar
Sheriff
Posts: 17734
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:Racket is beautiful.


I took a quick look at it and it seems like it would be a good candidate for learning with Conway's Game of Life. I'm going to put Racket on my list of languages to learn. Thanks!

I'm still very enamored with Kotlin right now. I've been tweaking my Main program to run solutions and so far I have this:

To give me this output:

Day 1 (Day1-sample.txt)
Part 1: 24000 ✅
Part 2: 45000 ✅

Day 1 (Day1.txt)
Part 1: 71502 ✅
Part 2: 208191 ✅

Day 2 (Day2-sample.txt)
Part 1: 15 ✅
Part 2: 12 ✅

Day 2 (Day2.txt)
Part 1: 14264 ✅
Part 2: 12382 ✅

Day 3 (Day3-sample.txt)
Part 1: 157 ✅
Part 2: 70 ✅

Day 3 (Day3.txt)
Part 1: 7446 ✅
Part 2: 2646 ✅

Day 4 (Day4-sample.txt)
Part 1: ❌ expected [1] but got [6]
Part 2: ❗ (pending...)
 
Junilu Lacar
Sheriff
Posts: 17734
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Day 4 solved.

Problem seemed easy enough at first glance but it took me longer to get done than I anticipate. Part of it was refreshing on Kotlin ranges and constructors/initializers and deciding on a couple of design choices.

Essentially, convert to ranges, then count full containment (part 1) and overlaps (part 2)
 
Piet Souris
Bartender
Posts: 5584
213
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Indeed easy again. But we haven't seen the last of it yet.... that hint to "longer numbers ...456...." probably means misery awaiting.

I used a record called Range, and I wanted to give it a constructor with a String parameter of the form "3-6". but I could not get that to work, some error about something being not canonical or likewise. So I added a static method Range of(String s), and that worked.

Java, of course.

edit: github
 
Tim Cooke
Marshal
Posts: 5792
368
IntelliJ IDE Python TypeScript Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I very much drop into "stream of consciousness" mode when coding these solutions. Day 4 for me was variables for the upper and lower bounds followed by a largely incomprehensible if this and or that condition.

Looking forward to the days where the immediately obvious solution exceeds space and/or time constraints and requires a bit of proper thinking. I enjoy those ones the most.
 
Piet Souris
Bartender
Posts: 5584
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Be careful with what you wish... one day you might get it (and that'll be sooner rather than later)
 
Junilu Lacar
Sheriff
Posts: 17734
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Piet Souris wrote:edit: github


Nice. Thanks for sharing. I knew there was a better way to determine overlap and I already knew that formula. Just goes to show (again) that I tend to complicate first, then simplify than the other way around.

Here's my Kotlin solution on GitHub

Very similar to your Java solution.

Great minds, huh? ;)
 
Junilu Lacar
Sheriff
Posts: 17734
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Piet: was looking at your Day 1 solution -- just want to point out that singular of Elves is just Elf.

Very similar solutions again.

More comments/questions in the AoC 2022: Day 1 solutions discussion
 
Liutauras Vilda
Sheriff
Posts: 8988
652
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've got Day 4 solved too, where part 2 was very easy and short, however, part 1 got a bit sloppy mess, which I'm going to work on refactoring now that stress faded away
 
Piet Souris
Bartender
Posts: 5584
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Junilu Lacar wrote:@Piet: was looking at your Day 1 solution -- just want to point out that singular of Elves is just Elf.


Thanks! Just like in Dutch then: elf - elven
 
Junilu Lacar
Sheriff
Posts: 17734
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Piet Souris wrote:Indeed easy again. But we haven't seen the last of it yet.... that hint to "longer numbers ...456...." probably means misery awaiting


And so it starts with Day 5.

Parsing this puzzle's input alone is going to be "fun". Parsing is really the bulk of the problem. The rest is just a matter of performing the appropriate stack operations.
 
Piet Souris
Bartender
Posts: 5584
213
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just read the exercise. Indeed the problem is the inputfile. Three strategies come to mind: using a regex to determine the position of each letter, the positions of the letters are fixed, so require just some counting, and typing the piles into your code, which is probably the quickest way. Won't have time until this afternoon, though.
 
Tim Cooke
Marshal
Posts: 5792
368
IntelliJ IDE Python TypeScript Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh boy, now begins the challenge of string parsing. I think I have an idea of how to tackle it, wish me luck.
 
Stephan van Hulst
Bartender
Posts: 15737
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't bother parsing the initial stacks. I just pasted them straight into my code and transposed them by hand.
 
Tim Cooke
Marshal
Posts: 5792
368
IntelliJ IDE Python TypeScript Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Might not be a bad idea. I just noticed that the stack count and sizes aren't all that large. I had expected there to be loads of really deep stacks making it impractical to do it manually.
 
Stephan van Hulst
Bartender
Posts: 15737
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My general strategy for every day includes first looking at my input to determine which parts I can do by hand, and which parts I must automate. I believe if you want to make a chance getting any points at all on the general leaderboard, you mustn't waste time writing code unnecessarily.

Of course, getting any points at all on the general leaderboard also means getting up in time to start the puzzle when it is published. I'm not doing that this year.

After I submit my answer, I automate the parts I initially solved manually.
 
Liutauras Vilda
Sheriff
Posts: 8988
652
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't deal with badly formatted data. I fix it first.  ...built stacks by hand.

Day 05 done.
 
Piet Souris
Bartender
Posts: 5584
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Solved day 5.

Again easy, but a bit tricky, it was easy to make some mistakes, like forgetting to skip some elements and to re-initialize the stacks between the first and the second part. But it was again fun.

I did the input manually, by far the fastest way, I think. So my input-routine for the test looked like:
 
Liutauras Vilda
Sheriff
Posts: 8988
652
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Piet Souris wrote:easy to make some mistakes, like forgetting to skip some elements and to re-initialize the stacks between the first and the second part


This is where Racket's immutable data types are very handy. You fiddle with the stack you get a new stack (in my case I used hash table + lists).

I overall finding immutable data types much easier to cope with than mutable. In majority of the cases performance impact isn't significant. If ever is, it is algorithm.
 
Tim Cooke
Marshal
Posts: 5792
368
IntelliJ IDE Python TypeScript Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did end up programmatically parsing the input text for day 5, but I do take some delight in text wrangling so quite enjoyed it.
 
Liutauras Vilda
Sheriff
Posts: 8988
652
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim, I just had a look at your test suite. Found one:

I think I understand better now what those package names mean: com.timdrivendevelopment
Staff note (Stephan van Hulst) :

 
Stephan van Hulst
Bartender
Posts: 15737
368
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For Day 6, I might have written the shortest code I've written for AoC so far.
 
Tim Cooke
Marshal
Posts: 5792
368
IntelliJ IDE Python TypeScript Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ha ha busted!

In my defence, that's the default template code you get when you run the maven generate command. I'm being lazy and haven't tidied up.
 
Tim Cooke
Marshal
Posts: 5792
368
IntelliJ IDE Python TypeScript Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Day 6 fairly straight forward, and I even wrote some unit tests just for you Liutauras.
 
Junilu Lacar
Sheriff
Posts: 17734
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:For Day 6, I might have written the shortest code I've written for AoC so far.




Kotlin's windowed() function on sequences made the solution almost trivial.
 
Could you hold this kitten for a sec? I need to adjust this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic