• 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
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Advent of Code 2018

 
Marshal
Posts: 5764
361
IntelliJ IDE Python TypeScript Java Linux
  • Likes 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's getting to that time of year again when us nerdy types get to shun the trappings and jollies of the Christmas holiday season and absorb ourselves in pointless, but fun, programming puzzles.

That's right! It's time again for the Advent of Code.

Advent of Code wrote:Advent of Code is a series of small programming puzzles for a variety of skill levels. They are self-contained and are just as appropriate for an expert who wants to stay sharp as they are for a beginner who is just learning to code. Each puzzle calls upon different skills and has two parts that build on a theme.


Who's planning on having a go at it this year? Would you be interested in joining a CodeRanch Leaderboard? Just for the giggles of course.

It all starts on Saturday 1st December, obviously. Have fun!
 
Marshal
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
Oh no, again...
 
Saloon Keeper
Posts: 5583
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A year gone by??

Hmm... last year I struggled with assignment 23, when I was accused of cheating. I got so p*** off, I decided never to get involved again! But blood creeps where it can't go (Dutch saying), so I'm afraid you can count me in, again....
 
Liutauras Vilda
Marshal
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
Last year I didn't get a chance to enjoy the prior Christmas period as all days passed by instantly (gone) because of this. But seeing Piet again here, I think I might want too. Have day or two still to think about.

For what is worth, this year the language of choice would be what? I'm thinking about either Kotlin or Scala. Leaning towards Scala more. Piet, we hear some rust metal sound (R...).
 
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 probably will. I wonder if I can reuse the harness I wrote last year for running solutions and verifying answers.
 
Liutauras Vilda
Marshal
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 just got Scala environment setup - write me down too.
 
Liutauras Vilda
Marshal
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
Boys, clean the dust from your keyboards.
 
Tim Cooke
Marshal
Posts: 5764
361
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
The first few days are always nice and straight forward, then they hit you with a right zinger later on. So far so good though.
 
Liutauras Vilda
Marshal
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
Oh, and yes, github.

Tim, technically you got a bug in second part, luckily you didn't have 0 as a frequency in your data set
- Actually, that's not a bug, didn't read carefully, 0 should be a starting frequency as latest example demonstrates.

And to use an Array or List is a slow option due to linear search. Set in this case would work way way faster.
 
Piet Souris
Saloon Keeper
Posts: 5583
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used the fact that Set.add in Java returns a boolean, so that saves a line of code. Seems that Scala does not have that. (but it is Scala, so you save a lot of lines elsewhere     )
 
Liutauras Vilda
Marshal
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:I used the fact that Set.add in Java returns a boolean, so that saves a line of code. Seems that Scala does not have that. (but it is Scala, so you save a lot of lines elsewhere     )


I saw. I had a Scala course (well, not Scala course, but we used Scala as a main language) in University, so I must say I like this language a lot (way more than Kotlin), I just forgot its syntax slightly, but will revise in few days of exercises, and along the way will learn new things.
 
Piet Souris
Saloon Keeper
Posts: 5583
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The add method in Scala does return a boolean, like in Java. I only looked at the + method.

Indeed, my Scala knowlegde is rusty, and its API is still as daunting as ever....
 
Liutauras Vilda
Marshal
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 have lost one position since yesterday. Piet is next to push me down Thanks in advance  

I'm about to refactor my second part to be more functional. Anyway, both solved in Scala again.
 
Tim Cooke
Marshal
Posts: 5764
361
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
Liutauras you are dead right about using a Set rather than an array.

Run times on my laptop...
Before: 0m53.999s
After : 0m0.087s


Now on to today's puzzle.
 
Liutauras Vilda
Marshal
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,
A regular eye may not notice, but what's the story about the @author Sylvia in assignment_02_A?

Does that mean that we were beated by your beloved one this time? Wouldn't be anything tremendously surprising.
 
