Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Advent of Code 2020

 
Marshal
Posts: 7933
548
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:It's just for fun remember, not really a competition.


Deep in your heart you know that's not entirely true. There is a reason when I look at the exercise 8.30am you already have it solved.


Piet Souris wrote:And looking at the scoreboard, my only ambition left is to be in that scoreboard in the first place.


Well, my immediate ambition is to have some safe buffer from Piet's score .. which is not big at moment, shrinks successfully.
 
Saloon Keeper
Posts: 12608
273
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Piet Souris wrote:Is it me, or is that assignment pretty laborious?


It was, but I enjoyed it regardless. I just know this puzzle will come back to haunt us, so I have taken the time to use strong types for all passport entries.

Jj Roberts wrote:I'm giving it a crack for the first time. I'm using Ruby, learning on the fly. I'm still a really green programmer, I'll see how far I get


Have you joined Tim's leaderboard yet? If so, what's your screen name?
 
Saloon Keeper
Posts: 283
42
Firefox Browser MySQL Database Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, I haven't. I thought I would have enough of a job to complete the puzzles . I might still join for the fun of it.
 
Sheriff
Posts: 4961
318
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
Please do.
 
Bartender
Posts: 4272
160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:Well, my immediate ambition is to have some safe buffer from Piet's score .. which is not big at moment, shrinks successfully.


You the Great Pro considering humble me as a competitor makes me feel honoured! But I have to admit: my best days are far beyond me, unfortunately. For instance, I had quite some trouble understanding your Racket-code.
 
Piet Souris
Bartender
Posts: 4272
160
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:It was, but I enjoyed it regardless. I just know this puzzle will come back to haunt us, so I have taken the time to use strong types for all passport entries.


Yes, I invested some time in a Passport class.

For interested people: my GitHub name is PietSnot, a well-known Dutch name.
 
Jj Roberts
Saloon Keeper
Posts: 283
42
Firefox Browser MySQL Database Java Ubuntu
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Cooke wrote:Please do.



I joined . My name is Jesse on there. I'm surprised that I'm not at the bottom!  
 
Tim Cooke
Sheriff
Posts: 4961
318
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
Snapping at the heels of Liutauras, nicely done.
 
Piet Souris
Bartender
Posts: 4272
160
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jj Roberts wrote:I joined . My name is Jesse on there. I'm surprised that I'm not at the bottom!  


Whoaat??? You are ahead of me! Is Trump right? Is there a big fraude??      
 
Liutauras Vilda
Marshal
Posts: 7933
548
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Piet Souris wrote:You the Great Pro considering humble me as a competitor makes me feel honoured!


Oh Piet, we both know that's other way round, my hat off!

Tim Cooke wrote:Snapping at the heels of Liutauras, nicely done.


Jj Roberts, now that's not entirely fun. I'm not sure whether you were told or not, but I'm not that fascinated about the loss idea so please behave.


 
Tim Cooke
Sheriff
Posts: 4961
318
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

Liutauras Vilda wrote:Deep in your heart you know that's not entirely true. There is a reason when I look at the exercise 8.30am you already have it solved.


That's a fair observation  
 
Liutauras Vilda
Marshal
Posts: 7933
548
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's getting ridiculous, I'm getting bubble sorted down the list

I found part 2 confusingly written, took some time to understand what's required.
 
Tim Cooke
Sheriff
Posts: 4961
318
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
Yes me too. I went all round the houses trying to think of the available seats as a grid of 128 x 8 seats. That didn't work out until I reread the puzzle instructions and did what was suggested there. Still don't really understand the logic in the id derivation.
 
Stephan van Hulst
Saloon Keeper
Posts: 12608
273
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not proud of my solution, but it was quick: I generated a set of all possible seat IDs, and then eliminated all IDs that could be generated from the list of boarding passes. Then I inspected the remaining "unclaimed" seats by eye and saw that there was only one that didn't fit any pattern, and just gambled that that was the required seat. I didn't bother writing a solution that picked the correct seat for me.
 
Tim Cooke
Sheriff
Posts: 4961
318
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
Stephan, that's what I did at first but even after removing the front and back row and deleting IDs present in the input file I was still left with over 200 IDs. Still don't really get how it was so wrong.
 
Jj Roberts
Saloon Keeper
Posts: 283
42
Firefox Browser MySQL Database Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did the same as Stephen. After confirming that it was right, I read the challenge again and fixed it to return the correct seat.
 
Piet Souris
Bartender
Posts: 4272
160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Horrible assignment....

I got everything right, couldn't find a fault, but my answer B was wrong. Checked and rechecked, spent hours, only to find that the answer should be the ID, while I kept sending the full number (with all these B's and R's). Nightmare.

I turned the list to a sorted ID-array, and then looked to see which two successive elements differed 2.
 
Liutauras Vilda
Marshal
Posts: 7933
548
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Piet Souris wrote:
I turned the list to a sorted ID-array, and then looked to see which two successive elements differed 2.


That's exactly what I did. By sorting and looking at them I reverse engineered requirements and understood what potentially is being meant by those misleading +1 and -1 IDs.

We all know how to find the missing number in a list 1..N, but these werent from 1, so I didnt want to spend more time trying to wrap my head around and just used recursion to iterate over.
 
Piet Souris
Bartender
Posts: 4272
160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Indeed confusing was that the flight was full, so I expected there to be 1024 seats minus a few. However, there were only 875 Strings in the input. I then realized there would be much more gaps but apparently only one that differed 2.
 
