/r/codegolf

Photograph via snooOG

Challenges to test your code shortening skills. Not necessarily practical, but fun!

Challenges to test your code shortening skills. Not necessarily practical, but fun!

 

Other programming subreddits:

/r/codegolf

2,639 Subscribers

0

How to Host Code golf

I want to host a code golf contest online but make it invite only for around 500 people

Can anyone tell me a good way to do it.

0 Comments
2024/12/12
07:27 UTC

9

Prompt Golf - code golf but where you write the shortest AI prompt

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!

https://preview.redd.it/1d17a6wtec2e1.png?width=1256&format=png&auto=webp&s=6036d7b53247c902b5afbec06fbcb12d4f516261

6 Comments
2024/11/22
00:00 UTC

7

Python fizzbuzz in 63 bytes

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)
0 Comments
2024/11/13
03:59 UTC

5

Python Fizzbuzz 78 bytes

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

0 Comments
2024/11/12
20:26 UTC

1

Drawing program to fit in a tweet (273 bytes)

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)

2 Comments
2024/11/12
19:57 UTC

3

Password generator 173 Bytes in python (2 modules)

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

1 Comment
2024/10/17
23:02 UTC

2

Getting my online community into Splunk through CodeGolf. Splunkers here, whats the best way to score SPL for CodeGolf

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!

0 Comments
2024/10/17
17:16 UTC

4

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?

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.

View Poll

1 Comment
2024/10/14
16:28 UTC

5

Hosting Code Golf Contest

can anyone suggest any suitable platforms to host a code golf contest right now, ik about code.golf and anarchygolf

6 Comments
2024/10/09
15:02 UTC

5

Radix sort in JS, 75 bytes.

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

1 Comment
2024/08/29
19:14 UTC

2

Challenge with fully functional game with 30 Python lines of code. Line by line source code at the top of the video

0 Comments
2024/02/25
17:52 UTC

3

Countdown to Lovebyte 2024 Tiny Code Demoparty ( https://lovebyte.party ) - 3 Days left (Atari Lynx)

0 Comments
2024/02/06
12:31 UTC

1

Countdown to Lovebyte 2024 Sizecoding Demoparty ( https://lovebyte.party ) - 4 Days left

0 Comments
2024/02/05
15:55 UTC

3

Countdown to Lovebyte demoparty ( https://lovebyte.party) - 5 Days left

0 Comments
2024/02/04
16:44 UTC

8

Any program in one line of python

Hello team. I think I can prove that any program at any level of complexity can be written in one line of python code. For example, here is advent of code day 7 problem 1:

with open("problem.txt", "r") as tf:(lambda fi, pd: (lambda m, sf2, lf, f: print(sum([int(x.split()[1]) * (i + 1) for i, x in enumerate(sorted(tf.read().split("\n"), key=lambda ct: sf2([int(x) if x.isnumeric() else m[x] for x in ct.split()[0]], f(lf(ct.split()[0])))))])))({"A": 14, "K": 13, "Q": 12, "J": 11, "T": 10}, (lambda h1, hp1: int(fi(hp1) + fi(h1))), (lambda t: [i for i in range(1, len(t) + 1) if (sorted(t) + ["z"])[i] != (sorted(t) + ["z"])[i - 1]]), (lambda tu: pd(sorted([x if i == 0 else x - tu[i - 1] for i, x in enumerate(tu)], reverse=True)))))((lambda ns: "".join([f"{n:02d}" for n in ns])),(lambda n: n + ([0] * (5 - len(n)))))

I actually wrote an article on my personal website to show how any program can be written in one line of python. I'd love for you to read it if it sounds interesting to you!

https://rebug.dev/post/TWCPgeW6ILJOa2WdR3U4

What do you think? Is my conjecture proven?

3 Comments
2024/02/01
01:12 UTC

0

Elegant js or Python memory game implementation?

Hi.

My kid is slowly getting into programming. I don't want to get too involved as I want him to be self taught like I was, however I had a look at the memory game he wrote and well he is my kid but that was one of the worst spaghetti code I've seen recently.

So I googled some top solutions on Google and to be honest it's not too good either, there's a lot of repeated code or HTML fragment, clearly violating the DRY rule.

Can anyone point me to an elegant, readable implementation of a memory game?

I appreciate that I'm not exactly looking for the leanest, shortest implementation however I'm sure at least one of you can point me to an elegant repo please.

Thank you very much in advance!!!

3 Comments
2024/01/29
13:58 UTC

7

Jugly.io: a minimalist JavaScript code golfing plateform

Hello fellow golfers!

I've recently made Jugly, a free web app designed for JavaScript code golfing. My goal was to create a place where simplicity meets challenge, allowing to focus on what we love most: crafting the shortest, least elegant code possible.

  • Pure JavaScript Challenges
  • Integrated monaco editor
  • Leaderboards

I built Jugly because I love code golfing in JS and thought it'd be cool to have a spot where we can all share that. It's a laid-back place for anyone who wants to play around with code, learn a bit, and maybe show off some.

Fancy a round of golf? Swing by https://jugly.io and see how few characters you can get away with!

It's a little project I whipped up in my spare time, nothing too fancy. I'm really looking forward to hear your feedback and see your names shining on the Jugly leaderboards!

14 Comments
2024/01/04
22:14 UTC

6

The 40 day countdown to the Lovebyte sizecoding/codegolfing demoparty ( https://lovebyte.party ) on February 9-11th 2024, starts now!

1 Comment
2024/01/02
11:35 UTC

5

What features do you wish golfing languages have?

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?

5 Comments
2023/12/05
23:41 UTC

3

9 code golf challenges: authorization

A logic game, similar to “Regex Golf”, that is designed to teach you authorization principles by completing permissions with as few objects as possible.

https://oso-golf.netlify.app/

0 Comments
2023/11/15
15:19 UTC

3

A free to enter, 240 character maximum, open-source iterated prisoner's dilemma tournament

I'm running an iterated prisoner's dilemma tournament for computer programs. All programs get access to their opponent's source code, and restricted to 240 characters maximum. The exact rules are posted at this link. You don't need an account on that website to participate, you can just put your program in the comments on Reddit or PM me. Have fun!

1 Comment
2023/11/09
16:58 UTC

5

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

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)
0 Comments
2023/10/24
17:06 UTC

7

List of Primes up to n in Python

Was playing around with some stuff and came across that black box of primes post. Decided to take a crack at it for fun. Came across a few components here and kinda threw it all together. Not original by any means, but still cool to look at.

f=lambda n:[]if n<2 else([n,*f(n-1)]if(n>1)&(n//1==n)&all(n%k for k in range(2,n))else f(n-1))

Credit to u/FreakCERS for the primality checker. I think there's room for improvement. Beyond me though. I don't usually do this sort of thing

1 Comment
2023/09/26
21:59 UTC

3

"Fairwell" - Four 3D animations with soothing music in 256 bytes

3 Comments
2023/09/11
16:22 UTC

Back To Top