Adventofcode.Com 2017 is live :)

Hello everyone,

 

From now till the 25th of december each day 2 programming problems to sharpen your programming skills.

http://adventofcode.com/

 

Theme this year:

The night before Christmas, one of Santa's Elves calls you in a panic. "The printer's broken! We can't print the Naughty or Nice List!" By the time you make it to sub-basement 17, there are only a few minutes until midnight. "We have a big problem," she says; "there must be almost fifty bugs in this system, but nothing else can print The List. Stand in this square, quick! There's no time to explain; if you can convince them to pay you in stars, you'll be able to--" She pulls a lever and the world goes blurry.

When your eyes can focus again, everything seems a lot more pixelated than before. She must have sent you inside the computer! You check the system clock: 25 milliseconds until midnight. With that much time, you should be able to collect all fifty stars by December 25th.

Collect stars by solving puzzles. Two puzzles will be made available on each day millisecond in the advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!

You're standing in a room with "digitization quarantine" written in LEDs along one wall. The only door is locked, but it includes a small interface. "Restricted Area - Strictly No Digitized Users Allowed."

It goes on to explain that you may only leave by solving a captcha to prove you're not a human. Apparently, you only get one millisecond to solve the captcha: too fast for a normal human, but it feels like hours to you.

  • + 5
  • 0
  • 706
  • 68

Comments

I joined it :)

 

PS.: you can have multiple private leaderboards, in case you wonder.

I'm in. Here's my solution.

Thought about using $zstrip, but while it can remove duplicates, it can't leave only duplicates:

w $zstrip("11223","=E")
123

 

Also, for second task it says:

1212 produces 6: the list contains 4 items, and all four digits match the digit 2 items ahead.
1221 produces 0, because every comparison is between a 1 and a 2.

Shouldn't 1221 produce 3 as first 2 and second 1 match.

Currently failed on second task with 10938.

I also started from $zstrip,  but in task 1111 should produce 1, when $zstrip returns only one 1.

for the second task, you should simply compare values from the first half of string with the same position from the second half. 

 set input="1212"
 set len=$l(input)/2
 set sum=0
i=1:1:len {
   if $e(input,i)=$e(input,len+i),$i(sum, i*2)
 }
 zw sum

This is smart! )

I did part2 checking the whole length :/

Should've done Day 3 part 1 same as you. Deriving the formula took me like half an hour.

Here's mine: https://github.com/eduard93/AOC/tree/master/AOC

Where is Danny when you need him? I guess he got a bit tired by doing 2016 one :) 


 

 

Guessed right : found out that i still have a wife and two kids, ... bummer ;)

Darn it Bert, these things are addictive!

There's no way I'm getting up at 5am to even possibly get on the main leader board, but its fun to see how we all approach it.

I'll post mine up here....

https://gist.github.com/SeanConnelly/065cb51fc6572c6bf3dac4a9973fb54f

And maybe a few JavaScript ones as well if I get time...

https://gist.github.com/SeanConnelly/e0623e13241fd94fbf8df96b09755f95

Just for fun, one liners get an extra point - everyone rolls eyes :)

Day three part 2...

s (x,y)=0,d=7,g(0,0)=1,a="+1  -1" f i=1:1 {s e=$s(d=7:1,1:d+2),d=$s($g(g(x+$e(a,e,e+2),y+$e(a,e-2,e)))="":e,1:d),x=x+$e(a,d,d+2),y=y+$e(a,d-2,d),g(x,y)=$g(g(x,y+1))+$g(g(x,y-1))+$g(g(x+1,y))+$g(g(x+1,y+1))+$g(g(x+1,y-1))+$g(g(x-1,y))+$g(g(x-1,y+1))+$g(g(x-1,y-1)) i g(x,y)>t ret g(x,y)}

Not getting up at 5 am here either.

But seeing different solutions in cache is worth it.

 

I wonder, guys, how did you solve that the word is Anagram in Day4:

A valid passphrase must contain no two words that are anagrams of each other - that is, a passphrase is invalid if any word's letters can be rearranged to form any other word in the passphrase.

