Posted 17 February 2012 - 02:32 AM
Code golf is a programming game where a problem is given to be solved. At the end of the challenge, all the solutions are checked for accuracy and the solution with the lowest amount of characters wins.
Here's how this will work. Every Thursday I will edit this post with a new challenge. The challenge must be sent to me via private message before 12:01 am EST the next Thursday, or else I will ignore it. You can resend a shorter or fixed solution to me as long as it is still on time. Just make sure you say in your message that this is a resend.
The solution must be done in Lua unless I specify otherwise. I check all solutions using Lua 5.1 on the Lua for Windows binary. If you think your code might be incompatible, send me a private message and we will work it out. The code you submit does not necessarily have to be compatible with ComputerCraft unless I specify otherwise in the challenge.
SEND ME A PASTEBIN LINK
I will not include your code in the solutions otherwise.
Lastly, I want to ask that you not post any hints or solutions in this thread until the challenge is over, as that could ruin the fun for some people. I hope to see some awesome entries from you guys. Good luck!
[left]This week's challenge is to make a program that compiles brainfuck code to Lua. If you don't know what brainfuck is, then go here or search it up on Google.[/left]
[left]Input:[/left]
[left]D:program.txt[/left]
[left]D:compiled.txt
D:input.txt
D:output.txt[/left]
[left]program.txt:[/left]
,[.,]
compiled.txt: (This will vary across solutions, of course)
mem = {}
p = 0
inputIndex = 1
outputIndex = 1
input = string.toable(io.open("D:input.txt", "r"):read()) –There is no string.totable, but you get the point
output = {}
mt = {__index = function() return 0 end}
setmetatable(input, mt)
setmetatable(mem, mt)
mem[p] = input[inputIndex]
while mem[p] ~= 0 do
output[outputIndex] = mem[]
mem[p] = string.byte(input[inputIndex])
end
io.open("D:output.txt", "w"):write(table.concat(output))
[left]input.txt:[/left]
This text will be copied to the output!
output.txt after compiled code execution:
This text will be copied to the output!
Here's how this will work. Every Thursday I will edit this post with a new challenge. The challenge must be sent to me via private message before 12:01 am EST the next Thursday, or else I will ignore it. You can resend a shorter or fixed solution to me as long as it is still on time. Just make sure you say in your message that this is a resend.
The solution must be done in Lua unless I specify otherwise. I check all solutions using Lua 5.1 on the Lua for Windows binary. If you think your code might be incompatible, send me a private message and we will work it out. The code you submit does not necessarily have to be compatible with ComputerCraft unless I specify otherwise in the challenge.
SEND ME A PASTEBIN LINK
I will not include your code in the solutions otherwise.
Lastly, I want to ask that you not post any hints or solutions in this thread until the challenge is over, as that could ruin the fun for some people. I hope to see some awesome entries from you guys. Good luck!
The Challenge
[left]This week's challenge is to make a program that compiles brainfuck code to Lua. If you don't know what brainfuck is, then go here or search it up on Google.[/left]
Details
- Limit of 30,000 memory cells.
- If pointer tries to go under the minimum cell, make it wrap to the highest cell.
- If pointer tries to go over the maximum cell, make it wrap to the lowest cell.
- All 8 commands must be supported.
- Compiled code must optimize multiple successive +,-,>, and <.
- The user must be allowed to give three inputs: a file for the program, a file for the compiled Lua, a file to be used as input for the brainfuck program, and a file to be used as output for the brainfuck program.
- If an i/o error occurs or access is denied, output exactly "File i/o failed." (without quotes) and end the program.
- , should get input from the input file given. ,[,.] should make the output file look the same as the input file. This also means that . should output to the output file given, of course.
- When gets to and goes past EOF, , must return 0.
Example
[left]Input:[/left]
[left]D:program.txt[/left]
[left]D:compiled.txt
D:input.txt
D:output.txt[/left]
[left]program.txt:[/left]
,[.,]
compiled.txt: (This will vary across solutions, of course)
mem = {}
p = 0
inputIndex = 1
outputIndex = 1
input = string.toable(io.open("D:input.txt", "r"):read()) –There is no string.totable, but you get the point
output = {}
mt = {__index = function() return 0 end}
setmetatable(input, mt)
setmetatable(mem, mt)
mem[p] = input[inputIndex]
while mem[p] ~= 0 do
output[outputIndex] = mem[]
mem[p] = string.byte(input[inputIndex])
end
io.open("D:output.txt", "w"):write(table.concat(output))
[left]input.txt:[/left]
This text will be copied to the output!
output.txt after compiled code execution:
This text will be copied to the output!