Posts by celtschk
C (gcc), 32 bytes f(a,b){return a>0?f(b,a-b)+1:0;} Try it online!
Python 3, 76 71 bytes Saved 5 bytes thanks to user def f(p,n):l=[n*p//q for(p,q)in p if n%q<1];return f(p,l[0])if l else n Try it online! This code assumes that the fractions are given a...
Given two strings, I define their product as follows: If any of the two strings is empty, the product is the empty string. If the second string consists of a single character, the result ...
I think everything strictly needed to write or judge a solution should never be hidden. If you feel it is too large, think about how to shorten it. Information that is not strictly necessary can b...
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!
Some additional cosiderations on using the sandbox: First, a migration mechanism might encourage good behaviour, for example by migration being only possible if the post has a minimal score, and/o...
Python 3, 48 bytes def f(n,d):return f"[{(50*n+d//2)//d*'|':-<50}]" Try it online!
Contestants should read from standard input and write to standard output. This is because almost all programming languages, including most esoteric programming languages, allow reading from standar...
C (gcc), 64 62 bytes Saved 2 bytes thanks to m90 in the comments. i;f(char*s){i=atoi(s)>>4;return'A'+(i&8?i&4?i&2?i%2+3:2:1:0);} Try it online!
Use pointer arithmetic and \0 with string literals In C, strings are just zero-terminated character arrays, which means you can play tricks with pointer arithmetic. For example, the line char*s=a...
C (gcc), 774 bytes #define S strcat(o, #define I(s)if(n)S s);else{S" ");return;} #define B);break;case n,N,s;char*i,o[999],*d[]={"zero ","one ","two ","three ","four ","five ","six ","seven "...
Python 3, 99 bytes r=[*range(26)] a="ABCDEFGHIJKLMNOPQRSTUVWXYZ" for i in r+r[-2::-1]:print(" "*(26-i)+a[:i]+a[i::-1]) Try it online!
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...
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...
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...
If you have any tips for golfing in Python, add them as answers to this post.
Unlambda, 1 solution Since Unlambda code that does something always contains the backtick character, there cannot be more than one solution. ```.2.5.6i
C (gcc), 232 bytes f(n,w,p){printf("%i bottle%s of beer%s%s",n,"s"+(n<2)," on the wall"+w,p);}main(i){for(i=99;i;){f(i,0,", ");f(i,12,".\n");printf(i>1?"Take one down and pass it around, "...
C (gcc), 114 bytes f(int n,int*p,int*i,int**o){if(n){int*m=i,k;for(;*m!=*p;++m);k=m-i;f(k,p+1,i,o);f(n-k-1,p+k+1,m+1,o);*(*o)++=*p;}} Try it online! Arguments: n is the length of the arra...
- ← Previous
- 1
- 2
- 3
- 4
- Next →