Created
June 25, 2021 00:44
-
-
Save johnblanco/797cb0a42bf67811e07047f0f4b7068d 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
//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