Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »

Search

Advanced Search Options

To further refine your search, you can use additional qualifiers such as score:>0.5. For example, the search score:>=0.5 created:<1y grammar would return only posts mentioning "grammar" that have a score >= 0.5 and were created less than a year ago.

Further help with searching is available in the help center.

Quick hints: tag:tagname, user:xxx, "exact phrase", post_type:xxx, created:<N{d,w,mo,y}, score:>=0.5

Filters
 
66%
+2 −0
Q&A Tips for golfing in Python

If you have any tips for golfing in Python, add them as answers to this post.

19 answers  ·  posted 3y ago by celtschk‭  ·  last activity 9d ago by trichoplax‭

Question code-golf tips
66%
+2 −0
Q&A Tips for golfing in Python

If you have a loop or if, you can save two or more characters (depending on the current indentation level and the number of statements in the body) by putting it right after the colon: For example...

posted 3y ago by celtschk‭  ·  edited 3y ago by General Sebast1an‭

Answer
66%
+2 −0
Challenges My house is destroyed! Can you make me one?

jq --raw-output, 32 bytes jq is the language of the month, apparently. Here it is! Not sure if the --raw-output flag really matters, someone let me know. "#"*.+(" #"+" "*(.-2)+"#")*(.-1) Try ...

posted 3y ago by snail_‭  ·  edited 3y ago by snail_‭

Answer
66%
+2 −0
Challenges When The Ternary Is Balance

Python 3, 78 bytes def t(n,*l):d="0+-"[n%3];return d*(not l or n*n) if n*n<2 else t((n+1)//3,1)+d Try it online!

posted 3y ago by celtschk‭  ·  edited 3y ago by celtschk‭

Answer
66%
+2 −0
Q&A Tips for golfing in Python

Replace for loops with string multiplication Let's say we have: for i in range(6):print(end="#") Try it online! This basically outputs # 6 times, which is self-explanatory in the code itsel...

posted 3y ago by General Sebast1an‭

Answer
66%
+2 −0
Challenges Stairs? Stairs! Stairs.

Haskell, 78 bytes (!)0.(*2) i!n|i<n=(drop 3$(n-i)#' '++"_/"++i#'#'):(i+2)!n|0<1=[] (#)=replicate Try it online!

posted 3y ago by Hakerh400‭

Answer
66%
+2 −0
Q&A Tips for golfing in Python

Replace print loops by list unpacking If you want to print elements of a list one per line, the straightforward way to do it is a loop: for i in l:print(i) But this can be shortened using list...

posted 3y ago by celtschk‭

Answer
66%
+2 −0
Q&A Tips for golfing in Python

import* You can import some libraries and if you find yourself using: from lib import * Remove the space between import and *, because it works for whatever reason.

posted 3y ago by General Sebast1an‭

Answer
66%
+2 −0
Challenges "Hello, {name}!"

Haskell, 43 35 bytes main=interact$("Hello, "++).(++"!") Try it online!

posted 3y ago by Hakerh400‭  ·  edited 3y ago by Hakerh400‭

Answer
66%
+2 −0
Challenges "Hello, {name}!"

C (gcc), 43 bytes a[99];main(){printf("Hello, %s!",gets(a));} Try it online!

posted 3y ago by Lundin‭

Answer
66%
+2 −0
Challenges Are All Elements Equal?

Ruby, 15 bytes ->a{a.all?a[0]} ->a{ } # lambda taking array `a` a.all? # do all items in the array match... a[0] # ...the first? Try it online!

posted 3y ago by snail_‭

Answer
66%
+2 −0
Challenges Are All Elements Equal?

C (gcc), 46 bytes f(int*a){return *a<0|a[1]<0||*a==a[1]&f(a+1);} This takes an array that is terminated by a negative number (which is not part of the list content, just like the te...

posted 3y ago by celtschk‭

Answer
66%
+2 −0
Q&A Tips for golfing in Python

Renaming functions A funny, cool, and useful trick. If you have to write a single function multiple times (usually range() on for loops), then you can simply assign a variable by the function's na...

posted 3y ago by General Sebast1an‭  ·  edited 9d ago by trichoplax‭

Answer
66%
+2 −0
Challenges Reverse an ASCII string

Lua, 32 bytes print(string.reverse(io.read())) Try it online! Noice built-in.

posted 3y ago by General Sebast1an‭

Answer
66%
+2 −0
Challenges Tile pyramids on top of each other!

Ruby, 43 bytes ->n{(1..n).map{|i|" "*(n-i)+?/*i+?\\*i}*$/} ->n{ } # lambda (1..n).map{|i| } # map over 1 to n ...

posted 4y ago by snail_‭

Answer
66%
+2 −0
Challenges Towering Cistercian Representation

JavaScript (Node.js), 606 bytes for(_="=>\\\\ =j(...(a:').join`\\n`[q](/aa),/ / / d[c[___) .match(/.{.||]/g,=='.mapf=(n,m=([a,b]a?m(b)+a',l=10000n,j=, b,c=0a-c?[b(cj,b,c+1)]:[],b=[q='rep...

posted 4y ago by Hakerh400‭  ·  edited 4y ago by Hakerh400‭

Answer
66%
+2 −0
Challenges Write a Deadfish Interpreter

APL (Dyalog Classic), 47 bytes i←+∘1⋄d←-∘1⋄s←×⍨⋄o←⎕∘←⋄{}{0⌈a×256≠a←⍎⍕⍺,⍵}/⌽0,⍞ Try it online!

posted 4y ago by rak1507‭

Answer
66%
+2 −0
Challenges Write a Deadfish Interpreter

JavaScript (Node.js), 80 bytes f=a=>a.map(a=>(a&=6,a-2?a-6?c+=1-a/2:d+=c+' ':c*=c,c*=c!=-1&c!=256),c=0,d='')&&d Try it online!

posted 4y ago by Hakerh400‭

Answer
66%
+2 −0
Challenges Length of a Sumac Sequence

Jelly, 9 bytes Rȧ_@Rп@L Try it online! Takes $t_1$ on the left and $t_2$ on the right. R}ȧ_@RпL works given the arguments in the opposite order. R Ascending range from 1 to t_1 (...

posted 4y ago by Unrelated String‭  ·  edited 4y ago by Unrelated String‭

Answer
66%
+2 −0
Challenges Evaluate a single variable polynomial equation

Pyth, 10 bytes s*R^H~hZhA Try it online! Alternate 10 byte solution: s.e*b^eQkh Try it online!

posted 4y ago by hakr14‭  ·  edited 4y ago by hakr14‭

Answer
66%
+2 −0
Challenges Golf me a polygonal loader

CGCC Sandbox, Codidact Sandbox Given three positive integers as input, animate an ascii-art polygonal loading symbol on the screen. Intro Using the first input $n$, Take one the following regul...

1 answer  ·  posted 4y ago by Razetime‭  ·  edited 3y ago by General Sebast1an‭

Question code-golf ascii-art animation
66%
+2 −0
Q&A Befunge Golfing Tips

Bitwise operations (WIP) Befunge, rather pointedly, lacks bitwise ops. No shifts, no and, no or, no xor. Shifts Shifts can be implemented as multiplication and division by powers of two. Shifts...

posted 4y ago by moony‭

Answer
66%
+2 −0
Challenges Bytes to Segfault

Bash, 11 kill -11 $$ Try it online!

posted 4y ago by Nominal‭

Answer
66%
+2 −0
Sandbox The Tannenbaum series

posted 4y ago by Lundin‭

Article code-golf