This puzzle works for any programming language that has the same //
single-line and /* ... */
multi-line comments that C++, C# and Java do.
You are debugging an application. You find a fishy block of code, which you comment out and replace with some new code:
/*
code block A
*/
code block B
After some debugging, you find that you need to step through block A again to see how it worked. This requires quite a lot of cursor movement:
← remove “/*” here
code block A
/* ← change “*/” to “/*” here
code block B
*/ ← add “*/” here
This is very laborious if you need to keep switching between block A and block B. So you decide to find a better way.
Place combinations of asterisks and slashes before block A, between the blocks, and after block B, such that you can flip between block A and block B by adding/removing only one character in one place. You may assume that the code blocks A and B do not contain any /*
or */
.
There are two possible solutions.