r/codegolf • • Apr 08 '18

[Python3.5][ALL] Codejam 2018 Qualification Round

0 Upvotes

I had some fun over the weekend codegolfing my solutions to the qualification round of the codejam. I managed to bring the average file size under 200 bytes, but the problem A is still much larger than the others, do you see how to improve it?


r/codegolf • • Apr 03 '25

Extreme python golfing

1 Upvotes

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 • • Sep 23 '26

My 32x32 PNG is only 104 bytes - when tiled it makes this peak wallpaper [OC]

1 Upvotes

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 • • Aug 05 '25

Consumer of RAM

Post image
0 Upvotes

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 • • Jun 30 '15

Pastebin clone in a tweet

Thumbnail
twitter.com
6 Upvotes

r/codegolf • • Nov 24 '19

Fibo pyramid

0 Upvotes

1 1 2 3 5 8 13 21 34 55 ....


r/codegolf • • Apr 03 '21

Dragon's Lair by Desire - 256 bytes intro for Msdos/FreeDos/WinXP/DosBox

Thumbnail
pouet.net
4 Upvotes

r/codegolf • • Jan 22 '14

[C#] Deleting a directory tree. In a weird way...

Thumbnail
gist.github.com
0 Upvotes

r/codegolf • • Jun 18 '14

Write An Aphorism Using Valid Code [CONTEST][ALL]

Thumbnail
codegolf.stackexchange.com
0 Upvotes

r/codegolf • • Dec 03 '25

1k drum machine and step sequencer

Thumbnail js1k.com
1 Upvotes

r/codegolf • • Apr 12 '19

My C++ homework in 260 characters

6 Upvotes
#define q int const
bool sameSet(q*a,q*b,q*c,q*d){if(b-a>d-c)swap(a,c),swap(b,d);int s=1,r=0;for(;a!=b;s*=*a++);for(;c!=d;r|=s%*c++);return!r;}void copyEvens(q a[],size_t c,int b[],size_t&d){d<c?throw length_error(0):d=0;for(q*e=a+c;a<e;a++)if(~*a%2)b[d++]=*a;}

r/codegolf • • Feb 10 '17

jsgolf.club: a slack room to talk about JS code golfing

Thumbnail
jsgolf.club
0 Upvotes

r/codegolf • • Jun 09 '15

Tweetable Python Code Golf

Thumbnail
python3.codes
0 Upvotes

r/codegolf • • Mar 06 '21

Only one more week until Lovebyte 2021 tiny intro demoparty (http://www.lovebyte.party/) on March 12-14, 2021

1 Upvotes

Only one more week until Lovebyte 2021 (http://www.lovebyte.party/) on March 12-14, 2021 and we've got so much great content for you lined up for you all through the whole weekend! Nano Awards, Roundtables, Preshows, Seminars and many intro compeitions for all platfroms from atari, commodore and zxspectrum to dos and tic-80 and everything in between

We are entering our last week until the lovebyte party with two new reveals at the MDT9K Lovebyte special preparty on 6th March 20:30 UTC+0 / 21.30 CET at https://www.twitch.tv/psenough with your host psenough, hellmood and guests.

So go watch, Get your vote/registration keys today, Vote for the Nano Awards, Spread the word and Get those entries in!


r/codegolf • • Nov 23 '13

[BASH] Something outside the box of common CS examples: An HPC job restart script [ALL]

1 Upvotes

I present to you my restart script in use on our HPC cluster.

export TIME4SAVE=90
mpirun ${HOME}/d19e/execute/DLP.X &
export SLEEP_ID=$!
( sleep ` qstat -f $PBS_JOBID | awk -v t=$TIME4SAVE                   \
    '{if ( $0 ~ /Resource_List.walltime/ )                            \
        { split($3,duration,":");                                     \
          print duration[1]*3600+duration[2]*60+duration[3]-t }}' `; \
  pkill -P $SLEEP_ID) >& /dev/null  &
wait
~/Startscripts/starters/resubmit_torque.py 
wait

Charcter count is 444 charcters, including spaces, excluding newlines.

Have fun golfing!


r/codegolf • • Oct 25 '25

10 PRINT is a book about a one-line Commodore 64 BASIC program, published in November 2012.

Thumbnail
10print.org
1 Upvotes

r/codegolf • • May 16 '26

New Challenge on Byte Heist: Cockroach Salad

Thumbnail byte-heist.com
1 Upvotes

r/codegolf • • Oct 04 '14

[javascript] rock, paper, scissors, lizard, spock

2 Upvotes

Challenge: Write a function that takes the two choices as argument(s), and returns the correct outcome ie. "lizard poisons spock" for the arguments "lizard" and "spock". For invalid input or ties, output "nobody wins". Bonus points for not using E6 features and not leaking variables to the environment. I have a version using standard js with no leaking in 279 bytes, using E6 features at 260 - I'll post it in 24 hours (or before if it's beaten)


r/codegolf • • Oct 12 '14

[PYTHON] quicksort

2 Upvotes

Hey guys, new to code golf and coding in general. I understand quicksort is a simple algorithm, but if you guys can write entire servers in under 50 lines, then I'd bet some of you can write this in under 50 characters. Anyway, this what I've got so far; a function that takes an array and returns it sorted.

def q(a):
	if len(a)<2:return a
	m=a[int(len(a)/2)]
	return q([x for x in a if x<m])+[x for x in a if x==m]+q([x for x in a if x>m])

Including the tabs, since python needs them, but not the unnecessary spaces, my code comes out to 132 characters. Let's see you guys blow me out of the water.


r/codegolf • • Apr 05 '14

[java] Change Of Number Base[All]

2 Upvotes

I was bored and started thinking about how short this could get. At first it seemed a little imposing, but the character count dropped quickly.

For the purpose of this challenge the code should be able to convert from base 10 to any other base between 2 and 16, inclusive.

My solutions:

a is the number in base ten, b is the desired base. Discounting any unneeded white space, this come out to 187 chars.

public static void changeOfBaseGolf(int a, int b){
    int c,d;
    for(d=a==0?0:(int)(Math.log(a)/Math.log(b));d>=0;d--,a%=c)
        System.out.print("0123456789ABCDEF".charAt(a/(c=(int)Math.pow(b,d))));
}

I love recursive solutions to stuff, so I also made this. It's 203 chars if I don't count the helper method. Like I said, this is just for the fun of recursion.

public static String  changeOfBaseGolf(int a, int b,int c){return(c==0?"0123456789ABCDEF".charAt(a):"0123456789ABCDEF".charAt(a/(int)Math.pow(b,c))+changeOfBaseGolf(a%(int)Math.pow(b,c),b,c-1))+"";}

The recursive solution, unfortunately requires that you supply the the number of digits the final answer will have, so there must be a method for that. I did not bother to play to much golf with this, because it was never meant to be the shortest solution.

 public static int maxPlaceValue(int num,int base){
    return (int) (num<base?0:(Math.log(num)/Math.log(base)));
 }

Any other solutions would be great to see. If you can improve upon my java solution, I'd like to see it. If you can make something shorter in another language, I'd also love to see it.


r/codegolf • • Oct 17 '25

javascript demos in 140 characters

Thumbnail dwitter.net
2 Upvotes

r/codegolf • • Oct 03 '22

Code golfing American Psycho's new business card

Thumbnail
youtu.be
10 Upvotes

r/codegolf • • Jul 17 '23

(Meme) "I'm something of a golfer myself..."

Post image
10 Upvotes

r/codegolf • • Jan 29 '24

Elegant js or Python memory game implementation?

0 Upvotes

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!!!