Noodle9
  • Member for 8 years, 1 month
  • Last seen this week
24 answers
43 votes
2k views
Simplify ijk-string
2 votes

Python 3, 199 \$\cdots\$ 182 173 bytes f=lambda s,n=0:s<'.'and f(s[1:],1-n)or len(s)>1and f(s<'2'and s[1:]or(s[0]==s[1]and'-1'or{'ij':'k','jk':'i','ki':'j','ji':'-k','kj':'-i','ik':'-j'}[s[:...

View answer
20 answers
18 votes
2k views
Gödel numbering of a string
1 votes

C (gcc), 116 110 106 bytes Saved 3 bytes thanks to the man himself Arnauld!!! Saved 4 bytes thanks to ceilingcat!!! d;g;p;r;f(char*s){for(p=r=1;*s;r*=pow(p,17088/ *s++%75%14|1))for(g=0;!g;)for(g=d=p++...

View answer
14 answers
7 votes
593 views
Calculate \$ \lfloor n \log_2(n) \rfloor \$, exactly
0 votes

C (gcc), 52 \$\cdots\$35 23 bytes Saved 8 bytes thanks to tsh!!! f(n){n=logb(pow(n,n));} Try it online! Uses the formula from Manish Kundu's Python answer.

View answer
18 answers
21 votes
4k views
Convince me Gabriel's Horn is possible
2 votes

C (gcc), 70 69 bytes Saved a byte thanks to EliteDaMyth!!! f(x,y,z,i)float x,y,z;{for(;++i<11;)printf("%f ",2*(x*y+x*z+i*y*z));} Try it online! Prints out the surface areas starting at ...

View answer
19 answers
37 votes
3k views
Peter is a picky eater!
9 votes

Python 3, 96 92 91 bytes f=lambda l,n=1:n<=len(l)and-~f([v-(e<n)for e,v in enumerate(sorted(l)[::-1])if(e<n)-v],n+1) Try it online! Simply "eats" \$1\$ each of the \$n\$ cookies ...

View answer
15 answers
14 votes
1k views
Convert version string to pack_format
2 votes

C (gcc), 67 \$\cdots\$ 60 58 bytes Saved a byte thanks to ceilingcat!!! Saved 4 6 bytes thanks to tsh!!! Saved 2 bytes thanks to rtpax!!! y;f(p){p=(~-sscanf(p,"1.%d.%d",&p,&y)*y+p*p+...

View answer
15 answers
14 votes
1k views
Convert version string to pack_format
0 votes

Python 3, 72 bytes f=lambda p,n=0:float(p[2:])<[9,11,13,15,16.2,17,18][n]and n+1or f(p,n+1) Try it online!

View answer
20 answers
19 votes
1k views
Exact generalised harmonic numbers
2 votes

Python 3.8, 91 bytes import math f=lambda n,m,N=0,D=1:n and f(n-1,m,N*n**m+D,D*n**m)or(N/(G:=math.gcd(N,D)),D/G) Try it online! Inputs \$n\$ and \$m\$ and returns the numerator and denominator of \$...

View answer
37 answers
22 votes
2k views
Sum of first n terms of this series
2 votes

C (gcc), 45 43 bytes Saved 2 bytes thanks to Olivier Grégoire!!! t;s;f(x,n){for(s=t=0;n--;)s+=t=t*10+x;n=s;} Try it online!

View answer
19 answers
24 votes
1k views
Just Enough Ones
4 votes

C (gcc), 45 41 bytes f(n){n=n--<3?n:-~n*n*(f(n)+n*f(n-1)/2.);} Try it online! Inputs a positive integer \$n\$ and returns \$a_n\$.

View answer
18 answers
26 votes
2k views
Sum on a Fenwick Tree
3 votes

C (gcc), 31 38 36 bytes Added 7 bytes to fix a problem kindly pointed out by Nick Kennedy and Arnauld. f(a,n)int*a;{n=n?f(a,n--&n)+a[n]:0;} Try it online! Inputs a pointer \$a\$ to the Fenwick ...

View answer
18 answers
26 votes
2k views
Sum on a Fenwick Tree
4 votes

Python 3, 36 34 bytes Saved 2 bytes thanks to the man himself Arnauld!!! f=lambda a,n:n and a[n]+f(a,n&~-n) Try it online! Inputs Fenwick Tree \$a\$ (with a leading \$0\$) and \$1\$-indexed \$n\$...

View answer
12 answers
5 votes
912 views
Base-ically Guard
2 votes

C (gcc), 70 bytes a;i;r;f(x,b,l)int*b;{for(a=1,r=i=0;x;x/=10)r+=x%10*a,a*=b[i++%l];x=r;} Try it online! Inputs a non-negative integer in base 10, a pointer to the array of bases, and the array's ...

View answer
23 answers
18 votes
2k views
Delannoy numbers
1 votes

C (gcc), 45 bytes D(m,n){m=m*n?D(m-1,n)+D(m-1,n-1)+D(m,n-1):1;} Try it online!

View answer
18 answers
8 votes
1k views
Least notes money exchange
2 votes

C (clang), 60 58 bytes Saved 2 bytes thanks to G. Sliepen!!! f(n,x,y,s){(n+=y)%x?f(n,x,y,s+1):printf("%d %d",n/x,s+1);} Try it online! Uses the formula from Jonathan Allan's comment to ...

View answer
33 answers
22 votes
2k views
Apply at indices
3 votes

C (clang), 54 \$\cdots\$ 52 43 bytes Saved 9 bytes thanks to att!!! f(g(),*L,*I,n){for(;n--;)L[*I++]=g(L[*I]);} Try it online! Inputs a pointer to a function \$g\$ (inputting an int parameter and ...

View answer
3 answers
6 votes
366 views
Swap encoding iteration count
2 votes

C (clang), 5.383 seconds #include <strings.h> #include <string.h> #include <stdio.h> #include <stdlib.h> unsigned int f(char* str) { unsigned int count = 0; char ...

View answer
15 answers
15 votes
1k views
How many Faro shuffles for a cycle?
1 votes

C (gcc), 194 \$\cdots\$ 180 174 bytes Saved 6 bytes thanks to ceilingcat!!! w=52;n;c;i;j;a[156];f(s,l)int*s;{for(c=i=0;i<w*3;)a[n=i++]=i%w;for(;n;++c)for(j=0;j<l;++j)for(i=!wmemcpy(a+w,a,w);i&...

View answer
14 answers
21 votes
2k views
Collatz, Sort, Repeat
1 votes

C (gcc), 183 \$\cdots\$ 149 148 bytes g;t;l;i;e(a,b)int*a,*b;{i=*a>*b;i-=*a<*b;}f(k,n){int a[g=l=n<<k];for(;g||k--;g=qsort(a,l,4,e))for(i=l;i--;a[i]=g?i+1:t%2?3*t+1:t/2)t=a[i];i=a[n-1];} ...

View answer
14 answers
17 votes
951 views
Implement swap encoding
2 votes

C (clang), 98 96 87 bytes i;j;t;f(char*s){for(;*s;++s)for(i=0,j=index(s+1,*s)-s;j>i;s[j--]=t)t=s[i],s[i++]=s[j];} Try it online! Inputs a pointer to a string and swap encodes the string in place.

View answer
14 answers
17 votes
951 views
Implement swap encoding
0 votes

Python 3.8, 96 bytes f=lambda s,i=0:i<len(s)and f(i<(j:=s[i+1:].find(s[i])+i+1)and s[:i]+s[j:i:-1]+s[j:]or s,i+1)or s Try it online!

View answer
16 answers
11 votes
2k views
Write a program with infinite expected output
1 votes

Bash, 24 bytes echo 32767/$RANDOM|bc -l Try it online! Prints a random number between \$1\$ and \$\infty\$.

View answer
17 answers
8 votes
1k views
Base-ically god
1 votes

C (gcc), 82 bytes a;c;i;r;f(x,b,l)int*b;{for(a=1,r=i=0;x;x/=c)c=b[i++%l],r+=x%c*a,a*=10,x-=x%c;x=r;} Try it online! Inputs a non-negative integer in base \$10\$, a pointer to the array of bases, and ...

View answer
12 answers
15 votes
1k views
Phibonacci - Relation between Phi and Fibonacci
2 votes

Python 3, 120 102 88 bytes Saved a whopping 18 32 bytes thanks to ovs!!! f=lambda n,r=1,a=0,b=1:n>1and f(n-1,r,b,a+b)or-((1+5**.5)*r//2!=b*r//a or~f(n,r*10,a,b)) Try it online!

View answer
74 answers
21 votes
4k views
Compose a song, line by line
4 votes

Day 0. C (gcc), 5 bytes f(){} Try it online! Next line: YOU ARE LIKELY TO BE EATEN BY A GRUE (MC Frontalot "It Is Pitch Dark")

View answer
64 answers
50 votes
10k views
Implement Minceraft
8 votes

C (gcc), 48 bytes f(){printf("Min%sraft",rand()%10000?"ec":"ce");} Try it online! Version closer to \$\frac{1}{10000}\$ For a pseudorandomness as close to \$\frac{1}{...

View answer
16 answers
14 votes
388 views
Sum over an Interval
2 votes

C (gcc), 82 80 79 bytes Saved 2 3 bytes thanks to ceilingcat!!! a;b;c;f(char*s){sscanf(s+1,"%d,%d%c",&a,&b,&c);a-=*s&1;b-=c<42;b=a*~a-b*~b>>1;} Try it online!

View answer
31 answers
25 votes
2k views
Count the trailing zeros
4 votes

C (gcc), 38 27 bytes Saved 11 bytes thanks to AZTECCO!!! f(n,b){n=n%b?0:1+f(n/b,b);} Try it online!

View answer
37 answers
23 votes
1k views
Replace all items with their counts
2 votes

C (clang), 84 \$\cdots\$ 81 75 bytes Saved 6 bytes thanks to AZTECCO!!! b;i;j;f(*a,l){for(i=-1;++i<l;printf("%d ",b))for(b=j=l;j--;)b-=a[i]!=a[j];} Try it online! Inputs a pointer to an ...

View answer
39 answers
28 votes
2k views
Implement an Over function
4 votes

C (gcc), 54 \$\cdots\$ 39 37 bytes Saved 8 bytes thanks to dingledooper!!! Saved 2 bytes thanks to ceilingcat!!! o(f,g,a,b)int f(),g();{g(f(a),f(b));} Try it online!

View answer
1 2
3
4 5
19