Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 86147

Code-golf is a competition to solve a particular problem in the fewest bytes of source code.

1 vote

Shortest auto-destructive loop

Zsh, 18 bytes Abusing the short form of the for and implicit short command list. Will report "Command not found" for the first iteration, but will continue to the second and then crash. for i (1 0 …
GammaFunction's user avatar
1 vote

Incrementing Numbers, Over Multiple Sessions

Zsh (no coreutils), 32 bytes a=`<$0` <<<$[$#a/2-15] >>$0<<<: (Note the trailing newline) Uses the length of the script. On each invocation, the last line shown above will append : (identical to tr …
GammaFunction's user avatar
3 votes

Attacking the Hydra

Zsh, 41 bytes We ignore N, as stated by the rules. for i;a+=(0) for i;a[i]=($[++j] $j) <<<$a Try it online! Pretty standard: Make an array of 0s to start, print it to finish. The a[i]=(a b) met …
GammaFunction's user avatar
3 votes

triplegolf - not only the source code length counts!

Zsh, 20 bytes <<< $-$_$_$_$_$_ [ The problem we face here is alluded to in a comment above: Zsh prints the program name in addition to the line number before every error. The solution here uses …
GammaFunction's user avatar
1 vote

Tex Quotes(UVa 272)

(GNU) sed, 38 33 30 bytes -4 by removing the -n flag and implicitly printing on n, -1 by reusing previous /expression/, thanks @Cowsquack. -3 by using implicit branch-to-end. :a s/"/``/;T :b s//''/; …
GammaFunction's user avatar
5 votes

Little Endian Number to String Conversion

Zsh, 46 bytes i=$1 repeat 4 printf %02x $[j=i%256,i=i/256,j] Try it online!
GammaFunction's user avatar
1 vote

Calculate the internal angles of a regular polygon with N sides

Zsh, 17 bytes <<<$[180-360./$1] Try it online! Pending consensus, the following may be a valid 15 byte solution, or more likely a 17 byte tie with () declaring it a function: ((180-360./$1)) …
GammaFunction's user avatar
0 votes

Who's Who in the Name-Change Game?

AWK, 132 bytes /.* -?[0-9]/{a[$1]+=$2} !/.* -?[0-9]/{a[$2]=a[$1]+0;delete a[$1]} END{PROCINFO["sorted_in"]="@val_num_desc";for(k in a)print k,a[k]} Try it online! We're careful to +0 to make sure …
GammaFunction's user avatar
1 vote

Help me pair my left and right socks!

Zsh, 179 177 bytes typeset -A p l for x (`<&0`)((l[$x]++)) for k;((p[$k]=l[$k]<l[-$k]?l[$k]:l[-$k],l[$k]-=p[$k],l[-$k]-=p[$k])) a=({,-}$^@) for k (${(k)l:|a})((p[$k]=l[$k]/2,l[$k]%=2)) typeset p l …
GammaFunction's user avatar
0 votes

Find all unambiguous prefixes of a set of strings

Zsh, 95 bytes local -A m for w;{m[$w]=$w;x= for c (${(s::)w})x+=$c&&[ ${(M)@:#$x*} = $w ]&&m[$x]=$w } local m Try it online! The only way to "return" an associative array in Bash/Zsh is by decla …
GammaFunction's user avatar
3 votes

The Sorting Hat

Zsh, 66 bytes case $1 in ?ra*|g*)<<<S;;[lp]*|cho)<<<R;;h?r*|r*)<<<G;;*)<<<H;esac Try it online! No hash functions available, so we make do with pattern matching in a single case statement: case …
GammaFunction's user avatar
1 vote

Generate newspaper page number sets

Bash, 42 bytes -1 bytes from @pxeger for((x=$1;x>y;)){ echo {,}$[++y]\ $[x--];} Try it online! Try it online! I'm usually the Zsh guy, but here Bash wins by a few bytes because it evaluates brace e …
GammaFunction's user avatar
2 votes

Help me pair my socks

Zsh, 81 74 bytes -3 bytes by testing set difference in arithmetic mode instead, -4 bytes by using local instead of typeset local -A p for x;a=(${a:#$x} ${x:|a})&&((${#x:|a}&&++p[$x])) local p <<<$a …
GammaFunction's user avatar
4 votes

Iterative Smallest Complement

Zsh, 44 bytes <<<$@ a=({$1..$@[$#]}) (($#))&&$0 ${a:|argv} Try it online! <<<$@ # output arguments a=({$1..$@[$#]}) # all integers between first and last args (($#)) && # if the …
GammaFunction's user avatar
1 vote

The Unaverageables

Zsh, 75 bytes for x;for y;((s=x+y,s%2||x==y))||a+=(${=${(M)@:#$[s/2]}:+$x $y}) <<<${@:|a} Try it online! Not as compact as I was expecting... for x;for y # for $x, $y in the Cartesian product of t …
GammaFunction's user avatar

1
2 3 4 5
18
15 30 50 per page