Skip to content

Instantly share code, notes, and snippets.

@Judas
Last active September 9, 2025 17:01
Show Gist options
  • Save Judas/4241d6013fff338916bd6953fa7d630c to your computer and use it in GitHub Desktop.
Save Judas/4241d6013fff338916bd6953fa7d630c to your computer and use it in GitHub Desktop.
Wordle shenanigans
import java.io.File
// Data as a map of (letter position | letter) => # of occurrences
private val results: MutableMap<Pair<Int, String>, Int> = mutableMapOf()
fun main() {
// Read words from resource file
val words = File("src/main/resources/drawable-words.txt").readLines()
// Analyze each word
words.forEach { word ->
// Split by letter
word.chunked(1).forEachIndexed { position, letter ->
// Add to results
val result = results[position to letter] ?: 0
results[position to letter] = result + 1
}
}
// Split by letter position
(0..4).forEach { position ->
val letterMap = results
.filter { it.key.first == position } // Filter by letter position
.map { it.key.second to it.value } // Transform to a map of (letter => # of occurrences)
.sortedByDescending { it.second } // Sort by occurrences
.map { it.first to (it.second.toDouble() * 100 / words.size) } // Transform to %
.filter { it.second >= 5 } // Only keep values > 5% occurrences
.map { it.first to "%.2f".format(it.second) } // Format to 2-decimals string
.associate { it.first to "${it.second}%" } // Format to 2-decimals string
println("Pos. ${position + 1} : $letterMap")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment