SQL Puzzle: Advent of Code

Leave a comment

August 29, 2018 by Kenneth Fisher

A few years back someone started the Advent of code. If you aren’t familiar with it, it’s an advent calendar of coding puzzles. Each day of December before Christmas there are two puzzles (with very Christmasy descriptions). You can do them with any language you choose, or even multiple languages. I personally find it a challenge to do a coding puzzle with a language like SQL that’s really meant to be a batch language. That said, the first puzzle of the 2017 advent calendar is to take a long string of numbers and add up all of the ones where the next number is the same as the current one. So the ‘9991’ is 18, the first two count, the third one doesn’t because the next number is 1. ‘1234’ would be 0 because in no case is the next number the same as the current one. Oh, and it’s a loop. So the last number get’s compared with the first one.

So, here’s my variation. Construct your own random string of 200 digits, then calculate the total. Oh, and do your best to avoid loops. We like batches better don’t we? 🙂

The advent of code gets harder as it goes, but even at the beginning, it’s great practice in T-SQL, particularly if you are a developer.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 6,758 other subscribers

Follow me on Twitter

Archives

ToadWorld Pro of the Month November 2013