Skip to content

Instantly share code, notes, and snippets.

@ShelbyCohen
Last active December 18, 2019 04:36
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 ShelbyCohen/209beef02f54fc3c5ac95c6edf57dccb to your computer and use it in GitHub Desktop.
Save ShelbyCohen/209beef02f54fc3c5ac95c6edf57dccb to your computer and use it in GitHub Desktop.
val blank = { entry: Map.Entry<Int, LongWrapper> ->
flowOf(max(0L, entry.value.get() -
scrabbleAvailableLetters[entry.key - 'a'.toInt()]))
}
val nBlanks = { word: String ->
flow {
emit(histoOfLetters(word)
.flatMapConcat { map -> map.entries.iterator().asFlow() }
.flatMapConcat({ blank(it) })
.reduce { a, b -> a + b })
}
}
val checkBlanks = { word: String ->
nBlanks(word).flatMapConcat { l -> flowOf(l <= 2L) }
}
val score2 = { word: String ->
flow {
emit(histoOfLetters(word)
.flatMapConcat { map -> map.entries.iterator().asFlow() }
.flatMapConcat { letterScore(it) }
.reduce { a, b -> a + b })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment