Created
May 17, 2020 21:28
-
-
Save Araq/ec80ee8be65f52b09bf6eeb11a374081 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc complement(s: set[char]): string = | |
var last = '\0' | |
result = "" | |
for elem in '\0'..'\255': | |
if elem notin s: | |
if result.len == 0: | |
result.add elem | |
result.add elem | |
elif pred(elem) == last: | |
result[^1] = elem # patch last interval | |
else: | |
result.add elem | |
result.add elem | |
last = elem | |
echo result.len |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment