Bert Sarens · Dec 1, 2017

Adventofcode.Com 2017 is live :)

Hello everyone,


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


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.

0 1,108
Discussion (68)7
Log in or sign up to continue

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")


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.

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 ;)

They will still be there on christmass :p

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....

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

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)
        set normalized = normalized _ key _ occurrences
    quit:$d(%normalized(normalized))>0 $$$NO
    set %normalized(normalized) = 1
    quit $$$YES

Normalized words:

  • aaba -> a3b1
  • aaab -> a3b1

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