For example:

  • abcde fghij is a valid passphrase.
  • abcde xyz ecdab is not valid - the letters from the third word can be rearranged to form the first word.
  • a ab abc abd abf abj is a valid passphrase, because all letters need to be used when forming another word.
  • iiii oiii ooii oooi oooo is valid.
  • oiii ioii iioi iiio is not valid - any of these words can be rearranged to form any other word.

 

My solution is:

ClassMethod IsAnagram(word,test) as %Boolean {

if $L(word)'=$L(test) return 0

f i=1:1:$L(test) if $seq(test($E(test,i))),$seq(word($E(word,i)))

set a=$O(word(""))

while a'="" {

if word(a)'=$g(test(a)) return 0

set a=$O(word(a))

}

return 1

}


The full solution is here.

I implemented a simple hash function for it. I just created a new word from all the letters in alphabetical order.
If it's the same word. tadaaa. Code is found in my bitbucket above.

 

anagram used all letters, so I just compared lengths of strings and used $tr() to remove all characters from string one in another.

So, your code I would change like 

ClassMethod IsAnagram(word,test) as %Boolean {

  if $L(word)'=$L(test) return 0

  return $tr(word,test)=""

}

This is beautiful! I like $tr!

But wrong )

 E.g. it would not work for this example:

oiii ioii iioi iiio 

it's not valid, but for your example would be valid.

I first translated each word into normalized form - array of [letter, number of occurrences], ordered by letters. And then just checked if given normalized form already exists:

ClassMethod IsLettersUnique(word) As %Boolean
{
    set length = $length(word)
    for i=1:1:length {
        set letter = $e(word, i)
        set temp(letter) = $i(temp(letter))
    }
    
    set normalized = ""
    set key = ""
    for {
        set key=$order(temp(key),1, occurrences)
        quit:key=""
        set normalized = normalized _ key _ occurrences
    }
    
    quit:$d(%normalized(normalized))>0 $$$NO
    
    set %normalized(normalized) = 1
    
    quit $$$YES
}

Normalized words:

  • aaba -> a3b1
  • aaab -> a3b1

Oke,
The guys on the leaderboard are pretty insane.

I got up 2 mornings at 6am. (Thats when it starts for me.)
Started programming but being done and making no mistakes in 10 minutes or less to get on the leaderboard is just nuts.

Looks like we in the same timezone, and you solve tasks faster than me. When your time today was 15:47 minutes for the first task. But on the main Leaderboard fastest time 2:58. I really don't understand how it would be possible, to solve it so fast.

Today's task was pretty difficult, it takes few hours to solve it. I made a mistake in first part even if I got the right answer, but after when I rewrote my first part, the second part was solved quite fast. But I lost so much time to figure it out.

I thought about actually building the tree in ppg and recursively iterating over it till the error is pinpointed. But it sure would take a lot of time to implement. What's your approach? Any shortcuts?

In the first implementation, I tried to actually build the tree. But missed something, and got some duplications in the lowest branches. Then using the same tree trying to solve second part, I found more than one unbalanced branches and a long time had not noticed how it could be until I noticed duplications. Then I removed this way, and first part becomes much simpler if just search node which does not have parents. In the second part, you actually already have a tree when you know when it started from the first part.

It is not that the task was so difficult, for me it was more that debugging it was very complicated.
That and understanding the assignment was not easy for me toady.
 

 

We decided to promote and support the contest, and launched a challenge on Global Masters:

 

We would track the private leaderboard with code: 130669-ab1f69bf. Join this private leaderboard, solve tasks with Caché ObjectScript be the leader in the end and get the endless fame plus 10,000 GM points! 

2nd and 3rd places would get 5,000 and 3,000 points too.

Yes, there is some handicap for current members:

But we wouldn't change anything: we believe you have enough time and talent to beat them!

Let's have fun and let the COS power be with you! ;)

And, to join Global Masters just use your WRC creds on the login page, or leave a comment to this post, that you are participating in the contest, we would send you a special invite code.

Can you make it a requirement to share your code?

That way, we can learn something from other people and how they solve things.

I was planning on sharing my code at the end of the event, I think it is more fair that way

