Skip to content

Instantly share code, notes, and snippets.

@windmaomao
Last active September 5, 2020 14:24
Show Gist options
  • Save windmaomao/7c00aad20306f1cf5d610c4cf3aa18cc to your computer and use it in GitHub Desktop.
Save windmaomao/7c00aad20306f1cf5d610c4cf3aa18cc to your computer and use it in GitHub Desktop.
Generator to the rescue
fun part2s(s: String): Int {
val all = s.asSequence()
scan(0) { acc, c -> acc + charValue(c) }
return all.indexOf(-1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment