# A floodfill that needs no stack, just 16 spare colors

Original title: A Stackless Floodfill Automaton

> Hacker News story 50235661 · language: en · submitted 2026-10-25
> Web version: https://zeli.app/story/50235661
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 54 · by [andsoitis](<https://news.ycombinator.com/user?id=andsoitis>) · 💬 24
[original](<https://t3x.org/files/floodfill.pdf>) · [HN discussion](<https://news.ycombinator.com/item?id=50235661>)

## Summary

Recursive floodfill normally keeps the coordinates of every origin pixel on a stack. Nils M Holm shows that with 16 unused color values you can encode a finite state automaton directly in the image instead: each filled pixel stores the direction it came from and the direction to try next, so backtracking means following arrows rather than popping a stack. He built it for a text-based minesweeper on a BASIC system with only 7K of program memory and 30 levels of subroutine nesting, and includes a working implementation.

## Key quote

> If you can spare 16 colors, though, no stack is needed.

## HN discussion (24 comments)

### [hyperhello](<https://news.ycombinator.com/item?id=50260832>)

> The algorithm uses about half a byte per pixel and saves the path it follows. That kind of implies that the stack is still there and present, it’s just bounded to the number of pixels, and could actually be modified to just use a bounded area of the heap. But conceptually it’s easier to follow the way the paper was written. Neat.

### [zimpenfish](<https://news.ycombinator.com/item?id=50260482>)

> Huh, that's useful because I had to write a floodfill a couple of days ago and it was a pain in the arse.
>
> I'll be converting my code to the stackless version toot sweet.

### [amelius](<https://news.ycombinator.com/item?id=50264382>)

> Curious if Claude could come up with this when asked to implement a flood fill without stack. Alas, out of tokens.

---

## Cite

- Page: https://zeli.app/story/50235661
- Date: 2026-10-25
- Source: t3x.org (https://t3x.org/files/floodfill.pdf)
- Hacker News: https://news.ycombinator.com/item?id=50235661

## Other languages

- zh: https://zeli.app/zh/story/50235661 · markdown: https://zeli.app/zh/story/50235661.md
- ja: https://zeli.app/ja/story/50235661 · markdown: https://zeli.app/ja/story/50235661.md
- ko: https://zeli.app/ko/story/50235661 · markdown: https://zeli.app/ko/story/50235661.md
- de: https://zeli.app/de/story/50235661 · markdown: https://zeli.app/de/story/50235661.md
- es: https://zeli.app/es/story/50235661 · markdown: https://zeli.app/es/story/50235661.md
- ru: https://zeli.app/ru/story/50235661 · markdown: https://zeli.app/ru/story/50235661.md