As soon as the number of points for the task depends on the time passed after task availability it’s relatively save to share it once you solved it. 

So it’s OK to show up the repo after the marathon ends but of course I would only appreciate to see the discussions around nice solutions in COS.

That is fine for me.

The only thing that we will miss a bit is the dirty code in case you clean in it up. But I can live with that. 
I learned a lot by watching the other repositories :)

Thought I might get the jump on at least one person above me on the board this morning, awake just an hour after day 9 started, all done in less than 9 mins, only to find all three have already been up and done it surprisesurprisesurprise

I might have to start setting the alarm...

Hi, Bert!

You are right! The winner should show the public repository with solutions in Caché ObjectScript to be recognized as a winner.

But I think it’s OK to share solutions even now. I would only appreciate it.

 

Jozef, Have you allready joined our intersytems private leaderboard? the code is: 130669-ab1f69bf

(you can join multiple btw if you are allready in a leaderboard)

Hi Bert, I'm already in as Daniel Reck (the successor of Josef Aßfalg)

My best result for the leaderboard was today:

Day       Time  Rank  Score       Time  Rank  Score
 15   00:10:36   312      0   00:13:22   198      0

And t hat means I am still only top 200. I was 4 minutes to slow.
How close have you guys come to top 100?

 

EDIT: I could have been 1 minute faster btw if I didnt submit the result of the test case as the first result. Waiting one minute doing nothing sucks.

My best day was a few days ago, but still very slow.

Day       Time  Rank  Score       Time  Rank  Score
 12   00:09:34   243      0   00:18:42   378      0

I'm usually much slower than you guys. Looks like you have more experience solving such tasks than me, you already solved both previous years.

11   00:08:01     90     11   01:55:04   1458      0

Had to take a break between these two, but barely top 100 on the first - the second part was quite easy so if I hadn't taken a break, maybe I would have been able to get top 100 again

The breaks are hard to deal with indeed. I have 1h tops and then I have to take care of the kids. After that I have to hope that I find some time at work.

I was 11 seconds faster on part 2 then you today dmitry. That was close.
I think I could have been faster if I didnt brute force it. Once you get a cycle I guess you can calculate where you should end up. I just did all 1B iterations :p

Day 18 was quite interesting, with two parallel jobs and communication between.

How do you realize this communication? Maybe the simplest way was to use Global. But I used $system.Event here.

I did not bother doing the jobs parallel. Turn-based did come up with an answer reasonably fast.

But I'm sure it would be interesting to sort out how to execute them in parallel. In any case I'm sure I'll be playing around with $system.Event (didn't know that one)...

Well I did the same as Ivo, just kept running the 2 jobs in the same loop.
I think you can trade info with globals as well.

 

Well done everyone, looks like you are all doing really well. I missed a few days and struggling to find the time to catch up now. Maybe boxing day :)

I just did mine state based, while one needed to wait, just flipped the state to the other

Today I really regret not getting up early...

started at 7:05 and finished first part in 12min, second part in 18min -> would get me a place in top 100...

sad

 

That means you probably used the best method to solve this problem. That method is not writing bugs. It helps a lot.

Wow. Day 23.

Hardest one for me so far. By the time I found out what the inner loops did I was about to give up. Such a simple optimisation as well.

 

I made the leaderboard today!!!!

Am insanely happy although it was only place 98: 

24   00:18:19   118      0   00:20:52    98      3

Congrats!!

I discovered that I'm no good at multi-tasking (surprise!)... Babysitting and coding is not an ideal combination

 

 

It is done. I will finally be able to sleep a bit more again.
Thank you all for making it a great race. I had lots of fun.

Yeah, question is, what will we do now?

In any case, thanks to everyone for sharing your code! It has been fun an educational!

 

I will probably finish the one from 2016. have 4 days to do that I never finished. After I will be able to relax and for next year I am going to prepare with macros and code snippets.

Oh and synacor, i will do synacor as well.

Hey, guys! Congratulations! I think we are ready to announce a winner of our home COS championship ;)

Guys, please share your GitHub or any other public repos with COS in UDL inside?