Skip to content

Instantly share code, notes, and snippets.

@johnblanco
Created June 25, 2021 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnblanco/797cb0a42bf67811e07047f0f4b7068d to your computer and use it in GitHub Desktop.
Save johnblanco/797cb0a42bf67811e07047f0f4b7068d to your computer and use it in GitHub Desktop.
//https://old.reddit.com/r/dailyprogrammer/comments/o4uyzl/20210621_challenge_395_easy_nonogram_row/
class Nonogram {
fun nonogramrow(binaryArray: List<Int>): List<Int> {
var currentLength = 0
var building = false
val result = mutableListOf<Int>()
for (elem in binaryArray) {
if (elem == 1) {
currentLength++
building = true
} else if (elem == 0 && building) {
result.add(currentLength)
currentLength = 0
building = false
}
}
if(building){
result.add(currentLength)
}
return result
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment