Jump to content




Lua Code Golf


114 replies to this topic

#41 immibis

    Lua God

  • Members
  • 1,033 posts
  • LocationWellington, New Zealand

Posted 17 August 2013 - 01:00 AM

I was wondering whether we should count required whitespace (e.g. in 'return x' or '" +"') then I came up with that :P

#42 Sora Firestorm

  • Members
  • 89 posts

Posted 17 August 2013 - 01:11 AM

Here's a trimmed version of what I've already submitted, weighing in at 548 chars

Spoiler


#43 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 17 August 2013 - 01:18 AM

View Postimmibis, on 17 August 2013 - 01:00 AM, said:

I was wondering whether we should count required whitespace (e.g. in 'return x' or '" +"') then I came up with that :P
To make things less complicated and keep scripts at least somewhat readable, I'd just not count whitespace at all.

#44 immibis

    Lua God

  • Members
  • 1,033 posts
  • LocationWellington, New Zealand

Posted 17 August 2013 - 01:20 AM


View PostKingdaro, on 17 August 2013 - 01:18 AM, said:

View Postimmibis, on 17 August 2013 - 01:00 AM, said:

I was wondering whether we should count required whitespace (e.g. in 'return x' or '" +"') then I came up with that :P/>
To make things less complicated and keep scripts at least somewhat readable, I'd just not count whitespace at all.
And then this is the solution to every challenge:

View Postimmibis, on 17 August 2013 - 12:36 AM, said:

74 chars packager (or any other program):
http://pastebin.com/BuGmiRrY


#45 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 17 August 2013 - 01:44 AM

For the top level coroutine override, here's my go at killing the top level shell. Although os.shutdown isn't restored in this script, the original function is stored in _G.o, so the script "n" might look like:

os.shutdown = _G.o
os.run ({}, "rom/programs/shell")

97 characters:
Spoiler


#46 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 17 August 2013 - 06:16 AM

My top level coroutine override.

Characters
82

