Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ppanel = {}
- --ppanel = {"0000","0000","0000","0000"}
- spanel = {}
- --spanel = {"1111","1111","0000","0000"}
- --ppanel = {"0000","0000","0000","0000"}
- function show(p)
- for i=1,height,1 do
- print(p[i])
- end
- end
- function touch(puzzle,x,y)
- panel = {}
- for i=1,height,1 do
- panel[i] = ""
- end
- for i=1,height,1 do
- for j=1,width,1 do
- chr = string.char(string.byte(puzzle[i],j))
- if (i >= y-1 and i <= y+1 and j >= x-1 and j <= x+1) then
- if (chr == '0') then chr = '1'
- elseif (chr == '1') then chr = '0'
- end
- end
- panel[i] = panel[i]..chr
- end
- end
- return panel
- end
- function panelcmp(p1,p2)
- for i=1,width,1 do
- for j=1,height,1 do
- chr1 = string.char(string.byte(p1[j],i))
- chr2 = string.char(string.byte(p2[j],i))
- if (chr1 ~= chr2) then return false end
- end
- end
- return true
- end
- panels = 0
- function bruteforce(ps,pp)
- --print(panels)
- if (panelcmp(ps,pp) == true) then print("SOLVED\n");for k=1,height,1 do print(pp[k]) end return true; end
- if (panels < turns) then
- for i=1,height,1 do
- for j=1,width,1 do
- panels = panels + 1
- ret = bruteforce(ps,touch(pp,j,i))
- panels = panels - 1
- if (ret == true) then print(j,i); for k=1,height,1 do print(pp[k]) end return true; end
- end
- end
- end
- return false;
- end
- io.write("Set the width> ")
- width = io.read('*n')
- io.write("Set the height> ")
- height = io.read('*n')
- io.write("Set the turns> ")
- turns = io.read('*n')
- io.write("Write the solution in ",height," lines please\n")
- for i=1,height,1 do
- spanel[i] = io.read('*l')
- end
- io.write("\nWrite the puzzle in ",height," lines please\n")
- for i=1,height,1 do
- ppanel[i] = io.read('*l')
- end
- print("\nSo the puzzle is: ")
- for i=1,height,1 do
- print(ppanel[i])
- end
- print("\nSo the solution is: ")
- for i=1,height,1 do
- print(spanel[i])
- end
- --[[
- str = touch(ppanel,2,2)
- for i=1,height,1 do
- print(str[i])
- end
- ]]--
- --[[
- str = ppanel
- while(panelcmp(spanel,ppanel) == false) do panels = panels + 1
- io.write("x> ")
- x = io.read('*n')
- io.write("y> ")
- y = io.read('*n')
- str = touch(str,y,x);
- show(str)
- if (panels > turns) then panels = 0; str = ppanel; end
- end]]--
- print(panelcmp(spanel,ppanel))
- bruteforce(spanel,ppanel)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement