Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define a function to jumble text
- local function jumbleText(text)
- local jumble = {}
- for i = 1, #text do
- jumble[i] = text:sub(i, i)
- end
- for i = #jumble, 2, -1 do
- local j = math.random(i)
- jumble[i], jumble[j] = jumble[j], jumble[i]
- end
- return table.concat(jumble)
- end
- -- Define a function to unjumble text
- -- Note: For simplicity, this function assumes the text was jumbled with the same method
- local function unjumbleText(jumbledText)
- -- This is a placeholder since unjumbling requires knowing the original positions
- -- Implementing a real unjumbling would need a more sophisticated approach
- return "Unable to unjumble without original positions"
- end
- -- Define a function to read text from a file
- local function readFile(fileName)
- local file = fs.open(fileName, "r")
- if not file then
- error("File not found")
- end
- local text = file.readAll()
- file.close()
- return text
- end
- -- Define a function to write text to a file
- local function writeFile(fileName, text)
- local file = fs.open(fileName, "w")
- file.write(text)
- file.close()
- end
- -- Main program
- local inputFileName = "input.txt"
- local jumbledFileName = "jumbled.txt"
- local unjumbledFileName = "unjumbled.txt"
- -- Read the original text
- local originalText = readFile(inputFileName)
- -- Jumble the text
- local jumbledText = jumbleText(originalText)
- -- Write the jumbled text to a file
- writeFile(jumbledFileName, jumbledText)
- -- Try to unjumble the text (Note: This won't work correctly with the current unjumble function)
- local unjumbledText = unjumbleText(jumbledText)
- -- Write the unjumbled text to a file
- writeFile(unjumbledFileName, unjumbledText)
- -- Check if the unjumbled text matches the original text
- if unjumbledText == originalText then
- print("The unjumbled text matches the original text.")
- else
- print("The unjumbled text does not match the original text.")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement