Countdown: Rebuilding a 6x6 Tap Puzzle in SwiftUI

Wenjing Fang2026-12-01NotesSwiftSwiftUIiOSProgramming

TIP

Introducing Countdown, a zero-dependency SwiftUI 6x6 tap puzzle for iOS with Z/4 puzzle generation, par scoring, and a code-generated app icon.

Countdownopen in new window is a 6x6 tap puzzle for iOS built in Swift 6 and SwiftUI with no external dependencies. Each cell holds a value from 0 to 3. Tapping a cell lowers it and its four orthogonal neighbors by one, wrapping 0 back to 3. Clear every cell to zero to win.

The app started as a port of an older Kivy game (random-apps/myapps/countdown), with a rebuilt puzzle engine.

Countdown Play screen in light mode showing a Hard 6x6 board, elapsed time, move count, and a highlighted hint cell

Unique Solutions Over Z/4

Tap order does not matter, and four taps on the same cell cancel out. Any board state therefore maps to a 36-element vector of tap counts in Z/4. Because the 36x36 cross adjacency matrix is invertible over Z/4, every board has a single unique solution (Plan).

The original Kivy version scrambled boards with N random clicks. Clicks on the same cell could wrap past four and cancel, so 10 clicks produced puzzles needing 6 to 10 moves and 20 clicks produced puzzles needing 12 to 20. A "Hard" board could end up shorter than an "Easy" one.

Countdown generates puzzles directly from a solution vector instead. Plan.random(moves:) draws without replacement from a bag containing each cell three times, capping every cell at three taps so moves never cancel:

  • Fixed difficulty grades: Easy needs 10 moves, Hard needs 20, and Expert needs 30, every time.
  • O(1) solved check and par scoring: Keeping the remaining Plan alongside Board tracks movesLeft on every tap without scanning all 36 cells. Finishing at par with zero hints records a perfect run.
  • Hints and undo: Hint highlights plan.next with a border ring, and Undo reverses both the board cross and the owed tap count.

Interface, Timing, and Records

Cell hue encodes value so the board reads by color before digits: blank for 0, emerald for 1, yellow for 2, and vermilion for 3. Palette.swift defines paired light and dark hex values side by side, setting cleared cells against the board tray (#16191B / #2F3639) so empty tiles stay visible in dark mode.

The Clock tracks wall time starting on the first tap and pauses when the app leaves the foreground. Resetting the board returns the grid to its starting layout while leaving the clock and move counter running.

Countdown Records screen in dark mode showing the appearance toggle and top runs scored against par for Easy, Hard, and Expert

The Records tab keeps the player name, a System/Light/Dark appearance override, and one sorted top-3 Leaderboard per grade in UserDefaults, replacing the original game's parallel arrays and negative-index lookups. The app icon uses the same hex palette: Tools/MakeIcon.swift generates the light, dark, and tinted assets from code.

Build and Run

Source code is on GitHub at github.com/cellsummer/ios-countdownopen in new window. Building requires Xcode with the iOS 18 SDK or newer:

xcodebuild -scheme Countdown -destination 'platform=iOS Simulator,name=iPhone 17' build

Personal signing stays out of the repository. To run on a physical device, add DEVELOPMENT_TEAM = <TEAM_ID> to Config/Local.xcconfig.

Last Updated 12/1/2026, 4:15:51 PM