Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- if not tArgs[1] then
- error("Incorrect Parameters. neu <program name>")
- end
- local ref = "abcdefghijklmnopqrstuvwxyz\"()="
- local input = {" ","\n",".",","}
- for n in ref:gmatch("[^.]") do
- table.insert(input,n)
- end
- local goalf = fs.open(tArgs[1],"r")
- local goal = goalf.readAll()
- goalf.close()
- local tried = {}
- local thoughts = {}
- function used(level, char)
- if tried[level] then
- return tried[level][char]
- else
- tried[level] = {}
- return false
- end
- end
- function findVal(tab, val)
- for k,v in pairs(tab) do
- if v == val then
- return true,k
- end
- end
- return false
- end
- function countTable(tab)
- local n = 0
- for _ in pairs(tab) do n = n + 1 end
- return n
- end
- function genChar()
- local c
- if not tried[#thoughts+1] then
- tried[#thoughts+1] = {}
- end
- local suc,pkey = findVal(tried[#thoughts+1], true)
- if suc then
- c = pkey
- else
- if countTable(tried[#thoughts+1]) >= #input then
- error("Unknown character")
- end
- --if goal:sub(#thoughts+1,#thoughts+1)=="|" then
- -- printError("\n"..#tried[#thoughts+1])
- -- printError(#input)
- -- error("Wat... no catchy?")
- --end
- local stc = os.clock()
- repeat
- c = input[math.random(1,#input)]
- if os.clock()-stc > 0.1 then
- error("Caught foul exec time")
- end
- until used(#thoughts+1 , c) == nil --right here
- end
- return c
- end
- function right()
- local str = table.concat(thoughts)
- return str == goal
- end
- write("> ")
- while not right() do
- local pot = genChar()
- local px,py = term.getCursorPos()
- if pot=="\n" then
- write(" ")
- end
- write(pot)
- local pxx,pyy = term.getCursorPos()
- if (table.concat(thoughts) or "")..pot == goal:sub(1,#thoughts+1) then
- tried[#thoughts+1][pot] = true
- table.insert(thoughts,pot)
- sleep(0)
- else
- tried[#thoughts+1][pot] = false
- term.setCursorPos(px,py)
- sleep(0)
- end
- end
- print("")
- loadstring(goal)() -- :3
- local data = textutils.serialize(tried)
- local file = fs.open("data","w")
- file.write(data)
- file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement