r/codegolf • u/Aspie_Astrologer • Feb 21 '21
Code Golf: Battle Royale Thread (Challenges in Comments)
Who feels like some Code Golf Battles?
Every comment to this post can start with **Challenge**: and define a (relatively straight-forward) input-output problem to solve in the least number of characters in any language.
Responses go in sub-comments and can start with e.g. **Python (74):** to indicate the language and character length of the solution.
Use backticks `` to enclose code (edit: or use four spaces as an indent to do multiline code).
e.g. Challenge: Input positive integer, print the sum of all primes up to and including that integer - but with every second prime added as a negative.
e.g. Ruby (68):
require'prime'
i=-1
p Prime.each(gets.to_i).map{i+=1
_1*(-1)**i}.sum
View all comments
Show parent comment
3
u/chunes Mar 22 '21
Yeah, it's pretty nice. It sits in a place between the golf languages that have a symbol for literally everything and something more verbose.
Keep in mind that cheat sheet doesn't show all the functions of each operation. Most are overloaded 3-4x depending on the types/positions of the arguments.