Posts by Moshi
JavaScript (Node.js), 99 96 69 bytes s=>([a,b,c,d]=s.match(/-?\d+/g),a*c-b*d+(a=a*d+b*c,a<0?'':'+')+a+'i') Try it online! This regex is probably the best way to get the numbers. Also, f...
JavaScript (Node.js), 27 22 bytes -5 bytes thanks to Hakerh400 Direct computation f=n=>(n+(n*n+4)**.5)/2 $$\frac{n+\sqrt{n^2+4}}{2}$$ Try it online!
MoshiBot from numpy.polynomial import Polynomial def MoshiBot(data, history): if len(history) < 10: return [180, 180, 0] lastmin = min(history[-1]) lastmid = sorted(history[-1])[1] ...
Challenge It's a bootstrapping challenge this time! Write a full program that, once run, writes the source code of another program that in turn, once run, writes the source code for another progra...
JavaScript (Node.js), 47 40 50 49 bytes -1 (possibly -3) bytes thanks to Shaggy! f=(n,s='0')=>n?f(n/3+n%3/2|0,'')+"+-0+-"[n%3+2]:s Try it online! A basic recursive solution.
Python 3, 64 bytes def f(n): for i in range(n):print((' '*(n-i)+'_/'+'##'*i)[3:]) Try it online!
Python 3, 5 unique bytes, 28 total (()==())/((()==())+(()==())) (, ), =, /, + Uses (()==()) to get True with only 3 unique characters, as well as making the later grouping of (...+...) free. ...
Sclipting, (UTF-16) 454 406 bytes Yes. 塊匱❸곴김分倘標⓶❹演긆륩닆롩닶밎併鈉不終⓷곴김剩❶갾밈分倘⓷標⓷❺演긇끨닷녳눖멤併鈉⓶不終갾밈剩❶뉀分倘⓷標⓷❺演긆둵닦끲뉖밄併鈉⓶不終뉀剩⓶글會⓶倘❷長是긆굮뉂밀⓶終긇끨늗긠뉦뭵댢걦늖눠댶땸긇꽥덦녮긆녩뉶될닦땮뉐❷굀瀰是❶銅긂건덶녮融壹坼❸겠分掘덇밉⓸겠剩倘껐⓶⓹逆⓸終終긆뭮뉒건덶묠덆둲뉖넠뉦뭵댢걦늗뉥긇꽩...
Use the unpacking * instead of list If you want to convert an iterator/generator into a list, use the * operator instead of using the list function, e.g. Instead of list(iterable) Use [*iter...
Sclipting, (UTF-16) 26 bytes 갠긂갠밂乘감뒄뀢감雙갿및剩 Uses a formula I found here unsigned char b; // reverse this (8-bit) byte b = (b * 0x0202020202ULL & 0x010884422010ULL) % 1023;
Sclipting, (UTF-16) 86 bytes 標갠 관上가①要❶❹剩걉눑감⓶重右갰雙⓷加⓶❸分終⓷棄終并❶訂乾⓶折❷同終長괐縮⒈棄丟 Explanation: Input n 標 갠 관上 for b from 2 to 16 가 s = 0 ① n' = n 要 while n' is not 0 ❶❹剩 x = n...
JavaScript (Node.js), 160 bytes (r,d,n,l=r.length,s=d.length,p=(n,i)=>n?"01110110"[4*p(--n,i-1)+2*p(n,i)+1*p(n,i+1)]:i>=0&i<s?d[i]:r[(i%l+l)%l])=>[...Array(4*l+s+2*n)].map((_,i)=...
JavaScript (Node.js), 101 82 bytes -19 bytes thanks to Shaggy! x=>x.replace(/(..)\1{0,62}/g,(c,g)=>c>'c'||c[5]?(192+c.length/2).toString(16)+g:c) Try it online! Everything can be sol...
Python 3, 399 bytes def f(n): if n<1:return'zero' t=1000;m=t*t;r='r fif six seven eigh nine ';b=f'one two three four five six seven eight nine ten eleven twelve thir fou{r}twen thir fo{r}'....
Python 3, 191 bytes lambda p:[c for c in chain(*[C(p,r)for r in range(len(p)+1)])if all(all(i==(sum(p.values())/2>=sum(p[n]for n in d))for d in C(c,len(c)-i))for i in[0,1])] from itertools imp...
Sclipting, (UTF-16) 58 52 bytes 가匱❸增平갠下氫終要鈮貶⓶梴감⓶上❸乘殲終終并鈮掘增 Gives the nth ludic number, 0-indexed. 가 Start list of Ludics with 0 匱❹增平갠下氫終 Create a list of numbers from 2 to n+1 squared 要 W...
Python 2, 58 54 bytes lambda l:''.join(filter(None,sum(map(None,'',*l),()))) Try it online! Amazingly, shorter than my Python 3 answer! Uses this method to zip unequal-length lists and this me...
Python 3, 72 69 bytes lambda l:''.join(sum(zip(*[[*i]+['']*max(map(len,l))for i in l]),())) Try it online! Uses this method to flat zip, with modifications to pad the shorter lists.
JavaScript (Node.js), 242 234 bytes s=>([l,p,i,j,_,r]=/(-)?\+?(\d*)\.?(\d*?)(((\d+)\6|\d)\.|$)/.exec(s),[i,r]=c(c([i|0,1],[j|0,10**(l=j.length)]),[r=r||'0',10**l*(10**r.length-1)]),[(p?-i:i)/(j...
JavaScript (Node.js), 91 68 65 bytes s=>s.toUpperCase().match(/(?<=^| )[A-Z]|:|;|(?<=[.?!]) /g).join`` Assumes that the original text is properly formatted (has a space after punctuati...
C, 147 bytes float d(float**m,int r){if(r<2)return**m;int i=r,j;float s=0,*n[--r];for(;i--;s+=(i%2?-1:1)**m[i]*d(n,r))for(j=r;j--;)n[j]=m[j+(j>=i)]+1;return s;} Try it online! Basically ...
C (gcc), 301 bytes Function taking in an array of null-terminated strings and the array's length. #include <string.h> #include <stdlib.h> char*s="edellowreenrowncarletlackchreachuby...
JavaScript (Node.js), 75 68 bytes -7 bytes thanks to Hakerh400 (a,b)=>b.map(i=>[a[i],a[j]]=[a[j=b[Math.random()*b.length|0]],a[i]]) Try it online! Basic random swap algorithm. Unfortuna...
- ← Previous
- 1
- 2
- 3
- Next →