Puzzle Spree

Puzzle Spree

Spiral Function

Map integers to coordinates in a spiral pattern

Kuai Yu's avatar
Kuai Yu
Jan 24, 2025
∙ Paid

Problem Statement

A spiral function maps a nonnegative integer n onto integer coordinates (x, y) in a spiral pattern on a Cartesian plane. The spiral starts at the origin (0, 0) with n = 0 and expands outward in a counter-clockwise direction.

Write a function spiralCoordinates(n) that takes an integer n and returns its coordinates (x, y) in the spiral.

Exa…

Keep reading with a 7-day free trial

Subscribe to Puzzle Spree to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Puzzle Spree · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture