diff --git a/.idea/misc.xml b/.idea/misc.xml index 4975f0d..b257193 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -7,4 +7,9 @@ + + + \ No newline at end of file diff --git a/src/main/kotlin/com/github/borgoat/markovaldo/MarkovChain.kt b/src/main/kotlin/com/github/borgoat/markovaldo/MarkovChain.kt index 62f95e8..32a7fa1 100644 --- a/src/main/kotlin/com/github/borgoat/markovaldo/MarkovChain.kt +++ b/src/main/kotlin/com/github/borgoat/markovaldo/MarkovChain.kt @@ -28,12 +28,10 @@ class MarkovChain( val tokenState = ArrayDeque() tokens.forEach { if (tokenState.isNotEmpty()) { - val innerMap = probs.getOrPut(tokenState) { mutableMapOf() } + val innerMap = probs.getOrPut(tokenState.takeLast(order)) { mutableMapOf() } innerMap.getOrPut(it) { AtomicLong(0) }.incrementAndGet() } - tokenState.add(it) - if (tokenState.count() > order) tokenState.removeFirst() } }