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

Discussion (68)3
Log in or sign up to continue

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.

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

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

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.

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

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.