r/codegolf • • Jun 30 '15

Pastebin clone in a tweet

Thumbnail
twitter.com
6 Upvotes

r/codegolf • • Oct 09 '26

Code Golf leaderboard for any CG clash, see how you rank against other golfers

Thumbnail astroblurbs.work
5 Upvotes

r/codegolf • • Sep 28 '26

go/codegolf benchmark: frontier models vs. Google's 2015 code golfers

Thumbnail bjin.github.io
5 Upvotes

r/codegolf • • Dec 04 '25

Advent of Code: Day 3

5 Upvotes

Post your golfs. Use input.txt

Here are my solutions in Python.

Part 1 (80 bytes)

print(sum(int((a:=max(l[:-2]))+max(l[l.find(a)+1:]))for l in open('input.txt')))

Part 2 (151 bytes)

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')))

r/codegolf • • Jul 11 '25

Beat this Bash script (43 char)

5 Upvotes

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 • • Nov 12 '24

Python Fizzbuzz 78 bytes

5 Upvotes

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:

Now down to 60


r/codegolf • • Oct 14 '24

Theoretically, if PGA set up a competition where you had to write the shortest code to get a robot arm to swing a golf club to try and hit a hole in one, how many of you would be interested?

5 Upvotes

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.

7 votes, Oct 21 '24
5 Yes ⛳️
2 Nah, I’d probably skip this.

r/codegolf • • Jan 02 '24

Top 10 Dwitter Programs of 2023!

5 Upvotes

r/codegolf • • Dec 05 '23

What features do you wish golfing languages have?

5 Upvotes

I decided to take on the project of creating a golfing language (stack based is really easy to program). What features are golfing languages lacking that you wish they had?


r/codegolf • • Oct 24 '23

Someone manage to squeeze out one more byte from this Fizzbuzz?

5 Upvotes

The shortest fizzbuzz for JS (that I know of) is this one:

for(i=0;i<100;)console.log((++i%3?'':'fizz')+(i%5?'':'buzz')||i)

I tried a different approach. Haven't seen it anywhere else, but it's probably done before. I managed to get it down to one character away from the shortest one. Have I overlooked anything? Can you squeeze the last bit out of it? :)

for(i=0;i<100;)console.log("fizzbuzz".slice(++i%3&&4,i%5?4:8)||i)

r/codegolf • • Jan 16 '23

91 byte password generator

5 Upvotes
from random import*
while 1:print(''.join(map(chr,choices(range(32,127),k=int(input())))))

r/codegolf • • Dec 01 '21

Any improvements on my solve? (VanillaJS)

Thumbnail
self.programminghorror
5 Upvotes

r/codegolf • • Aug 13 '21

JS13KGames competition has started

Thumbnail
js13kgames.com
5 Upvotes

r/codegolf • • Mar 21 '21

Blake 32, a 32 byte intro by Marquee Design , written in X86 assembler

5 Upvotes

r/codegolf • • Feb 07 '21

(J/JLang) How to print an array to stdout as separate lines?

5 Upvotes

I'm trying to submit some code golf written in J but I can't figure out a 'golfy' way to print line-by-line in Jlang/Jsoftware.

Printing all primes below 100 is easy to do in J: p:i.25

However, this doesn't print to stdout so I have been forced to try stdout 0":p:i.25

Then now it's still not a solution because this output is in-line instead of having the output primes on separate lines. What's the 'golfiest' way to print an array vertically in J?


r/codegolf • • Jan 09 '21

Superform - A 256 byte demo for the ZX Spectrum

Thumbnail
pouet.net
5 Upvotes

r/codegolf • • Jul 03 '20

First try at code golfing (python 3)

5 Upvotes

Today I tried the first time to compact a piece of code as much as possible. I am sure that you guys can do much better, i would love to hear what you would compact.

The code searches Pi for the input string, and stops once it found it. It uses the "api.pi.delivery" Api. This means its pretty fast.

I got it down to 9 lines of code or under 300 characters.