Piet Souris
Saloon Keeper
Posts: 5583
213
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is because the laptop is my wife's (she is called Sylvia). A couple of years ago I bought her this laptop, then with 64-bit Windows 7. My old PC had 32 bit Windows XP, and when I needed Java8, I confiscated her laptop...

In NetBeans, the template for a new class was 'author: Sylvia', but I changed that to 'author: Piet'. Now it seems to have returned. Must have a look into that...

By the way: in exercise 2B I used an array to circumvent a limitation in the Java Stream. People criticised me for that, I just updated it to use an IntStream. And I managed to shorten the code by one line!

Sofar it has been easy. Waiting for the blow to come....

And there are some very fast members also busy. Reaching the top will be nigh impossible.... so my immediate target is to keep you under me    
(I would not accept that, if I were you, who the f*** does that Souris think he is)
 
Piet Souris
Saloon Keeper
Posts: 5583
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Day 3: a little more involved, but a nice one!
 
Liutauras Vilda
Marshal
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:Day 3: a little more involved, but a nice one!


If I remember correctly, day 3 in last year also was a lot of bother. However, at earliest I could sit down by the exercise in 6-7 hours from now, which is going to be 22h or 23h locally, and then if I'm not too tired, which I am already.

Anyway, Tim mentioned something about the Advent of Excuses, which I seem don't have any competent enough competitors to compete with in that area, so I guess I'm in a good situation still

Can't wait evening to see what's there (I skimmed quickly, but very busy now, so for later...).
 
Tim Cooke
Marshal
Posts: 5764
361
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
For a brief moment in time I am above Liutauras on the leaderboard, I shall savour this moment while I can.
 
Liutauras Vilda
Marshal
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
Really just wanted to get it done, such a sloppy mess. 02:24 AM. Going to sleep, which is left really just few hours.
 
Piet Souris
Saloon Keeper
Posts: 5583
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmmm.... not so easy day 4, a little tedious too. Used many Maps and Comparators<Map.Entry>. Made me feel as if I was doing some heavy coding in SAS.

Some members are not only extremely speedy, but have code that is even shorter than Scala. Amazing.
 
Tim Cooke
Marshal
Posts: 5764
361
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
Yes agreed. Day 4 used a little more brain-power but once I'd got part 1 done then part 2 was a doddle as all I had to do was change my ordering to use the max instead of sum function. It's rare it works out that way but heck I'll take it. I'm snapping at your heels now Piet! That Liutauras is way behind us..... for now.

Some of my Chicago friends have a bit of an advantage in that the puzzles are published at 11pm their time and most of them are already up waiting to get started. Malcolm says he has even set an alarm to remind him. It's mighty addictive.
 
Piet Souris
Saloon Keeper
Posts: 5583
213
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops, I got lucky.

I determined a List<Integer> sleepingMinutes from "falls asleep" to "wakes up" as

but I forgot to do 'map(i -> i % 60)' right after '.range'. So I got lucky that wake up always is in the same minute as falls asleep.
 
Liutauras Vilda
Marshal
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 Cooke wrote:That Liutauras is way behind us..... for now.


You know that comments are tend to go out of date quickly, whether it be code comments or comments here

Day 4 DONE. It was interesting though. GitHub.

Boys, just to be clear, I haven't given up yet! This week for me is a bit crazy with timing.

Anyway, I've got question, how the heck they design and come up with such puzzles in general? How they define set of data, scenarios, how they test that in order to be sure there is indeed only one outcome correct? I find it more difficult to solve this exercise in my head.
 
Liutauras Vilda
Marshal
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, we hold good hopes about you. I think you can get the crown down of this chap who is at the top at the moment
 
Tim Cooke
Marshal
Posts: 5764
361
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 have abandoned all hope of hitting the top of the board. Sree is on fire! She has her sights set on breaking into the top 100 global leaderboard. Her best to date is 114th.
 
Liutauras Vilda
Marshal
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 Cooke wrote:Sree is on fire! She has her sights set on breaking into the top 100 global leaderboard. Her best to date is 114th.


