Introducing Crunchy Data Warehouse: A next-generation Postgres-native data warehouse. Crunchy Data Warehouse Learn more

Posts about Advent of Code

  • 8 min read

    Advent of Code in PostgreSQL: Tips and Tricks from 2022

    Greg Sabino Mullane

    I’ve nearly finished solving the 2022 series in Advent of Code in PostgreSQL on our blog, many of these are available on our browser based Postgres playground as well. As many of you embark on your own Advent of Code adventures for 2023 this week, or maybe watch from afar, I wanted to pull together some themes, recommendations, tips, and tricks that I’ve seen work with the solutions. If there’s anything I’ve learned, it’s that you can solve almost anything with PostgreSQL! Before you do anyt...

    Read More
  • 25 min read

    Fun with Postgres ASCII Map and Cardinal Directions

    Greg Sabino Mullane

    This article will contain spoilers both on how I solved 2022 Day 23's challenge "Unstable Diffusion" using SQL, as well as general ideas on how to approach the problem. I recommend trying to solve it yourself first, using your favorite language. Tech used in this Day: • The file_fdw Foreign Data Wrapper • Materialized (and not materialized) CTEs aka Common Table Expressions • Custom data types • Various handy functions like string_to_table and array_agg and unnest • Tweaking the plan_...

    Read More
  • 21 min read

    Fun with Postgres Text File Mazes, Charts, and Routes

    Greg Sabino Mullane

    This article will contain spoilers both on how I solved 2022 Day 22's challenge "Monkey Map" using SQL, as well as general ideas on how to approach the problem. I recommend trying to solve it yourself first, using your favorite language. Tech used: • The file_fdw extension to read the input • Unlogged tables • Sequences • Building and modifying arrays via regexp_split_to_array and array_remove • More ASCII animation! The file_fdw extension to read the input Unlogged tables Sequences Bui...

    Read More
  • 8 min read

    Fun with Postgres Looped Functions and Linear Progressions

    Greg Sabino Mullane

    This article will contain spoilers both on how I solved 2022 Day 21's challenge "Monkey Math" using SQL, as well as general ideas on how to approach the problem. I recommend trying to solve it yourself first, using your favorite language. Tech used: • The file_fdw extension to read the input • Functions such as regexp_substr • Unlogged tables The file_fdw extension to read the input Functions such as regexp_substr Unlogged tables As always, we will use file_fdw to put our text input into...

    Read More
  • 11 min read

    Fun with Postgres Floats, Positioning, and Sequencing

    Greg Sabino Mullane

    This article will contain spoilers both on how I solved 2022 Day 20's challenge "Grove Positioning System" using SQL, as well as general ideas on how to approach the problem. I recommend trying to solve it yourself first, using your favorite language. Will I get these all posted before next year's AOC starts? Consider it a bonus challenge! :) Tech used: • CTEs (Common Table Expressions) • Using a non-integer type to help simulate a linked list • The ever useful file_fdw extension • sequence...

    Read More
  • 14 min read

    Fun with PostgreSQL Puzzles: Recursive Functions with Animations

    Greg Sabino Mullane

    We've also loaded a tutorial for Day 19's challenge if you want to try it with a pre-loaded data set. This article will contain spoilers both on how I solved 2022 Day 19's challenge "Not Enough Minerals" using SQL, as well as general ideas on how to approach the problem. I recommend trying to solve it yourself first, using your favorite language. Day 19 tasks us with creating lots and lots of mini robots to gather resources and feed our herd of elephants (rescued a few days back ). We'll do...

    Read More
  • 11 min read

    Fun with PostgreSQL puzzles: Surface Area and 3D Slices

    Greg Sabino Mullane

    This article will contain spoilers both on how I solved 2022 Day 18's challenge "Boiling Boulders" using SQL, as well as general ideas on how to approach the problem. I recommend trying to solve it yourself first, using your favorite language. (heatmap slicing a 3-D piece of lava - all in SQL!) We've also loaded a tutorial for Day 18's challenge if you want to try it with a pre-loaded data set. Tech: 🐘 The ever important file_fdw 🐘 Using sequences as a crude numbering aid 🐘 A recursi...

    Read More
  • 17 min read

    Fun with PostgreSQL Puzzles: Moving Objects with Arrays, Sequences, and Aggregates

    Greg Sabino Mullane

    (Yes, this image was generated completely by SQL statements!) We've also loaded a tutorial for Day 17's challenge if you want to try it with a pre-loaded data set. This article will contain spoilers both on how I solved 2022 Day 17's challenge "Pyroclastic Flow" using SQL, as well as general ideas on how to approach the problem. I recommend trying to solve it yourself first, using your favorite language. Another puzzle featuring elephants! (❤️ ❤️ ❤️). This time, the elephants are involved in...

    Read More
  • 22 min read

    Fun with PostgreSQL puzzles: Finding shortest paths and travel costs with functions

    Greg Sabino Mullane

    This article will contain spoilers both on how I solved 2022 Day 16's challenge "Probscidea Volcanium" using SQL, as well as general ideas on how to approach the problem. I recommend trying to solve it yourself first, using your favorite language. This article is delayed from the actual puzzle's release. My solutions may not be the "best" solution, as the goal is to provide a quick solution. We've also loaded a tutorial for Day 16's challenge if you want to try it with a pre-loaded data set....

    Read More
  • 18 min read

    How to Solve Advent of Code 2022 Using Postgres - Day 15

    Greg Sabino Mullane

    This article will contain spoilers both on how I solved 2022 Day 15's challenge "Beacon Exclusion Zone" using SQL, as well as general ideas on how to approach the problem. I recommend trying to solve it yourself first, using your favorite language. This article is delayed from the actual puzzle's release. Also note that my solutions are seldom going to be the "best" solutions - they were solved as quickly as possible, and these articles will show my first solutions, with some minor reformattin...

    Read More