import requests,json;p,s,x,z = "pi: ",0,input("Number to find?"),1000
while True:
 p+=requests.get("https://api.pi.delivery/v1/pi?start="+str(s)+"&numberOfDigits=1000").json()["content"]
 s+=z
 i=p.find(x)
 print(s,"letters searched")
 if i!=-1:
  print("found it! It was the",i,"letter.")
  break

It can ofc be shorted if you change the input and output.

Edit: I got it a good bit shorter with the help of the comments.

import requests;p,s,x,i = "",0,input("Number?"),-1
while i<0:p+=requests.get("https://api.pi.delivery/v1/pi?start=%s&numberOfDigits=999"%s).json()["content"];s+=999;i=p.find(x);print(s,"letters searched")
print("found it at position",i)

239 237 bytes.

Also its a 3-liner now


r/codegolf • • Mar 21 '20

Covid19 - Tiny MSDOS Intro in 256 bytes

Thumbnail
youtube.com
5 Upvotes

r/codegolf • • Oct 12 '17

Collatz Sequence Calculator in C (134 Bytes) - My first attempt at Golf

Thumbnail
pastebin.com
5 Upvotes

r/codegolf • • Sep 28 '17

New Code Golf Site with Perl 6/JS/Ruby/Python etc.

Thumbnail
code-golf.io
5 Upvotes

r/codegolf • • Aug 04 '17

[python3] Tic-tac-toe (380 chars minus ws)

5 Upvotes

Gist

L,Y,W,E,G='-',lambda i:B[A[i][0]][A[i][1]],[0,0],[2,2],0
B=[L]*3,[L]*3,[L]*3
while 1:
	G=1-G;t='XO'[G]
	for[a,b,c]in B:print(a+b+c)
	while 1:
		q=ord(input(t)[0])-49
		if q in range(9):x,c=B[q//3],q%3
		if x[c]==L:x[c]=t;break
	A=[(x+V*i,y+v*i)for a,b in[W,(0,1),(0,2)]for x,y,V,v in[(a,b,1,0),(b,a,0,1)]for i in[0,1,2]]+[W,E,(1,1),(2,0),E,(0,2)]
	exec("if(Y(0)==Y(1)==Y(2)!=L):print('W'+Y(0));exit()\nA=A[3:]\n"*8)

Let me know where I can improve, or if you have a better approach! I didn't want to explain line-by-line, but if something stands out as difficult to understand, let me know.

This is a 3x3 tic-tac-toe game that displays a 9-character grid (three characters, line break, etc.) to represent the board, then prompting for input by printing the current player's symbol (X or O) and waiting for input.

My number parsing makes some shortcuts, so non-numbers and numbers larger than one digit lead to unexpected behavior — it works for digits 1-9. What it does detect is trying to overwrite a space: it will prompt for input again. Of course, win detection is an important part of the game, looking for horizontal, vertical, and diagonal wins.

The board represents empty spaces with a hyphen (-) and X's and O's with X's and O's (obviously)


r/codegolf • • Jul 14 '17

JS golfed 3D twisty sphere in 136b ( https://codegolf.tk/a/116 )

5 Upvotes
for(A=960,B=540,x.fillRect(0,0,i=2e3,i);i--;)x.clearRect(A+1/(Z=2.5+C(p=i*C(t/2)/40)*S(q=i/628))*(X=S(p)*S(q))*A,B+C(q)/Z*A,s=69/Z/Z,s)

r/codegolf • • Jun 18 '16

Calculate ℯ to at least five decimal digits

5 Upvotes

ℯ is the base of the natural logarithm and its approximate value is 2.71828. ℯ can be calculated by summing the inverses of incremented factorials. A simple series that can be used to calculate ℯ can be seen [here on Wikipedia](https://en.wikipedia.org/wiki/E_(mathematical_constant).

Rules:

  • You are not to use a predefined constant for ℯ provided by your programming language's standard library or your program in calculation.

  • You are encouraged to use /u/CompileBot to demonstrate your code if at all possible.


r/codegolf • • Mar 05 '26

Cutting edge transpilation/compilation frameworks? (Non-LLM code generation)

4 Upvotes

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#?