Skip to main content
deleted 770 characters in body
Source Link
Blab
  • 471
  • 3
  • 4

Lua, 402 344344 312 bytes

344312:

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 p(s=='/'then p'and(r(b,n-f)..s)elseif s=='+'thenor ps=='+'and(f~=h and r(' ',n-1)..'+'or r('+ ',n))elseif s=='x'thenor 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

402344:

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

402 Readable:

r,p,b,x=string.rep,print,' ','x'
function'x'function d(s,n)
  h=(n+1)/2;
  if2;if s=='-'then 
    p(r(s..b,n))
  end
  ifend;if s=='='then 
    p(r(s..b,n))
    p(r(s..b,n))
  end
  ifend;if s=='/'then 
    for i=1,n do 
      p(r(b,n-i)..s)
    end 
  end
  ifend;if s=='+'then 
    for i=1,n do 
      p(i~=h and r(' ',n-1)..'+'or r('+ ',n))
    end 
  end
  ifend;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 90 characters eliminatedreduced and I can still do better. A solid next stepit's now painful to look at even when expanded. :|

Lua, 402 344 bytes

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:

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

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.

Lua, 402 344 312 bytes

312:

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 p(s=='/'and(r(b,n-f)..s)or s=='+'and(f~=h and r(' ',n-1)..'+'or r('+ ',n))or 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

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:

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

90 characters reduced and it's now painful to look at even when expanded. :|

added 2 characters in body
Source Link
Blab
  • 471
  • 3
  • 4

402344:

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

344402:

r,p,b,x=string.rep,print,' ','x'function d(s,n)h,l=h=(n+1)/2,s..b;e=r(l,n)if2;if s=='-'then p(er(s..b,n)elseif)end;if s=='='then p(er(s..b,n))p(er(s..b,n)else)end;if s=='/'then for f=1i=1,n do if s=='/'then p(r(b,n-fi)..s)elseifend end;if s=='+'then for i=1,n do p(f~=hi~=h and r(' ',n-1)..'+'or r('+ ',n))elseifend end;if s=='x'then p(f<hfor andi=1,n do if i<h then p(r(b,fi-1)..x..r(b,n-2*f2*i)..x or)elseif f>hi>h andthen p(r(b,n-fi)..x..r(b,2*f-2n+2*i-n2)..x or)else p(r(b,fi-1)..x)end end end end

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

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:

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
added 471 characters in body
Source Link
Blab
  • 471
  • 3
  • 4

Lua, 402402 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:

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.

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.

Also looks like this is an old challenge. Oops- followed a link from a new challenge that was only about printing pluses.Round 2: 58 characters eliminated and I already went through the work though so I'll leave my answer anywayscan still do better. A solid next step.

Lua, 402 bytes

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

Readable:

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.

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:

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.

Source Link
Blab
  • 471
  • 3
  • 4
Loading