Posts by celtschk
Python 3, 75 bytes lambda a:[[i,k]for i in r(l(a))for k in r(l(a[0]))if a[i][k]] r=range;l=len Try it online!
C (gcc), 53 bytes This uses the shortcut behaviour of logical or (||) to only multiply if it is a divisor; the loop end condition then makes sure it's a proper divisor. i=1;p=1;f(n){for(;i<n...
C (gcc), 37 bytes This takes an integer as input. It uses the fact that the last digit is odd if and only if the number is odd, and that integer division by 10 removes the last digit. Testing if ...
Bash, 205 bytes for s in C{C{CC,D,M},DC,MC} {CM,DC,D}{D,M} I{C,D,I{II,V,X},L,M,VI,X{C,I,L,V,X}} L{C,D,L,M,XC,XL} MMMM V{C,D,IV,IX,L,M,V,X} X{C{C,D,L,M,X},D,LX,M,X{C,L,XX}} do echo $1|grep -q $s...
Python 3, 35 bytes lambda m:list(zip(*m[::-1]))[::-1] Try it online! The format is a list of tuples. The content of the tuples could be any type; in my tests I used single-digit strings bec...
Python 3, 59 bytes lambda n,m:sum(choices(range(m),k=n))+n from random import* Try it online!
Lundin just suggested in a comment under another question that I tag the challenge Looping Counter as kolmogorov-complexity. Now I'm not sure if it actually qualifies for that tag, for the followi...
C (gcc), 103 bytes Using a different approach than my previous solution, therefore posting as new answer as suggested here. i;main(){while(i++<100){char s[]="FizzBuzz",*t=s+4*!!(i%3);if(i%5)...
C++ (gcc), 61 bytes float f(int n,float*p,float x){return n?*p+x*f(n-1,p+1,x):0;} Try it online!
Unlambda, 40 bytes `````````````.H.e.l.l.o.,. .W.o.r.l.d.!i Try it online!
Replace n+1 with -~n and n-1 with ~-n For integers, n+1 and ~-n have the same value, as have n-1 and -~n. While the expressions themselves have the same lengths, the replacements often allow to s...
Replace if/else expressions by array subscripts Consider the statement a=b if x<y else c You can get rid of the expensive keywords by using the implicit conversion of boolean values to inte...
Python 3, 91 90 bytes Saved one byte thanks to Mark Giraffe in the comments lambda l:"".join(["".join(x)for x in zip_longest(*l,fillvalue='')]) from itertools import* Try it online!
C (gcc), 40 bytes i;f(n){for(i=1;n>0;n-=i,i+=2);return!n;} Try it online!
Python 3, 64 62 bytes for i in range(1,101):print("Fizz"*(i%3<1)+"Buzz"*(i%5<1)or i) Try it online! Saved two bytes thanks to Moshi in the comments.
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...
C (gcc), 87 bytes P1: i;main(){scanf("%d",&i);printf("i;main(){scanf(\"%%d\",&i);printf(\"%%d\",%d+i);}",i);} Try it online! Generated P2 for input 10: i;main(){scanf("%d",&i...
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...
C (gcc), 50 bytes f(int(*o)(i,j),int n){return n-1?o(f(o,n-1),n):1;} Try it online!
C (gcc), 33 31 bytes f(x,y){return x+y+(x==2&y==2);} Try it online! Saved two bytes thanks to Shaggy
SOS, 155 Bytes !+!-!!+!-!!!!+!!-!!+!-!+!-!+!!-!+!!-!!!+!!-!+!!-!!!+!!-!+!!!!-!!+!-!+!!-!!!!+!-!!!!!!+!-!+!-!+!!!-!+!!-!+!!!!-!+!!!-!!+!-!!+!!-!+!!-!!!+!!-!!+!-!!+!-!!!!+! Explanation: Each ! o...
SOS, 76 bytes +>+>?<+>?<+>?<+>?<+>?<+>?<+>?<+>?<<)<<-(>{>!<{>!<{>!<{>!<{>!<{>!<{>!<{>!&l...
Python 3, 74 bytes def f(a): d={x:0 for x in a};r=[] for x in a:d[x]+=1;r+=[d[x]] return r Try it online!
- ← Previous
- 1
- 2
- 3
- 4
- Next →