---
title: "Solving the \"Impossible\" in ClickHouse: Advent of Code 2025"
description: "All 12 Advent of Code 2025 puzzles are solved in pure ClickHouse SQL, each as a single query that parses the raw input and computes both parts with no UDFs, temporary tables or preprocessing."
url: "https://swe.quest/articles/solving-the-impossible-in-clickhouse-advent-of-code-2025-a7dba91c6e7476ad"
canonical: "https://clickhouse.com/blog/clickhouse-advent-of-code-2025"
source: "ClickHouse"
published: "2025-12-31"
difficulty: "medium"
kind: "How-to"
reading_minutes: 42
tags: ["sql","analytics","algorithms"]
---

# Solving the "Impossible" in ClickHouse: Advent of Code 2025

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2025-12-31, 42 min read, How-to. Original: [https://clickhouse.com/blog/clickhouse-advent-of-code-2025](https://clickhouse.com/blog/clickhouse-advent-of-code-2025)

## Summary

All 12 Advent of Code 2025 puzzles are solved in pure ClickHouse SQL, each as a single query that parses the raw input and computes both parts with no UDFs, temporary tables or preprocessing. Imperative patterns are mapped onto ClickHouse features: window functions such as sum() OVER and lagInFrame turn simulations into running totals, arrayJoin with range expands compact ranges into rows, arrayExists with lambdas detects repeating patterns, and arrayFold carries accumulator state for greedy algorithms. Every day includes the full commented CTE-chained query, showing how far ClickHouse's array and higher-order functions can stretch beyond OLAP workloads.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [SQL](https://swe.quest/tags/sql.md) (Languages)
- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)
- [Algorithms](https://swe.quest/tags/algorithms.md) (Architecture & design)

## Prerequisites

- SQL CTEs ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- window functions
- ClickHouse array functions ([easy posts on Analytics & OLAP](https://swe.quest/tags/analytics.md?difficulty=easy))

## Keywords

ClickHouse, Advent of Code, arrayFold, arrayJoin, window functions

## Related posts

- [ClickHouse Newsletter March 2023: Contributing to ClickHouse](https://swe.quest/articles/clickhouse-newsletter-march-2023-contributing-to-clickhouse-86808ac436001235.md): ClickHouse · 2023-03-23 · Medium · 6 min read · SQL, Analytics & OLAP
  ClickHouse v23.2 ships 18 new features, 30 performance optimisations and 43 bug fixes, headlined by multi-stage PREWHERE, read support for Apache Iceberg v1 tables, and correlation matrix computation.
- [ClickHouse Release 26.4](https://swe.quest/articles/clickhouse-release-26-4-f4f5532396f893cd.md): ClickHouse · 2026-05-08 · Medium · 10 min read · Analytics & OLAP, SQL, Query engines, Performance engineering
  ClickHouse 26.4 ships 39 features, 45 performance optimizations and 238 bug fixes, led by SQL-compatibility additions: VALUES as a table expression with column aliases, PostgreSQL-style EXTRACT units, SET TIME ZONE, NATURAL JOIN and compound INTERVAL literals.
- [ClickHouse Release 26.7](https://swe.quest/articles/clickhouse-release-26-7-1ce7ef970afa5876.md): ClickHouse · 2026-08-06 · Medium · 30 min read · Query engines, Analytics & OLAP, Performance engineering, Vector search
  ClickHouse 26.7 ships 61 features, 112 performance optimizations and 329 bug fixes, led by a fused ordered-aggregation pipeline that pushes LIMIT into in-order GROUP BY.
- [ClickHouse Release 23.10](https://swe.quest/articles/clickhouse-release-23-10-2e0fc84d309ada86.md): ClickHouse · 2023-11-13 · Medium · 11 min read · Analytics & OLAP, SQL, Databases
  ClickHouse 23.10 ships 23 new features, 26 performance optimisations and 60 bug fixes.
- [ClickHouse Newsletter July 2023: Seeing Clearly](https://swe.quest/articles/clickhouse-newsletter-july-2023-seeing-clearly-a153c241f5923252.md): ClickHouse · 2023-07-24 · Medium · 10 min read · Analytics & OLAP, SQL, Databases
  ClickHouse v23.6 adds 10 features, 12 performance optimisations and 31 bug fixes.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
