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/a28c07d670ce6ef9b66393f9089263fe to your computer and use it in GitHub Desktop.
Save ShelbyCohen/a28c07d670ce6ef9b66393f9089263fe to your computer and use it in GitHub Desktop.
val blank = Function<Map.Entry<Int, LongWrapper>, Flux<Long>> { entry ->
Flux.just(max(0L, entry.value.get() - scrabbleAvailableLetters[entry.key - 'a'.toInt()]))
}
val nBlanks = Function<String, Flux<Long>> { word ->
Flux.from(histoOfLetters.apply(word)
.flatMap<Map.Entry<Int, LongWrapper>> { map ->
Flux.fromIterable<Map.Entry<Int, LongWrapper>>(
Iterable { map.entries.iterator() }) }
.flatMap(blank)
.reduce { a, b -> sum(a, b) })
}
val checkBlanks = Function<String, Flux<Boolean>> { word ->
nBlanks.apply(word)
.flatMap { l -> Flux.just(l <= 2L) }
}
val score2 = Function<String, Flux<Int>> { word ->
Flux.from(histoOfLetters.apply(word)
.flatMap<Map.Entry<Int, LongWrapper>> { map ->
Flux.fromIterable<Map.Entry<Int, LongWrapper>>(
Iterable { map.entries.iterator() }) }
.flatMap(letterScore)
.reduce { a, b -> Integer.sum(a, b) })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment