Win a copy of Spring in Action (5th edition) this week in the Spring 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Advent of Code 2018  RSS feed

 
Greenhorn
Posts: 13
4
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just refactored my day 5 part 2 to use the reacted polymer for the a..z iteration and reduced the runtime from

to


23 times faster is good, right?
 
Sheriff
Posts: 4568
286
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Michael Mraz wrote:23 times faster is good, right?


Right  
 
Marshal
Posts: 6257
420
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Sorry about that. I'll mention my solutions only after the puzzle for the next day has been released.


That's fine These days I really can't sit down on problems instantly, except the late evening on that day, so go ahead guys discussing stuff, I know how interesting that is. I just will skim through these once notice there are details discussed.
 
Master Rancher
Posts: 3001
105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Piet Souris wrote:Some members are not only extremely speedy, but have code that is even shorter than Scala. Amazing.


hi Michael,

welcome!

My remark was about your Perl (?) script. I don't speak Perl and I didn't understand a bit of it, but it was mighty short!

@All
I did probably the same as Stephan, only I used a StringBuilder. The whole program (reading the input, and solve parts A and B) took around 0.77 seconds.

That Tim is becoming a nuisance, closing the gap more and more....
And the Yankees are a legue too far for us mere mortals...

 
Tim Cooke
Sheriff
Posts: 4568
286
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Our Chicaco dwelling friends get a new puzzle at 11pm so just have to stay up a little late to get started. Where I am, in Northern Ireland, I would have to be up and ready for 5am and that ain't gonna happen.

It's early days yet Piet, still plenty of time for the wheels to come off my AoC wagon. #AdventOfExcuses
 
Liutauras Vilda
Marshal
Posts: 6257
420
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I've submitted Day 5 Part 1, I know, a bit late, but that's fine, game isn't over yet. Tim, I hope the rating system works more on the stuff who has more stars, right? In which case if you guys will give up at some point with some cheap excuses, I could still catch up.

Part 1 I found easiest so far of all previous days. Simply iterating over collection and then (char1 - char2).abs == 32 (get rid of both), that means it is a combination of lower/upper. Most costly operation is remove. So I see that Stack what Stephan suggested is obviously an efficient way, because the remove is always O(1), as oppose to O(n) (each time) in case of an Array or List. Anyway, I'll keep it as I have now, it is 2 seconds only. However, second part might require to change something.
 
Liutauras Vilda
Marshal
Posts: 6257
420
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Part 2 done too. Done in my own way. Not a second, but not a minute either. So in this case I prefer to increase sleep minutes rather than reduce program's running time I might still will do.
 
Liutauras Vilda
Marshal
Posts: 6257
420
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, and couldn't resists from sharing. Tim, you are far far behind me See attach pic.
Screenshot-2018-12-06-at-00.04.11.png
[Thumbnail for Screenshot-2018-12-06-at-00.04.11.png]
 
Tim Cooke
Sheriff
Posts: 4568
286
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Day 6 is melting my head
 
Bartender
Posts: 9494
184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's tougher than the puzzles before for sure. I battled a bit with the first part, but the second part was comparatively much easier.

I'll upload my solution later, when I get my Git repo sorted out. There's still a lot of crud there from last year.
 
Liutauras Vilda
Marshal
Posts: 6257
420
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:It's tougher than the puzzles before for sure. I battled a bit with the first part, but the second part was comparatively much easier.


I just understood now the logic behind the given example. It took me about a half an hour (might even one hour) of constant looking to it.

Didn't try to implement yet, but currently it doesn't look very complicated. Will try as soon as I'm available.
 
Tim Cooke
Sheriff
Posts: 4568
286
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also took me a good while to get the requirement straight in my head before I even attempted to go near a computer with it. All done now though, phew!
 
Creator of Enthuware JWS+ V6
Posts: 3181
276
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although I haven't looked at the puzzles, but I just enjoy reading your posts. It must be good fun.

All of you deserve a Cow!
 
Piet Souris
Master Rancher
Posts: 3001
105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Was a bit late, today. And the fact that I had a .flatMap and a .filter in the wrong order (hard to find) didn't help.

Anyway, if you want to practise Maps and all the juggling that can come with it, then this day 6 is your chance!

To make a distinction between a normal Point and a data (input) Point, I created a PietsPoint extends Point, that only has two constructors referring to super. Don't know if that is handy, but it made the Maps a little more comprehensible.
 
Liutauras Vilda
Marshal
Posts: 6257
420
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frits, thanks for the cow!

Frits Walraven wrote:It must be good fun.


No, it isn't. Unless you solved it and watching others struggling. I'm the only one who hasn't solved yet. Started... I'm half way through in Part 1. Got all the areas of all coordinates. Except one thing - don't know yet how to rule out infinity ones So now all can laugh, but it isn't funny for me.

Liutauras Vilda wrote:...currently it doesn't look very complicated


shut up!
 
Piet Souris
Master Rancher
Posts: 3001
105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Frits Walraven wrote:Although I haven't looked at the puzzles, but I just enjoy reading your posts. It must be good fun.

All of you deserve a Cow!


Thanks, Frits!
 
Tim Cooke
Sheriff
Posts: 4568
286
Clojure IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Frits thanks for the cow! There's plenty of room in the leaderboard if you want to join in?

I wonder how Michael "I'm not a software engineer by trade but is kicking all our butts" Mraz found today's day 6 puzzle?
 
Liutauras Vilda
Marshal
Posts: 6257
420
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Part 1 solved. Interesting one indeed. Will commit soon. Will be interesting to sneak into yours to see how you all solved it.
 
Tim Cooke
Sheriff
Posts: 4568
286
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I'll be keeping you behind me on the board this time Liutauras
 
Liutauras Vilda
Marshal
Posts: 6257
420
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved Day 6 Part 2 too.

It was easy! Well, it meant to be easy...    Spent half an hour figuring out what is wrong with my algorithm as instead "total distance to all given coordinates of less than 10.000" I had 1.000 (one zero less), so got nothing as resulting area, and then started looking to wrong places what might be wrong. So then after noticing that got wrong figure from specs, said: "yayay, now all will be fine"!. Executed code, got result - bang! Answer is Too High! What? Well, it says "less than 10.000" not "less than or equal to 10.000", so spent another half an hour

Oh dear... all that today's misery ended finally. I have a feeling that this year is kind of a bit more difficult than last year. Or my Racket skills are better than Scala's. Missing #Racket #'N #Its #Recursion #To #Be #Honest

Tim, indeed, you beat me on this one, so now I'm behind.

As a bonus puzzle for us all, we can calculate the resulting area of the obtained stars in a whole private group, I think it shrinks slowly
 
Michael Mraz
Greenhorn
Posts: 13
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Cooke wrote:I wonder how Michael "I'm not a software engineer by trade but is kicking all our butts" Mraz found today's day 6 puzzle?



I got part 1 done correctly and ran into the bug with certain input sets failing with correct solutions.  Saw the problem reported in the reddit thread so I grabbed the part 2 using a second, anonymous account I am submitting on which didn't have the bug and wrote up my part 2 solutions.  When I woke up Thursday mornign the bug had been fixed and I submitted both parts successfully.  (Explaining in case anyone is looking at the JSON API output and sees the timestamps on my day 6 submissions within minutes of each other.)

I pushed my code this evening.  Visualizing the grid like in the example and how to place distances and transitions through each coordinate when traversing the optimal distance route between points seemed the way to go.  The key was to make a grid of all the input points, measure the distances and the number of times each coordinate crossed the points between each point.  Then I made a set with all the points in a 10K grid and joined the grid counts into the set.

I had to lean hard on perl's array references and tying.  Learned about flattened zipping 2 arrays into a multi-dimensional array too.  Was way more complicated than I had hoped.

You Java programmers got me all jealous with your varied data types in the stdlib.  I have hash, array and scalar to work with because perl is the only thing I can program quickly in.
 
Michael Mraz
Greenhorn
Posts: 13
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, I vaguely remember a taxicab distances problem from last year.  Different problems for both parts, but the same logic applied. At least I knew how to calculate the distances.
 