Now I feel that I came from a lower division league team to an upper, except that way way too early.

Tim, are you trying to say that we deal with real professionals over here, so our chances never been greater than "slim". Nice. And "Her". Give good wishes from us (well, at least from me then). Fingers crossed she breaks through 100.
 
Tim Cooke
Marshal
Posts: 5764
361
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 can only speak for myself of course. YMMV.
 
Tim Cooke
Marshal
Posts: 5764
361
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
My Day 5 solution took around 8 minutes to complete on my pretty high spec laptop... oh the shame.

But I managed to refactor and get it down to ~2.5 minutes, which while still terrible, is less so than before.
 
Greenhorn
Posts: 13
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got my Day 5 Part 1 done so fast that could have made the top 100.  Except, I forgot perl $#array returned the index and not the size.  So, my answer was off by 1.  I spent the next 33+ minutes trying to figure out what I did wrong.

Part 2 took an hour, but over half that was reruns with debug output because I didn't put [] around my uppercase+lowercase letter for the regex to strip the letter from the word.


To those asking "Who the heck is this random person?".  I used to work with Tim Cook at the Chicago Mercantile Exchange and participated in his leaderboard last year.  So, by default I showed up for this year and Tim invited me to this discussion.  My code is in a repo linked on my github from my AoC account.  I've also carried the tradition into my new employer and have a leaderboard for my teammates and a chat channel we're bantering about the contest on.
 
Liutauras Vilda
Marshal
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
Welcome to the Ranch

Michael Mraz wrote:Except, I forgot perl $#array returned the index and not the size.  So, my answer was off by 1.  I spent the next 33+ minutes trying to figure out what I did wrong.


Don't worry, I'm on that leaderboard too, except that way below you. So you say you don't write tests too (too means as myself in these puzzles)? I hope slightly differently things go at your work, tsss... in case boss is reading
 
Michael Mraz
Greenhorn
Posts: 13
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Michael Mraz wrote:I used to work with Tim Cook


=~ s/Cook/Cooke/;
 
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
Huh. My day 5 solution runs in half a second.

My Polymer class encapsulates a stack, and every time I add a unit to the polymer, I push it on top of the stack, unless it's the polar opposite of the top of the stack, then I just pop the opposite from the stack instead.

For the second part, I first determine all unique types in the input string, and then for each type, I create a new string that is just the input string with all occurrences of that type replaced by the empty string. I then run each new input string through the solution to part 1 to determine the length, and keep track of the shortest.
 
Tim Cooke
Marshal
Posts: 5764
361
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
Hi Michael, Welcome to the Ranch! great to see you here.

You're not alone in being hindered by silly mistakes. Sreedevi says she was so tired last night she kept submitting the wrong thing and having to wait to be allowed to submit again.

And Liutauras, Sree says thanks for the global top 100 encouragement
 
Michael Mraz
Greenhorn
Posts: 13
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:So you say you don't write tests too



I'm not a software developer by trade.  I do DevOps with a splash of Site Reliability Engineering.  Is that a good excuse for not doing TDD?
I usually default to lots of type statements and using the smaller example input set to see what my logic is doing.
 
Tim Cooke
Marshal
Posts: 5764
361
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
Stephan, I never thought of using a stack for this but it makes total sense. I'm going to have to refactor again now
 
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
Let us know if you get any performance benefit. :)
 
Liutauras Vilda
Marshal
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
You guys careful and don't spoil the logic as I haven't look at the exercise yet. Anyway, nevermind, who can understand you guys...
 
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
Sorry about that. I'll mention my solutions only after the puzzle for the next day has been released.
 
Tim Cooke
Marshal
Posts: 5764
361
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
Holy Smokes!!!

Initial run = 8 minutes
Refactor 1 = 2 minutes 30 seconds
Refactor 2 = Half a second

Thanks very much Stephan!
 
There were millions of the little blood suckers. But thanks to this tiny ad, I wasn't bitten once.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic