r/codegolf • u/matigekunst • 13d ago
Kuramoto-Sivashinsky 2D [1019 chars]
Enable HLS to view with audio, or disable this notification
r/codegolf • u/matigekunst • 13d ago
Enable HLS to view with audio, or disable this notification
r/codegolf • u/Aspie_Astrologer • Oct 09 '26
r/codegolf • u/Hell__Mood • Oct 03 '26
r/codegolf • u/bjin • Sep 28 '26
r/codegolf • u/jakeyt_9587 • Sep 23 '26
I made the world's smallest 32x32 grayscale PNG - only 104 bytes (down from 108 bytes WR).
Technique: PLTE trim + static Huffman table. Pure PNG spec, no AI.
When tiled vertically, it creates a peak / sunset glitch wallpaper effect.
File loads in 0s even on slow data.
r/codegolf • u/onformulation • Sep 10 '26
r/codegolf • u/Faputo4ka • Aug 30 '26
For the past few days, I’ve been obsessed with a single question: How small can a valid PNG file possibly get while still being natively readable by a PC (specifically, opening properly in the standard Windows photo viewer/gallery)?
I started by trying to make a lightweight 512x512 file, eventually managing to shrink it down to 111 bytes. After that, I started playing around with compression levels and various patterns, even managing to generate some basic procedural textures in PNG format that weighed roughly the same.
Then I decided to go deeper and chase the absolute minimum file size. At first, I hit a wall at 67 bytes—an article I read online claimed that was the lowest possible size for a functional PNG. But I kept experimenting and eventually pushed past it down to 55 bytes, and finally all the way to 42 bytes.
My current record is a fully working 42-byte PNG. It opens without issues on Windows and can be sent across messaging apps where it renders properly as an image.
However, I've hit a hard brick wall here. Every single attempt to strip away even one more byte results in an invalid file or completely breaks the structure.
My question is: Does anyone have any radical ideas, unconventional compression tricks, or deep spec-hacking methods to squeeze it down even further? I'm open to any crazy suggestions!
r/codegolf • u/StrategicHarmony • Jun 16 '26

As an exercise in focus and economy I wanted to make a set of games with short but (hopefully) readable source code.
It was a fun challenge and taught me a lot. I hope the results will be of interest or amusement to others.
There are five games in total. There's also a manifesto about doing this kind of project for those who like that sort of thing.
Part of the challenge is actually releasing things and accepting feedback so I'd be grateful for any opinions you have to offer, whether critical or complimentary.
If you've written a deliberately short game too then please link to it, I'm interested to see what can be done.
r/codegolf • u/IntroductionTop2025 • May 16 '26
r/codegolf • u/Edev90 • Apr 21 '26
As the title says. Above GIF is footage of it running in Chrome. No libraries like Three.js or trig functions were used. Due to the small footprint the "Camera" features only 1 Isometric perspective.
Could get golfed down slightly more probably... but not much. I'll release the un-golfed source once I clean it up a bit and add comments. Enjoy!
Gist of the golfed code can be found here: https://gist.github.com/edev90/00dd40e8424740358bf9b7d5d482d30a
r/codegolf • u/angry_cactus • Mar 05 '26
Hope this isn't the wrong place, but do you know of any radical transpilation/compilation frameworks, at least as powerful as WebAssembly, such as Typescript to C, or Python to C#?
r/codegolf • u/IntroductionTop2025 • Feb 16 '26
r/codegolf • u/eymenwinner • Jan 16 '26
ShaderGolf is a programming/drawing challenge where there is a canvas scanned top to bottom, uses 16 colors, there are 2 variables called c (color) and t (time), and there is a program called 'shader' that executes when each pixel is scanned, and the program is just literally a single expression. the t variables increments after each pixel is scanned.c is 0 per pixel by default. Here are some example patterns:
Line: 15 - !(t % 257) * 15
Colored stars: 15 - !(t % 46) * (15 - t % 16)
Colored circles: t * (t >> 7) >> 3
Try at: http://eymenwinneryt.42web.io/shg.htm

