summaryrefslogtreecommitdiff
path: root/content/string/lyndon.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'content/string/lyndon.cpp')
-rw-r--r--content/string/lyndon.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/content/string/lyndon.cpp b/content/string/lyndon.cpp
new file mode 100644
index 0000000..e44379b
--- /dev/null
+++ b/content/string/lyndon.cpp
@@ -0,0 +1,11 @@
+bool next(string& s, int maxLen, char mi = '0', char ma = '1') {
+ for (int i = sz(s), j = sz(s); i < maxLen; i++)
+ s.push_back(s[i % j]);
+ while(!s.empty() && s.back() == ma) s.pop_back();
+ if (s.empty()) {
+ s = mi;
+ return false;
+ } else {
+ s.back()++;
+ return true;
+}}