ChatGPT Nails Code Golf with a Beautifully Elegant One-Liner for Ordinals

IgorBrigadir · x · 2026-08-12

While testing ChatGPT, a developer discovered that it generated a piece of code golf (minimalist code) art for appending English ordinal suffixes (e.g., 1st, 2nd, 3rd) to numbers:

O=lambda n:f"{n}{'tsnrhtdd'[(n//10%10!=1)(n%10<4)n%10::4]}"

The author was blown away by the absolute beauty of this solution. The replies sparked a discussion on whether AI could generate a system to create compound words where a sequence of letter removals yields a desired message.

Related event: ChatGPT Impresses Developers with Elegant Code Golf Solutions(2 posts)→

Original post →

More from coding & agent

coding & agent channel →