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
import kotlin.random.Random | |
class RandomWordGenerator(words: List<String>) { | |
private val graph = mutableMapOf<Char, MutableSet<Char>>() | |
private val firstLetters = mutableSetOf<Char>() | |
private val lastLetters = mutableSetOf<Char>() | |
init { | |
words.forEach { word -> | |
word.forEachIndexed { index, currentLetter -> |
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
import Foundation | |
class RandomWordGenerator { | |
private var graph: [Character: Set<Character>] = [:] | |
private var firstLetters: Set<Character> = [] | |
private var lastLetters: Set<Character> = [] | |
func insert(words: [String]) { | |
words.forEach { word in | |
guard !word.isEmpty else { return } |