Michael Mraz
Greenhorn
Posts: 13
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Say 7 is beginning on a [ur=https://xkcd.com/323/l]Balmer Curve[/url] with the intention of making top 200 for part 1.  Wish me luck.
 
Michael Mraz
Greenhorn
Posts: 13
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Michael Mraz wrote:Say 7 is beginning on a [ur=https://xkcd.com/323/l]Balmer Curve[/url] with the intention of making top 200 for part 1.  Wish me luck.


No way to edit posts on this forum, eh?  I can see how I've slipped out of the  curve
 
Liutauras Vilda
Marshal
Posts: 6257
420
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim, don't tell me that for 2nd part of today's stuff you are going to implement concurrent version with BlockingQueue

I understand what is asked in 2nd part, just the labor work looks pretty annoying. Part 1 however was easy.
 
Stephan van Hulst
Bartender
Posts: 9494
184
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For those interested, my solution to day 6: https://github.com/Nibsi/Advent-of-Code/blob/master/puzzles/puzzle-year-2018/src/main/java/nl/nibsi/aoc/puzzle/y18/d06/Day06Puzzle.java

It's verbose firstly because I jammed all classes into one file and secondly because I didn't refactor to deduplicate code. It works fast though.
 
Stephan van Hulst
Bartender
Posts: 9494
184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved day 7 by writing a Graph class and repeatedly removing 'roots' from it (nodes without incoming edges). For the second part, I associate a counter with each node, and decrement it each second on roots that are currently 'in progress'. Only when the counter reaches 0, the root is removed and the rest of the algo works pretty much the same as part 1.

Day07Puzzle
Graph
 
Liutauras Vilda
Marshal
Posts: 6257
420
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice organization and readability. Wouldn't be surprised if you even re-used some of the parts from last year's AoC when you created bunch of re-usable components.
 
Tim Cooke
Sheriff
Posts: 4568
286
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bumbled my way through Day 7 Part 1 but was such a mess that Part 2 is near impossible. The level of technical debt I have created in mere hours is astounding.

Rewrite in progress........
 
Tim Cooke
Sheriff
Posts: 4568
286
Clojure IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeepers that was hard work! Satisfying to get all of Day 7 done though.
 
Michael Mraz
Greenhorn
Posts: 13
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Cooke wrote:Jeepers that was hard work! Satisfying to get all of Day 7 done though.



Reading through your steps2.py was a combination of "That logic makes sense" and "WTF does that do?" to me.  Then I realized you were keeping track of state, for all aspects of a task, on each worker and it made a lot more sense.  Less potential for array values out of synchronization when they all belong to the same object.
 
Tim Cooke
Sheriff
Posts: 4568
286
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Michael Mraz wrote:a combination of "That logic makes sense" and "WTF does that do?"


I'll probably feel the same way tomorrow if I'm honest. I chose to use Python because I don't use it hardly ever and want to gain some more familiarity with it. I don't pretend for a second to be any good at it.
 
Piet Souris
Master Rancher
Posts: 3001
105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What a nightmare! Spent the whole evening looking for a bug in part B. Couldn't find it, made a mess of my code trying everything, hairs turned grey from the misery, just found it.
I had:

Still can't believe it.... self confidence = Integer.MIN_VALUE;
 
Liutauras Vilda
Marshal
Posts: 6257
420
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm just simply wandering somewhere around and don't see a light at the end of the tunnel, any end. Head is totally empty now. Probably will give up on this one tonight and will go sleep with an expectation for tomorrow. But tomorrow will be 3 problems to solve, instead of 2. But had similar situation last year, it was just day 3, a spiral problem, which caused me also a headache.
 
Tim Cooke
Sheriff
Posts: 4568
286
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Day 8 is a welcome relief after yesterday. Straight forward enough, and even quite happy with the solution design too which is a rare thing.
 
Liutauras Vilda
Marshal
Posts: 6257
420
BSD
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Boys and Girls... I've nailed it, Day 7 (yesterday's) Part 2 done.

Definitely a fresh morning is more clever than tired night.

Yesterday I've done Part 1 in a less than opimum way, and that was the main reason why I was struggling with Part 2. Simply I was trying to accomplish 2nd part's requirements with Part 1 code, which was not well organized, in short - bad.

This morning I've deleted code and started over. This is what we suggest often, right? So took this advice myself

Watch my beauty:


Lesson learned:
Regardless, whether it is a puzzle or anything else - always pay tremendous attention to code organization. That way no puzzle is unsolvable.

I've got 2 today's puzzles to solve. Will do in an evening.
 
Michael Mraz
Greenhorn
Posts: 13
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Cooke wrote:Day 8 . . . Straight forward enough, and even quite happy with the solution design too which is a rare thing.



You used a queue.  I need to learn how to do that.  It's more about thinking through how to process the queue as entries and nested entries are encountered.  I used a recursive function to get to the metadata for the first entry and then parse backwards through all the children as they were encountered.
 
Michael Mraz
Greenhorn
Posts: 13
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:Watch my beauty:
\[code=scala\]object Day7



I was going to ask what language it was as it looked a bit like Java and Groovy to me.  Quoting your message revealed the code block which you labeled with the language so I got my answer.  Some of the development teams I support use Scala and I had to learn sbt configuration to update their build processes.  Looks interesting.  I should probably learn it.
 
Tim Cooke
Sheriff
Posts: 4568
286
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I don't know Perl at all but you can use any list like structure as a queue as long as there are facilities to take things off one end of the list and put things on the other. I see in perl you can use an array like a queue by limiting use to the push and shift functions.

 
Piet Souris
Master Rancher
Posts: 3001
105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just solved day 8, I had no time yesterday. Reconstructed the Tree by using a mixture of iteration and recursion. The code worked beautifully for the example given, but I was plagued by a StackOverflow in the real thing. Fortunately, the bug was easy to spot. Part B was very easy.

How do you increase the Stack size? I tried java -Xss1024M, but still got the same overflow error, so that did not seem to work.

Just had a look at day 9. Looks a bit tedious, with all that marbles and placement rules. We'll see.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!