r/codegolf • u/IntroductionTop2025 • Jan 07 '26
r/codegolf • u/eymenwinner • Jan 05 '26
This is very compact interpreter written in ES6, no obfuscation or any tools used. Code:
r=_=>{for(p=a.value,d=new Uint8Array(512),e=i=0,h=[];i<p.length;i++){k=d[e];({'>':_=>e++,'<':_=>e--,'+':_=>d[e]++,'-':_=>d[e]--,'[':_=>{if(!k)for(g=1;g;)g+=(p[++i]=='[')-(p[i]==']');else h.push(i)},']':_=>k&&(i=h.pop()-1),'.':_=>b.innerHTML+=String.fromCharCode(k)})[p[i]]?.()}}
EDIT 1/16/2025: Now 278 bytes
Demo at: http://eymenwinneryt.42web.io/bf.htm
r/codegolf • u/TheRealHappyPiggy • Dec 31 '25
So as the title says, I implemented Tic-Tac-Toe or Noughts and Crosses in Python as short as I could make it over the span of a few days. I'm at a point where I can't find any further improvements but I'd be happy to hear if anyone else can find something I was unable to!
Python Code (161 bytes):
b=p='_|_|_\n'*3
while'_'in b*all(3*p!=b[v>>4::v&15][:3]for v in[2,6,8,38,68,70,98,194]):
i=2*int(input(b))
if b[i]>'X':p='XO'[p>'O'];b=b[:i]+p+b[i+1:]
print(b)Edit: Improvements made with feedback (151 bytes)
b=p='_|_|_\n'*3
while'_'in b*all(3*p!=b[v&15::v>>4][:3]for v in b' `\x80bDd&,'):
if b[i:=2*int(input(b))]>'X':p='XO'[p>'O'];b=b[:i]+p+b[i+1:]
print(b)I flipped the upper and lower bits of each value in [2,6,8,38,68,70,98,194] and converted into the b-string: b' \\x80bDd&,'` , as well as utilizing the walrus operator (:=) to save a line break and a space (thanks to u/3RR0R400 for the ideas)
Example run:
_|_|_
_|_|_
_|_|_
4
_|_|_
_|O|_
_|_|_
5
_|_|_
_|O|X
_|_|_
2
_|_|O
_|O|X
_|_|_
6
_|_|O
_|O|X
X|_|_
0
O|_|O
_|O|X
X|_|_
1
O|X|O
_|O|X
X|_|_
8
O|X|O
_|O|X
X|_|OBelow is a simple explanation of what it does for anyone interested:
b: Board
p: Current Player Marker
b=p='_|_|_\n'*3 Initialize the board such that printing results in a 3x3 grid, as well as having each "cell" at an even index pattern (2* Cell index). Furthermore, I save bytes by chained assignment of p, since p is updated before it's used.
while'_'in b*all(3*p!=b[v>>4::v&15][:3]for v in[2,6,8,38,68,70,98,194]): This line has had the most effort put into it. It consists of two parts, draw detection ('_'in b), and a general win detection, combined in a way to make use of string repetition to avoid an and.
all(3*p!=b[v>>4::v&15][:3]for v in[2,6,8,38,68,70,98,194]) After each move the only winning pattern has to include the last players marker (except for the first iteration where 3*p=3*b can never equal a slice of b, thus entering the loop). Then test the string 'XXX' or 'OOO' against a slice of three characters from the board where each win pattern is stored in a single number, each having a starting position and a stride length stored in the upper and lower 4 bits of v respectively. (I did find this that reduces the codes character length, but increased the number of bytes: b[ord(v)&15::ord(v)>>7][:3]for v in'Ā̀Ѐ̂Ȅ̄ĆČ' due to the use of 'Ā̀Ѐ̂Ȅ̄ĆČ' where each character is more than one byte)
i=2*int(input(b)) I make use of the fact that input(prompt) prints the prompt (in this case b) to display the board before a move, then read an input and store in i, ready for indexing.
if b[i]>'X':p='XO'[p>'O'];b=b[:i]+p+b[i+1:] Here I update player and board if the input is valid, making use of b[i]>'X' being the same as b[i]=='_' for all valid b[i] in this context, to save one byte. Player switching uses a similar fact as well as indexing into 'XO' using a bool (This also sets the first player to O when p=b*3*)*. And finally updating the board is a simple slicing of b and adding of p since p is a string.
print(b) This line just prints the board a last time after a win or a draw (Here I did find using exit(b) or quit(b) to save one byte, but I didn't feel like it counted).
Since I know what constitutes "Tic-Tac-Toe" is a little arbitrary, I tried to define and follow a few self-imposed rules:
Display the board before each move in a 3x3 grid
Only allow placement of marker on empty cell, otherwise don't switch player
End the game and display the final board on a win or draw
Other rules that some might consider, which I didn't for this project
Also display the current player before each move
Pretty intuitive that the player switches after each turn (only caveat is when someone makes an invalid move)
Print out the result on a win or draw (Like "X won" or "Draw")
I didn't like the trade-off between an informative result representation and number of bytes (for example "X" vs "Player X won"), and I'd say it's pretty intuitive to figure out who won when the game ends.
r/codegolf • u/Slackluster • Dec 26 '25
r/codegolf • u/dantose • Dec 08 '25
As the puzzles get harder, less solutions are getting posted, so I'm just going to toss the rest of it in one thread.
Please label replies with day, part, and language.
r/codegolf • u/dantose • Dec 05 '25
Getting it out there, I'm a day behind so no golf from me on this one
r/codegolf • u/DimMagician • Dec 04 '25
Post your golfs.
Here are mine (Python):
b=[[0]+[c>'.'for c in l]for l in open('input.txt')]
w=len(b[0])
t=[[0]*w]
print(sum(v[i+1]&(sum((t+b+t)[j+x//3][i+x%3]for x in range(9))<5)for j,v in enumerate(b)for i in range(w-2)))b=[[0]+[c>'.'for c in l]for l in open('input.txt')]
s=w=len(b[0])
t=[[0]*w]
o=sum(sum(b,[]))
while s!=b:s=b;b=[[0,*((sum((t+b+t)[j+x//3][i+x%3]for x in range(9))>4)*v[i+1]for i in range(w-2)),0]for j,v in enumerate(b)]
print(o-sum(sum(b,[])))r/codegolf • u/DimMagician • Dec 04 '25
Post your golfs. Use input.txt
Here are my solutions in Python.
print(sum(int((a:=max(l[:-2]))+max(l[l.find(a)+1:]))for l in open('input.txt')))
print(sum([b:=l[-13:-1],int(max(b:=max(b,str(l[-14-i])+max(b[:w]+b[w+1:]for w in range(12)))for i in range(len(l)-13)))][1]for l in open('input.txt')))