Skip to content

Instantly share code, notes, and snippets.

@Araq
Created May 17, 2020 21:28
Show Gist options
  • Save Araq/ec80ee8be65f52b09bf6eeb11a374081 to your computer and use it in GitHub Desktop.
Save Araq/ec80ee8be65f52b09bf6eeb11a374081 to your computer and use it in GitHub Desktop.
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