sofuckinglost asked: Hello! Here's a little recursive idea to do your method in pseudocode. it won't let me add newlines in here, so sorry for the mess, but it's short and simple: int check( str ){ int min = len(str); for (i=0; i<len(str)-1; ++i) { new_str = replacement on str using chars i and i + 1; if (there was a replacement) { int n = check( new_str ); if (n < min) min = n; } } return min;}
Hi! I ended up doing something similar to what you wrote.
First I wrote a function that chops a string into three parts: everything before the two letters I’m looking at, the two letters I’m looking at, and everything after the two letters. So chopAt("cab", 0) becomes ["", "ca", "b"], and chopAt("cab", 1) becomes ["c", "ab", ""].
This means I had to write my loop differently (0.upto(s.size - 2) …), but I get some cool functionality here. I check the 1st index of what chopAt returns to see if I can reduce. If I can reduce, I add the recurrence to an array, and then I sort the array by word length and return the smallest word.
I like that you skip the whole array thing I did and decided to directly compare the string lengths in your loop. Maybe that’s a better practice (if so, I’m just too used to working with lisp-lists).