Hello, I am writing a simple program that takes a one line input of characters and ‘<’ and then outputs what the input would look like if the ‘<’ represented a desired backspace. For example if the input was “hello<<” then output should be “hel”. If the input is “helle<o my name is mm<att” the output should be “hello my name is matt”. My code does what I want but I think if I add a break statement saying if input[i] does not equal a character or ‘<’ symbol then break it would be faster. This might not do it so I am open to another way that you think would be a lot faster, maybe using a regex. The input can be up to 10^6 characters and must run in <1sec. I split the code, delete the backspaces and characters infront of the backspaces then re-join at the end. There has to be a quicker way…
Thanks for the help!
Here is my code so far
i = 0 input = gets.chomp.split("") length = input.length loop do
if input[i] == '<'
i = i -2 end
if i == length # or... input[i] has no character in it.