Note
I even cleanup my temp variable (75 characters if I don't cleanup)

Code
os.queueEvent("modem_message")
p=pcall
pcall=function()
  pcall=p
  p=nil
  os.run({},"a")
end

Note 2
pcall is called after printError is...

#47 ElvishJerricco

  • Members
  • 803 posts

Posted 17 August 2013 - 11:28 AM

View Posttheoriginalbit, on 17 August 2013 - 06:16 AM, said:

My top level coroutine override.

Characters
82

Note
I even cleanup my temp variable (75 characters if I don't cleanup)

Code
os.queueEvent("modem_message")
p=pcall
pcall=function()
  pcall=p
  p=nil
  os.run({},"a")
end

Note 2
pcall is called after printError is...

Won't work as written. You're just setting the pcall in the shell environment, not the _G environment. Also, it takes one fewer character to do function a() than a = function().

Written so it works,

Characters
82

Code
os.queueEvent("modem_message")
p=pcall
function _G.pcall()
  _G.pcall=p
  os.run({},"n")
end

EDIT: actually, not sure why you did p = nil. It's no big deal if you leave a random p=pcall in the shell environment that's never going to be used again. Especially since this competition is about making code as short as possible =P Edited the code and now its 82 again instead of 87.

#48 Sorroko

  • Members
  • 87 posts

Posted 17 August 2013 - 11:25 PM

This is my second attempt at the button api...

Code: 206 characters without whitespace
Spoiler

My test code:
Spoiler


#49 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 17 August 2013 - 11:34 PM

View PostSorroko, on 17 August 2013 - 11:25 PM, said:

This is my second attempt at the button api...

Code: 206 characters without whitespace
Spoiler

My test code:
Spoiler

Nice!

#50 kreezxil

  • Members
  • 128 posts
  • LocationBowie, TX

Posted 05 September 2013 - 04:18 PM

My Entry for the GOTO Challenge. Number of Characters: 544

Instructions:
  • Place mining turtle facing north.
  • Put fuel in any or all slots.
  • give command*: goto <x> <y> <z> [r]
*Note: You supply the character r if the coordinates are relative to the turtle, like 5 away would be relative. Instead of absolute coordinates.

Pastebin Code: DcWDK1RG
Turtlescripts: http://turtlescripts...ect/gjdhhr-GoTo

Spoiler


#51 bentallea

  • Members
  • 19 posts

Posted 08 September 2013 - 03:22 PM

I have a suggestion for a challenge: aes-128 encryption and decryption in one function

here is my attempt:
Spoiler


#52 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 10 September 2013 - 07:57 PM

Well boys, you'd best get coding because we have two new challengers. Bit, your challenge has been taken up by the one and only kreezxil! Your new size to beat is 544! And we now have a new challenge submitted by bentallea, who also currently holds the number one spot.

#53 NOTUSEDPLEASEDELETE

  • Members
  • 70 posts

Posted 18 September 2013 - 02:43 AM

Idea:

Make a fully functional ComputerCraft email that has these features:
  • Uses term.isColor() for colours.
  • Auto-checks after a message gets sent.
  • Good interface.
  • Customisable colours.


#54 bentallea

  • Members
  • 19 posts

Posted 06 October 2013 - 10:09 AM

this is for the turtle goto challenge
instructions:
  • place turtle facing west
  • insert fuel into any slot
  • run goto(x,y,z,[b])
NOTE: if there is any data in b then the coordinates are assumed global. leave b out of the function if the coordinates are relative to the turtle.
Spoiler
total length: 447 characters without whitespace

#55 Symmetryc

  • Members
  • 434 posts

Posted 06 October 2013 - 10:53 AM

View Postimmibis, on 17 August 2013 - 12:36 AM, said:

74 chars packager (or any other program):
http://pastebin.com/BuGmiRrY

Creates a global function package(dirPath) -> packagedString.
Doesn't write it to a file, the caller is responsible for that.
Couldn't you use #k instead of k:len()?
Edit: There are a couple more changes that can be done to make it smaller.
Char Count: 67
Spoiler


#56 kreezxil

  • Members
  • 128 posts
  • LocationBowie, TX

Posted 06 October 2013 - 11:43 AM

View Postbentallea, on 06 October 2013 - 10:09 AM, said:

this is for the turtle goto challenge
instructions:
  • place turtle facing west
  • insert fuel into any slot
  • run goto(x,y,z,)
NOTE: if there is any data in b then the coordinates are assumed global. leave b out of the function if the coordinates are relative to the turtle.
Spoiler
total length: 447 characters without whitespace
this program won't run it's only a function, You need the interface code for parsing the command line. it's character count will be more than 447. At minimum you will need this at the end of the program to make it functional:
a={...}
goto(a[1],a[2],a[3],a[4] or nil)
Also there is an error on line 1 of your function() you have 'B' and not 'b'. Remember variables are case sensitive. With my addition to make your goto function an actual program for the competition valid your total character count comes to 476!

#57 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 06 October 2013 - 11:56 AM

View Postkreezxil, on 06 October 2013 - 11:43 AM, said:

this program won't run it's only a function
This was the challenge I put forward "Your challenge is to create a `goto` function/program for a Turtle."

That does put bentallea in the lead with 447 characters.


View Postkreezxil, on 06 October 2013 - 11:43 AM, said:

Also there is an error on line 1 of your function() you have 'B' and not 'b'.
You've been around on these forums long enough now to know that a lowercase (or uppercase) b when placed directly beside a ) inside of code tags gets formatted in an attempt to make it an emoticon.
B)/>

I hope that you aren't just being a "sore loser" because your entry was beaten.

#58 Geforce Fan

  • Members
  • 846 posts
  • LocationMissouri, United States, America, Earth, Solar System, Milky Way, Universe 42B, Life Street, Multiverse, 4th Dimension

Posted 06 October 2013 - 01:53 PM

Challenge: Make an operating system in which runs without the shell, has windows, and uses no APIs in 3 characters.
Just kidding.
Real challenge:
Make a rednet API replacement without the use of the rednet API itself at all. It will also need to be able to use channels, not just make the computer ID the channel

#59 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 06 October 2013 - 03:22 PM

My attempt at a quine:
 


Run this as a program and it will return it own sourcecode.

Total characters: 0

#60 bentallea

  • Members
  • 19 posts

Posted 06 October 2013 - 04:53 PM

for a quine i have 2 possible ideas:
  • 	return "return"
    	
    = 14 chars
  • 	print("print(\"\")")
    	
    = 20 chars
run either one as a program should yield the source code





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users