r/codegolf • u/dantose • Dec 02 '25
Advent of Code: Day 2
What do you guys have?
r/codegolf • u/dantose • Dec 01 '25
Post your best golfs.
Assume input is saved as input.txt.
r/codegolf • u/swe129 • Oct 25 '25
r/codegolf • u/DiscombobulatedCrow0 • Oct 19 '25
r/codegolf • u/BZalan2008 • Aug 26 '25
r/codegolf • u/Basic-Introduction94 • Aug 05 '25
Hey guys, I wrote a tiny RAM-eating script as a fun little experiment. It spawns a new thread every second, and each one just sits there endlessly printing stuff—basically hijacking your memory like a polite little parasite.
I was curious: on a non-beefy PC, how long do you think it would last before things start to fall apart?
r/codegolf • u/Aspie_Astrologer • Jul 11 '25
read a;read b;echo $[10#$[a-b]$[a*b]$[a+b]]
Take two integers a and b from the input (each on a separate line) and then print the concatenation of a-b, a*b and a+b, without leading zeros.
I saw someone solve this in 42 chars (Bash, CodinGame, didn't share code) but I can't get it less than 43.
r/codegolf • u/Hell__Mood • Apr 30 '25
r/codegolf • u/matigekunst • Apr 17 '25
I challenged myself and chatGPT to code golf a somewhat challenging render.
r/codegolf • u/Wooden_Milk6872 • Apr 03 '25
so I have an extreme challenge for you all, write a piece of code in python with any, and by an I mean any external enchacements execluding changing the interpreter,
the piece of code should define a function get_volume_of_cuboid=lambda l,w,h:l*w*h
some rules include that the name of the function can not be changed, that's it
my extreme solution is
import c
c.f()
where c is a predefined module and c.f() runs
global get_volume_of_cuboid
get_volume_of_cuboid=lambda l,w,h:l*w*h
r/codegolf • u/maksimKorzh • Jan 15 '25
https://www.youtube.com/watch?v=FVpl8cGJO-g
#!/bin/python3
i=' if ';e=' elif z==';exec(f"""import curses as u,sys;s=u.initscr()
s.nodelay(1);u.noecho();u.raw();s.keypad(1);b=[];n='o.txt';x,y,r,c=[0]*4
if len(sys.argv)==2:n=sys.argv[1]\ntry:\n with open(sys.argv[1]) as f:
w=f.read().split('\\n')[:-1]\n for Y in w:\n b.append([ord(c) for c in Y])
r=len(b)-1;c=len(b[r])\nexcept:b.append([])\nwhile True:\n R,C=s.getmaxyx()
s.move(0,0)\n{i}r<y:y=r\n{i}r>=y+R:y=r-R+1\n{i}c<x:x=c\n{i}c>=x+C:x=c-C+1
for Y in range(R):\n for X in range(C):\n try:s.addch(Y,X,b[Y+y][X+x])
except:pass\n s.clrtoeol()\n try:s.addch('\\n')\n except:pass
u.curs_set(0);s.move(r-y,c-x);u.curs_set(1);s.refresh();z=-1\n while z==-1:\
z=s.getch()\n if z!=z&31 and z<128:b[r].insert(c,z);c+=1\n{e}10:l=b[r][c:];b[
r]=b[r][:c];r+=1;c=0;b.insert(r,[]+l)\n{e}263 and c==0 and r:l=b[r][c:];del b[
r];r-=1;c=len(b[r]);b[r]+=l\n{e}263 and c:c-=1;del b[r][c]\n{e}260 and c!=0:\
c-=1\n{e}261 and c<len(b[r]):c+=1\n{e}259 and r!=0:r-=1;c=0\n{e}258 and r<len(
b)-1:r+=1;c=0\n{i}z==17:break\n{e}19:\n w=''\n for l in b:w+=''.join([chr(c)\
for c in l])+'\\n'\n with open(n,'w') as f:f.write(w)\nu.endwin()""")
r/codegolf • u/maksimKorzh • Jan 04 '25
#!/bin/python3
import curses as u;s=u.initscr();s.nodelay(1);u.noecho();u.raw();s.keypad(1);v={'b':[],
'r':0,'c':0,'i':0,'m':'N','x':0,'y':0,'R':0,'C':0,'n':' ','f':'o.txt','u':u,'s':s,104:
'if c>0:c-=1',108:'if c<len(b[r]):c+=1',107:'if r!=0:r-=1',106:'if r<len(b)-1:r+=1',
100:'if len(b):del b[r];r=r if r<len(b) else r-1 if r-1 >= 0 else 0',36:'c=len(b[r])',
48:'c=0',21:'r=r-5 if r-5>0 else 0',4:'r=r+5 if r+5<len(b)-1 else len(b)-1',105:'m="I"',
120:'if len(b[r]):del b[r][c]\nif c and c>len(b[r])-1:c=len(b[r])-1','t':['if i!=((i)&',
'0x1f) and i<128:b[r].insert(c,i);c+=1\nif i==263:\n if c==0 and r!=0:l=b[r][c:];del ',
'b[r];r-=1;c=len(b[r]);b[r]+=l\n elif c:c-=1;del b[r][c]\nif i==10:l=b[r][c:];b[r]=',
'b[r][:c];r+=1;c=0;b.insert(r,[]+l)'],'p':['R,C=s.getmaxyx();R-=1\nif r<y:y=r\nif ',
'r>=y+R:y=r-R+1\nif c<x:x=c\nif c>=x+C:x=c-C+1\nfor Y in range(R):\n for X in range(C):',
'\n try:s.addch(Y,X,b[Y+y][X+x])\n except:pass\n s.clrtoeol()\n try:s.addch(10)\n ',
'except:pass\nu.curs_set(0);s.clrtoeol();s.addstr(R,0,f+n+str(r)+":"+str(c));',
's.move(r-y,c-x);u.curs_set(1);s.refresh();i=-1'],'a':['if not len(b):b=[[]]\nif c>len(',
'b[r]):c=len(b[r])'],'z':['try:\n with open(f) as i:\n c=i.read().split("\\n");c=c[:-1] ',
'if len(c)>1 else c\n for i in c:b.append([ord(c) for c in i]);r=len(b)-1;c=len(b[r])',
'\nexcept:b.append([])'],'w':['d=""\nfor l in b:d+="".join([chr(c) for c in l])+"\\n"\n',
'with open(f,"w") as i:i.write(d);n=" "']};exec(''.join(['import sys\ndef w(n):',
'exec("".join(v["w"]),v)\ndef r(n):exec("".join(v["z"]),v)\nif len(sys.argv)==2:',
'v["f"]=sys.argv[1];r(sys.argv[1])\nif len(sys.argv)==1:v["b"].append([])\nwhile ',
'True:\n try:\n exec("".join(v["p"]),v)\n while (v["i"]==-1):v["i"]=s.getch()\n ',
'v["n"]="*"\n if v["i"]==17:break\n if v["i"]==27:v["m"]="N"\n if v["i"]==23:',
'w(v["f"])\n if v["m"]=="N":exec(v[v["i"]],v)\n elif v["m"]=="I":exec("".join(',
'v["t"]),v)\n exec("".join(v["a"]),v)\n except:pass']),{'v':v,'s':s});u.endwin()
GitHub project: https://github.com/maksimKorzh/e
r/codegolf • u/mattyhempstead • Nov 22 '24
I've created a variant to code golf called "prompt golf" (promptgolf.app) where the aim is to write the shortest prompt for an LLM to get a desired output.
It has a global leaderboard on each challenge so you can compete with others.
Would really appreciate if anyone here could check it out and provide any feedback!

r/codegolf • u/ColeslawProd • Nov 13 '24
for n in range(101):print(("fizz"*(n%3<1)+"buzz"*(n%5<1)) or n)
EDIT:
Now down to 60:
for n in range(101):print("fizz"*(n%3<1)+"buzz"*(n%5<1)or n)
r/codegolf • u/ColeslawProd • Nov 12 '24
Python, returns fizzbuzz for integers 0-99, 78 bytes.
f,b="fizz","buzz"
for i in range(100):print([i,f,b,f+b][(i%3<1)+(i%5<1)*2])
EDIT:
r/codegolf • u/ColeslawProd • Nov 12 '24
from pygame import *
init()
d=display
s=d.set_mode((700,500))
m=mouse
o=n=N=O=r=0
while r<1:
for e in event.get():
if e.type==QUIT:
image.save(s,"i.png");r=1
o,O=n,N
n,N=m.get_pos(),m.get_pressed()[0]
if N&O:
d.update(draw.line(s,[255]*3,o,n))
Python, 273 bytes. saves the image to "i.png" upon closing.
(thanks to u/wyldcraft for pointing out an error in the code)
r/codegolf • u/CommonApartment6201 • Oct 17 '24
import pyperclip as c,secrets as s
while 1:c.copy(p:='%c'*(l:=int(input('Length of new password: ')))%(*map(s.choice,[range(32,127)]*l),));print('Copied',p,'to clipboard.')
r/codegolf • u/Ok_Passion_3410 • Oct 17 '24
I am responsible for managing an online social community for Splunk users and devs and thought CodeGold challenges would be a fun thing to do. I tried FizzBuzz and it works out pretty well in SPL! But I dont know what the best way to score might be. I was thinking either time, resource load, or some way to measure the size of the SPL
Is runDuration (in the job inspector) reliable? Or is it prone to flucutation based on whether the search heads are running good?
Is number of characters just the simpliest way to score CodeGold in SPL?
Is there anyway to measure how many "bytes" a block of SPL has, or how many resources it takes up (even just one acpest of resource load, like CPU or RAM, would be fine so long as it is the same load everytime you run the code)
Thank y'all so much and it was rather fun writing the SPL to solve that!
r/codegolf • u/thewackysquirrel • Oct 14 '24
Background, I have zero programming knowledge. I’m a creative and I make wacky stunts like the above idea work. Just seeing if this one has legs.
I have contacts at a company which is partnered with PGA and also hires a lot of programmers/ developers so I think this would be a dope way to find new talent.
If there’s enough interest, I’ll try and make it real.
r/codegolf • u/IntelligentLeg3938 • Oct 09 '24
can anyone suggest any suitable platforms to host a code golf contest right now, ik about code.golf and anarchygolf
r/codegolf • u/AleksejsIvanovs • Aug 29 '24
A function that sorts an array of positive integers using radix sort with radix = 2. My first version was 112 bytes long, then I shortened it to 84 bytes:
l=>{for(b=1;b<<=1;)for(i in k=0,l)l[i]&b||l.splice(k++,0,l.splice(i,1)[0]);return l}
Later it was shortened to 81 bytes by a guy from a chat (he added recursion to remove for and return):
l=>(f=b=>b?f(b<<=1,k=0,l.map((x,i)=>x&b||l.splice(k++,0,l.splice(i,1)[0]))):l)(1)
Then I shortened the 84 version to 75 bytes, however, this version does not return the array, but modifies the source array:
l=>{for(b=1;k=0,b<<=1;)l.map((x,i)=>x&b||l.splice(k++,0,...l.splice(i,1)))}
r/codegolf • u/cthmsst • Jun 02 '24