Backspace-and-retype a list of words
Perl, 43 bytes
42 bytes of code + -n
flags.
chop$@,say$@while!s/^$@//;s/./say$@.=$&/ge
To run it:
perl -nE 'chop$@,say$@while!s/^$@//;s/./say$@.=$&/ge' <<< "abc
abd
aefg
h"
Java 8, 144 bytes
This one is similar to the reference implementation but combines the two while
loops. It's a lambda expression accepting a String[]
parameter.
a->{String c="";int l=0,i;for(String w:a)while((i=w.indexOf(c))!=0||!c.equals(w))System.out.println(c=i!=0?c.substring(0,--l):c+w.charAt(l++));}
Ungolfed
a -> {
String c = "";
int l = 0, i;
for (String w : a)
while ((i = w.indexOf(c)) != 0 || !c.equals(w))
System.out.println(c = i != 0 ? c.substring(0, --l) : c + w.charAt(l++));
}
Acknowledgments
- -38 bytes thanks to CAD97's lambda suggestion
Pyth, 25 23 bytes
V+QkWxNk
=Pk)
M>._Nl~kN
Try it online.