Advent of code is fun, if you like programming.

In December every day thru Christmas you get a little puzzle that you need to write code to solve. You get some text and some rules; a single value will be the answer.

I wrote a programming language (called SAI) a while ago and I'm using it to solve these puzzles. I may post a few solutions here, so if you want to solve them on your own, don't read further, or any other "Advent" posts.

-- spoiler --

Here's the solution to the first puzzle, December 1.

In the code below, source is the provided input to your puzzle solver and the two debug statements print out the solutions to parts 1 and 2 of the puzzle:

  set
    elements to source.split('') thru it-0 // note!
    previous to elements last
    result to 0

  each elements as elem
    if previous = elem 
      set result + elem 
    set previous to elem
    
  debug "Part 1: ${result}"

  set
    result to 0
    len to elements.length
  
  count 0 to len as pos1
    set pos2 to (pos1 + (len/2)) % len
    if elements[pos1] = elements[pos2]
      set result + elements[pos1]
      
  debug "Part 2: ${result}"

I designed SAI to be easy to read and with a minimum of punctuation and special symbols, so it looks more like pseudo-code than actual code, and in general resembles a typed out version of what you would verbally describe a program to be doing. Also, this program is certainly not as efficient as one could make it. But I believe that readable and maintainable are more important than efficiency, with very narrow exceptions.

Note that SAI compiles to Javascript, so is subject to some of Javascript's bullshit, in particular the strange handling of numeric values vs strings of digits. A simple and fast way of converting a string to a value (if you're sure it is convertible) is to subtract 0 from it; that's what is happening here.

MORE
12/8 '17 4 Comments
I finished these as you gathered on Facebook. Enjoyed it a lot. Thanks for the nudge.
I wanted to let you know that I deliberately haven't read this because I kept thinking I was going to do the puzzles... you know, in my copious spare time... and I guess I'm still thinking that... it could happen... it's still the holidays!
I did all 25 puzzles and found a few bugs in my parser, so that was double cool! Also it was a fun way to start the day. I'm going back and poking at 2016's puzzles to do a bit more refinement and tweaking of the language before I get the latest version on github where it can be safely ignored.
That's awesome! I am blasting through, but I'm doing it in the language I use all day, so duh. I'm forcing myself to use ES6-isms, though.