I’m working my way through
Cracking the Coding Interview as a way of
learning the new features and tool ecosystem of C++17.
Q1.9 reminded me of those games where you need to make a shape by drawing straight lines through dots. The trick with those games is to realise that you can draw outside the (implicit) bounds of the dots themselves. For Q1.9, the trick is to realise that you can concat the test string as any rotation will be a substring of the repeated string.
I’m quite happy with the expressiveness of C++17 (with ranges-v3) so far. The solution to Q1.9 looks like:
return (lhs + lhs).find(rhs) != std::string::npos;
which is very Pythonic.