/r/codegolf
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
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.
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!
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)
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:
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)
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.')
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!
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.
can anyone suggest any suitable platforms to host a code golf contest right now, ik about code.golf and anarchygolf
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)))}
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?
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!!!
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.
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!
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?
A logic game, similar to “Regex Golf”, that is designed to teach you authorization principles by completing permissions with as few objects as possible.
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!
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)
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