|
| 12 May 2012 08:21 PM |
The object is to try to complete a task in Lua with as little characters as possible. Line breaks and other white-space characters count. You can have your code as ugly and hackish as you like.
First task:
Create a wave of an alternating character with x as the width, print the wave to the output. What the wave should look like:
Width 0:
\ / \ /
Width 1:
\ _\ _/ / \ _\ _/ /
Width 2:
\ _\ __\ __/ _/ / \ _\ __\ __/ _/ /
You can have the leading character be an underscore or space. I will be the judge. Remember, as little characters as possible! |
|
|
| Report Abuse |
|
|
| |
|
|
| 12 May 2012 08:26 PM |
| The object is to attempt to complete a task in Lua using as little characters as possible. |
|
|
| Report Abuse |
|
|
|
| 12 May 2012 09:00 PM |
| I have (unofficially) made a working example that is exactly 100 characters long, not including declaration of 'x', I will post at the end of this contest. (Should there be a prize? I have 1,000 R$ spare...) So if it's more than 100 characters, it could use some work! |
|
|
| Report Abuse |
|
|
LPGhatguy
|
  |
 |
| Joined: 27 Jun 2008 |
| Total Posts: 4725 |
|
|
| 13 May 2012 12:59 AM |
Here's an 11 line implementation:
r=string.rep function f(x) local o="" for i=1,x do o=o..r(" ",i).."\\\n" end for i=x,1,-1 do o=o..r(" ",i).."/\n" end return o end
Call f with any real number x. |
|
|
| Report Abuse |
|
|
LPGhatguy
|
  |
 |
| Joined: 27 Jun 2008 |
| Total Posts: 4725 |
|
|
| 13 May 2012 01:02 AM |
And actually, since I didn't completely conform to the requests of the output (width 0 should return an actual wave, and it should be two 'hills' long) here's a 13 line, 147 character implementation that's fixed:
r=string.rep function f(x) local o="" for _=0,1 do for i=0,x do o=o..r(" ",i).."\\\n" end for i=x,0,-1 do o=o..r(" ",i).."/\n" end end return o end |
|
|
| Report Abuse |
|
|
Valone
|
  |
| Joined: 08 Feb 2012 |
| Total Posts: 4371 |
|
|
| 13 May 2012 03:10 AM |
s=string.rep for i = 1,5 do for i2 = 1,i do print(s("-",i2-1).."\\") end for i3 = 1,i do print(s("-",i-i3).."/") end end
Nothing fancy, did exactly what you said, (had to switch from spaces :/ )
☜▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☜☆☞▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☞ -Valone; Game maker; Graphical Artist and Programmer. (Female) |
|
|
| Report Abuse |
|
|
Valone
|
  |
| Joined: 08 Feb 2012 |
| Total Posts: 4371 |
|
|
| 13 May 2012 03:12 AM |
Oops, missed the x bit....
s=string.rep x = 5 for i = 1,x do for i2 = 1,i do print(s("-",i2-1).."\\") end for i3 = 1,i do print(s("-",i-i3).."/") end end
☜▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☜☆☞▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☞ -Valone; Game maker; Graphical Artist and Programmer. (Female) |
|
|
| Report Abuse |
|
|
Valone
|
  |
| Joined: 08 Feb 2012 |
| Total Posts: 4371 |
|
|
| 13 May 2012 03:15 AM |
Sorry for the triple post. Got it to 111 characters.
s=string.rep p=print for i=1,10 do for v=1,i do p(s("-",v-1).."\\") end for a=1,i do p(s("-",i-a).."/") end end
☜▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☜☆☞▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☞ -Valone; Game maker; Graphical Artist and Programmer. (Female) |
|
|
| Report Abuse |
|
|
LPGhatguy
|
  |
 |
| Joined: 27 Jun 2008 |
| Total Posts: 4725 |
|
|
| 13 May 2012 03:17 AM |
@Valone But what about having it as a single string, and as a function? |
|
|
| Report Abuse |
|
|
Valone
|
  |
| Joined: 08 Feb 2012 |
| Total Posts: 4371 |
|
|
| 13 May 2012 03:21 AM |
Wasn't a rule. He just said put it in output =D I'll give it a go though.
☜▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☜☆☞▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☞ -Valone; Game maker; Graphical Artist and Programmer. (Female) |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
|
| 13 May 2012 09:38 AM |
It looks like Oysi is the winner, my code with 100 chars:
b=0 c={'\\','/',1,0}while 1 do for i=0,x do print((' '):rep(math.abs(x*b-i))..c[b+1])end b=c[b+3]end
I can donate 1000 R$, it's all I have. Want it? |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 13 May 2012 10:44 AM |
Take out the returns, and replace them with a ;
Make it 3-4 characters shorter. Because Windows adds \t to it. |
|
|
| Report Abuse |
|
|
| |
|
iCookieNL
|
  |
| Joined: 24 May 2009 |
| Total Posts: 1103 |
|
|
| 13 May 2012 01:35 PM |
dofile("C:/LuaCodeGold.lua")
owned. |
|
|
| Report Abuse |
|
|
| |
|
|
| 13 May 2012 04:39 PM |
@Blue:
Source: "" Output: ""
Done. |
|
|
| Report Abuse |
|
|
MacGod
|
  |
| Joined: 16 Apr 2012 |
| Total Posts: 114 |
|
|
| 13 May 2012 05:55 PM |
*makes this script import global function from other script that does cool stuff*
_G.a()
ok i win |
|
|
| Report Abuse |
|
|
|
| 13 May 2012 06:20 PM |
| @Mac, I am testing these on Luaforwindows. No ROBLOX functions. |
|
|
| Report Abuse |
|
|