Dendrobium
  • Member for 7 years, 9 months
  • Last seen this week
Lever Simulator 2015
16 votes

Javascript ES6, 62 Bytes s=>Math.sign([...s].reduce((p,c,i)=>p+~~c*(i-s.indexOf`^`),0)) -1 if left is heavier 0 if balanced 1 if right is heavier Ungolfed: s=> Math.sign( ...

View answer
Visualise Bit Weaving
11 votes

Javascript ES6, 168 167 bytes Edit: Whoops, turned out I was using the pipe | char instead of U+2502 │ in part of the function, updated byte count. _=>((n=`0 1 2 3 4 5 6 7 `)+[...`6452301`].map(i=...

View answer
Cover up zeroes in a list
11 votes

Javascript ES6, 19 bytes s=>s.map(i=>p=i||p) Straightforward solution, loop through input, assign p to current element i or to p if i is 0 and output it. Example run (assigning anonymous ...

View answer
Maze Generation
Accepted answer
10 votes

C: 265 253 Bytes #define f(v)for(v=0;v<k;++v) #define d(q,n)case q:r(c+n,c+2*n); z[4225],i,j,k=65;r(p,c){if(!z[c]){z[p]=z[c]=1;f(p)switch(rand()%4){d(0,-k)d(1,k)d(2,-1)d(3,1)}}}main(){f(i)z[i]=z[i+...

View answer
Make a 3var interpreter!
8 votes

Javascript ES6 ES7, 217 215 213 208 bytes f=s=>(O='',[for(c of'@#e'+s)eval('v=0,++v,--v,v*=v,O+=v,O+=String.fromCharCode(v),v=R,R=0,R=A+B,R=A-B,R=A*B,R=A/B|0,O+=R+" "'.replace(/v/g,'AB'[(x='@idspP&...

View answer
Starbucks to English
6 votes

Javascript ES6, 902 900 bytes s=>(R=(l,r)=>(l.split`.`.map((e,i,l)=>!(i%2)&&(r=r.split(e).join(l[i+1]+" "))),r),R("-.no.!.-tuple.1/2.half-caf.1/3.one-third-caf.2/3.two-thirds-caf.ECP....

View answer
Rotate a hypercube
6 votes

Javascript ES6, 584 bytes f=(...R)=>(P=s=>[...s].map(i=>parseInt(i,16)),C=document.createElement`canvas`,X=C.getContext`2d`,X.translate((C.width=300)/2,(C.height=300)/2),X.lineWidth=0.01,X....

View answer
Ways to get to the number
6 votes

Javascript ES6, 45 44 bytes f=(a,b=B)=>a<(B=b)?f(a+1)+f(a+2)+f(a*3):a==b Example runs: f(1,2) -> 1 f(2,6) -> 6 f(1 10) -> 84

View answer
Between the Lines
5 votes

Javascript ES6, 506 bytes a=>{with(document)with(body.appendChild(createElement`canvas`))with(getContext`2d`){width=height=(a.length+2)*80;scale(20,20);translate(1,1);lineWidth=0.1;beginPath();["...

View answer
Sort the pixels
5 votes

Javascript ES6, 334 bytes f=s=>{with((d=document).body.appendChild(c=d.createElement`canvas`).getContext`2d`)(i=new Image).src=s,drawImage(i,0,0,w=c.width=i.width,h=c.height=i.height),t=(g=...

View answer
Implement functional programming paradigms
5 votes

Javascript ES6, 197 * 0.9 = 177.3 bytes M=(f,l)=>F((a,b)=>[...a,f(b)],[],l) N=(f,x,n)=>f(--n?N(f,x,n):x) A=(f,l)=>f(...l) R=n=>n--?[...R(n),n+1]:[] F=(f,x,l,n=l.length)=>n--?f(F(f,x,...

View answer
Telescopic Parentheses
5 votes

Javascript/ES6, 97 chars f=s=>{for(n in s){m=o=d='';for(c of s)o+=n==(c<')'?d++:--d)?c:' ',m=m<d?d:m;n<m&&console.log(o)}} Usage f("(()(()())()((())))(())") Explanation fn=str=...

View answer
Truncate consecutive character runs to n length
4 votes

Javascript ES6, 60 54 55 43 bytes -12 bytes thanks to @TestSubject06 and @Downgoat (s,n)=>s.replace(/(.)\1*/g,x=>x.slice(0,n)) Example runs: f("aaaaaaabbbccCCCcc" , 2) -> "aabbccCCcc"...

View answer
Recursive Steiner Chains
4 votes

Javascript ES6, 379 bytes This solution was used to generate the example runs in the question. f=(s,ls)=>{with(V=document.createElement`canvas`)with(getContext`2d`)with(Math)return(width=height=s,...

View answer
Longest Common Prefix of 2 Strings
4 votes

Javascript ES6, 52 bytes f=(a,b)=>[...a].filter((e,i)=>e==b[i]?1:b='').join`` Usage: >> f("global","glossary") "glo"

View answer
A Sine of Greatness
4 votes

Javascript ES6, 154 148 (198 - 25%) (n=0)=>[S='sine',(O='co')+S,T='tangent',C='secant',X=O+C,O+T,V='ver'+S,O+V,'ex'+C,'ex'+X].map((q,i)=>q+': '+[s=Math.sin(n),c=Math.cos(n),t=s/c,e=1/c,o=1/s,1/...

View answer
Write a program to elasticize strings
3 votes

Javascript ES6, 42 41 bytes s=>[,...s].map((e,i)=>e.repeat(i)).join`` Example runs: f=s=>[,...s].map((e,i)=>e.repeat(i)).join`` f("Why") => "Whhyyy" f("SKype") => "...

View answer
Compress your code in an image
3 votes

Javascript ES6 - 216 bytes f=( )=>((d=(x=(v=document.createElement`canvas`).getContext`2d`).createImageData(v.width=9,v.height=8)).data.set([..."f="+f].reduce((p,c,i)=>(c=c.charCodeAt(0),[...p,...

View answer
Secret Santa - Revisited
3 votes

Javascript ES6, 191 This solution returns all possible pairings as a list of list of pairs: f=l=>(h=l=>l.length,n=l.map(i=>i.shift()),o=[],(r=s=>(g=h(s))<h(n)?l[g].map((e,x)=>e&...

View answer
Dimensional Analysis
3 votes

Javascript ES6, 479 bytes f=(s,b="s, m, gk, A, gkm,ss gkmm,ss gkmm,sss gkmm,AAss gk,mss As, gkmm,Asss AAssss,gkmm gkmm,AAsss AAsss,gkmm gkmm,Ass gk,Ass ,s".split` `,d="s m kgA N J W H PaC V F Ω S WbT ...

View answer
Stop, stand there where you are!
3 votes

JavaScript ES6, 40 bytes t=>{for(t=(d=Date.now)()+t*1e3;d()<t;);} Tested with the following: elapsed=(f,t,b=(d=Date.now)())=>(f(t),console.log(d()-b+"ms elapsed")) // accepts func, delay ...

View answer
Bit-Reversal Permutations
2 votes

Javascript ES6, 65 53 51 bytes f=(n,m=1)=>n?[...n=f(n-1,m+m),...n.map(i=>i+m)]:[0] Uses the recursive double-increment-concat algorithm. Example runs: f(0) => [0] f(1) => [0, 1] f(2) =&...

View answer
Back to the chemistry class
2 votes

Javascript ES6, 96*0.9 = 86.4 f=s=>`2C${(n=(s.match(/\d+(?!.*\d)/)[0]-2))>2?n/2:''}H${n+2} + ${1.5*n+1}O2 > ${n+2}H2O + ${n}CO2`

View answer
A single pixel moving in a circular path
2 votes

Javascript ES6, 202 bytes a=0;with((D=document).body.appendChild(D.createElement`canvas`).getContext`2d`)with(Math)setInterval((f=t=>t(a+=PI/6e3)*60+75)=>fillRect(f(cos,clearRect(0,0,150,150),...

View answer
Averages of Angles
2 votes

Javascript ES6, 87 bytes with(Math)f=(...n)=>(t=>180/PI*atan(t(sin)/t(cos)))(f=>n.reduce((p,c)=>p+=f(c*PI/180))) Example runs (Tested in Firefox): f(-91,91) // -0 f(-90,90) // 0 ...

View answer
Obfuscating text by cycling ternary digits
2 votes

Javascript (ES6), 179 bytes s=>[...s+s[0]].map(q=>`00${(q<'a'?26:q.charCodeAt(0)-97).toString(3)}`.slice(-3)).join``.slice(1,-2).match(/..?.?/g).map(q=>q>221?' ':String.fromCharCode(...

View answer
Evaluate a Stratego Battle
1 votes

Javascript ES6, 98 86 bytes (a,b,g)=>a==1?b==g?a:[a,b]:b=="B"?a==3?a:b:a=="S"?b==10?a:b:b=="S"?a:a==b?[]:+a>+b?a:b Accepts 3 args (attacker, defender, spotter guess). Example runs: f("4","6")...

View answer
Hidden Power Calculator
1 votes

Javascript (ES6), 203 bytes f=(...l)=>(q=(b,m)=>~~(l.reduce((p,c,x)=>p+(!!(c&b)<<x),0)*m/63),'...

View answer
Barcodegolf: Generate a number's UPC
1 votes

Javascript ES6, 199 bytes n=>`P1 95 30 `+(101+(g=(a,...s)=>(``+1e12+n).slice(...s,-6).split``.map(m=>(1e3+a[m].toString(2)).slice(-7)).join``)(a=[13,25,19,61,35,49,47,59,55,11],-12)+`01010`+...

View answer
Be respectful in the restroom
0 votes

Javascript ES6 - 98 95 91 86 84 88 bytes Edit: Seems that the leftmost-stall should be used in the case of a tie. Squared distances no longer work, reverted to absolute distance. (r,x=0,f=g=>r....

View answer