Skip to main content
2 of 4
added 471 characters in body
Blab
  • 471
  • 3
  • 4

Lua, 402 344 bytes

402

r,p,b,x=string.rep,print,' ','x'function d(s,n)h=(n+1)/2;if s=='-'then p(r(s..b,n))end;if s=='='then p(r(s..b,n))p(r(s..b,n))end;if s=='/'then for i=1,n do p(r(b,n-i)..s)end end;if s=='+'then for i=1,n do p(i~=h and r(' ',n-1)..'+'or r('+ ',n))end end;if s=='x'then for i=1,n do if i<h then p(r(b,i-1)..x..r(b,n-2*i)..x)elseif i>h then p(r(b,n-i)..x..r(b,-n+2*i-2)..x)else p(r(b,i-1)..x)end end end end

344

r,p,b,x=string.rep,print,' ','x'function d(s,n)h,l=(n+1)/2,s..b;e=r(l,n)if s=='-'then p(e)elseif s=='='then p(e)p(e)else for f=1,n do if s=='/'then p(r(b,n-f)..s)elseif s=='+'then p(f~=h and r(' ',n-1)..'+'or r('+ ',n))elseif s=='x'then p(f<h and r(b,f-1)..x..r(b,n-2*f)..x or f>h and r(b,n-f)..x..r(b,2*f-2-n)..x or r(b,f-1)..x)end end end end

402 Readable:

r,p,b,x=string.rep,print,' ','x'
function d(s,n)
  h=(n+1)/2;
  if s=='-'then 
    p(r(s..b,n))
  end
  if s=='='then 
    p(r(s..b,n))
    p(r(s..b,n))
  end
  if s=='/'then 
    for i=1,n do 
      p(r(b,n-i)..s)
    end 
  end
  if s=='+'then 
    for i=1,n do 
      p(i~=h and r(' ',n-1)..'+'or r('+ ',n))
    end 
  end
  if s=='x'then 
    for i=1,n do
      if i<h then 
        p(r(b,i-1)..x..r(b,n-2*i)..x)
      elseif i>h then 
        p(r(b,n-i)..x..r(b,-n+2*i-2)..x)
      else 
        p(r(b,i-1)..x)
      end
    end
  end
end

That ended up a bit bigger than intended after getting that x working, but at least I do already know a couple places I can shave off some bytes. This is my first pass though.

Also looks like this is an old challenge. Oops- followed a link from a new challenge that was only about printing pluses. I already went through the work though so I'll leave my answer anyways.

Round 2: 58 characters eliminated and I can still do better. A solid next step.

Blab
  • 471
  • 3
  • 4