Stephan van Hulst
Saloon Keeper
Posts: 12608
273
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The hint to the second part was written awkwardly, but makes sense in retrospect. Here are the unassigned seats for my program input:

The plane is missing 6 seats in the front, and a whole bunch in the back. I guessed the seat I was looking for was seat 711 because it stuck out like a sore thumb, but I only understood the hint in the question after I had given the correct answer.

Your seat wasn't at the very front or back, though; the seats with IDs +1 and -1 from yours will be in your list.


710 and 712 were in my list of assigned seats, so 711 is the seat I'm looking for.
 
Tim Cooke
Sheriff
Posts: 4961
318
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
I iterated the list of boarding passes checking for existing boarding passes for ID + 2, but missing ID + 1, then ID + 1 must be mine. Also checking for ID - 2 and ID -1 where an existing ID - 2 and missing ID - 1 means ID -1 must be mine.
 
Master Rancher
Posts: 3754
48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I sorted the list and looked for consecutive entries with a difference of two; it popped right out.

Which I now see is exactly what Piet said.  Serves me right for posting before catching up.

Today, annoyingly, my perfect part 1 solution was hobbled by the fact that I somehow cut and pasted an incomplete copy of the input file.  Wasted some time rechecking everything else before I thought to look at that.
 
Tim Cooke
Sheriff
Posts: 4961
318
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
There appeared to be a problem where sometimes the input content got truncated on load

https://twitter.com/ericwastl/status/1335466285946302465?s=19
 
Stephan van Hulst
Saloon Keeper
Posts: 12608
273
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My solution was hobbled by the fact that I just couldn't get out of bed before 10:30 today.
 
Liutauras Vilda
Marshal
Posts: 7933
548
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I set my alarm 5am this morning, and then voluntarily cancelled it when the time came, just couldn't get up so early. I'd find much easier just not to go sleep till 5.

Luckily day 6 was alright. Part 2 was literaly just one word change in my solution, from set-union to set-intersect.
 
Piet Souris
Bartender
Posts: 4272
160
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why o why does list1.retainAll(list2) return a boolean instead of a new collection?
 
Tim Cooke
Sheriff
Posts: 4961
318
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

Piet Souris wrote:Why o why does list1.retainAll(list2) return a boolean instead of a new collection?


I'm with you on that one, it's not intuitive at all. Perhaps the Guava library does a better job of it with their library of immutable collections? I haven't checked.
 
Liutauras Vilda
Marshal
Posts: 7933
548
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Piet Souris wrote:Why o why does list1.retainAll(list2) return a boolean instead of a new collection?


My only guess is to control the number of references created to mutable collections. Indeed very unintuitive to get boolean, less of use.
 
Liutauras Vilda
Marshal
Posts: 7933
548
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's interesting though, that looking to retro stats i.e. starting from 2017, this year AoC has almost 2.5 times more users (112850 vs 47045) who solved Day 1 exercise comparing to 3 years ago. In other words, more and more people every year enjoy AoC.
 
Mike Simmons
Master Rancher
Posts: 3754
48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Isn't retainAll just like most other methods in the standard collections library?  Given a choice between returning a new object, and mutating the original, they choose the latter.  It's not intuitive if you're used to immutable objects, but it seems pretty standard for java.util collections.
 
Stephan van Hulst
Saloon Keeper
Posts: 12608
273
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also believe the name "retainAll" betrays its mutable character. "Retain these and throw out the others". The immutable variant would be called "intersect" or "getIntersection".
 
Tim Cooke
Sheriff
Posts: 4961
318
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
Today, Day 7, shouldn't have been particularly tricky but I'd messed up my recursion logic which stalled me for most of the morning.
 
Stephan van Hulst
Saloon Keeper
Posts: 12608
273
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wasted 20 minutes this morning by thinking about the problem too quickly and thinking I might solve it with a tree. After a while I figured I was better off making a graph data structure instead and then I solved both problems very quickly.
 
Tim Cooke
Sheriff
Posts: 4961
318
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
I started the same as you but soon realised the tree was tricky because there wasn't a single 'root' node.
 
Piet Souris
Bartender
Posts: 4272
160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Used two Maps, for parts A and B. Then using a Queue to solve A, and a Fibonacci-way to solve B.

Very nice exercise, though a bit laborious. Most important: I'm ahead of Liutauras (for the time being)!!!
 
Liutauras Vilda
Marshal
Posts: 7933
548
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have dreadful time with Racket. Part 1 solved though.

Was trying to wrap my head around with recursion along with functional constructs inside, but the brains just didn't work, so was wandering somewhere close by. Then added a mutable hashtable (sorry racket) and got it solved pretty quickly - solution is not long, but horrible though mutating state (global) all over the place.

Now have part 2, and already missed my lecture for today.
 
Marshal
Posts: 71682
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Simmons wrote:Isn't retainAll just like most other methods in the standard collections library? . . .

It was designed twenty year ago, when there was less understanding of the importance of immutability.
Also, other Collection methods change the state of the target object, e.g. add() and remove(). So it didn't occur to them that mutability might be so useful. Also there were more fears about slow execution from creating new object in those days.
 
Mike Simmons
Master Rancher
Posts: 3754
48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, yes.  I wasn't trying to reconstruct all the thinking behind it, just pointing out it's consistent with the general design of the collections framework.  
 
Tim Cooke
Sheriff
Posts: 4961
318
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
Straight forward enough today, although I do feel like we're building some foundations for something bigger soon. I'm expecting to need a few bits and bobs from previous solutions to solve new ones.
 
Those are the largest trousers in the world! Especially when next to this ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic