This is my first time here at Code Golf SE so feel free to add your input/advice/suggestions to improve my post if necessary. The week after my computer science exam, the solutions were publicly published. One problem had a 45 line example solution but my solution was only 18 lines, (which I was very proud of), but I bet you guys here at code golf SE can do better.
Here are the requirements:
- Takes two inputs, string1 and string2.
- Delete the first occurrence of string2 found in the string1.
- Add string2 in reverse order to the beginning of string1, and
- Add string2 in reverse order to the end of the string1.
- If string2 does not occur in string1, do not modify string1.
- Output the modified string1
Example:
Input:
batman
bat
thebatman
bat
batman
cat
Output:
tabmantab
tabthemantab
batman
Note: The problem was intended to handle basic inputs. Assume all expected inputs are restricted to characters A-Z, numbers, or other special characters visible on your keyboard. It does not need to handle tabs or newlines.
Submissions with shortest byte counts in each language win.
s/string2//
fail \$\endgroup\$"batman_and_his_bat", "bat"
→"tabman_and_his_battab"
\$\endgroup\$