aboutsummaryrefslogtreecommitdiff
path: root/src/scalevalapokalypsi/utils/utils.scala
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-27 12:29:43 +0200
committerJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-27 12:29:43 +0200
commit98407b35ff477f372baa92bf582b90a961d4ad16 (patch)
treebb58925090075d1e9e30dd1593547db2cbe03bb6 /src/scalevalapokalypsi/utils/utils.scala
parent38900e0b291d5e0f59afaaa239cd237f733b6588 (diff)
downloadscalevalapokalypsi-98407b35ff477f372baa92bf582b90a961d4ad16.tar.gz
scalevalapokalypsi-98407b35ff477f372baa92bf582b90a961d4ad16.zip
Added part of story & improved singing with multiple verses & hemingway distance
Diffstat (limited to 'src/scalevalapokalypsi/utils/utils.scala')
-rw-r--r--src/scalevalapokalypsi/utils/utils.scala7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/scalevalapokalypsi/utils/utils.scala b/src/scalevalapokalypsi/utils/utils.scala
index 54d407b..4be0687 100644
--- a/src/scalevalapokalypsi/utils/utils.scala
+++ b/src/scalevalapokalypsi/utils/utils.scala
@@ -5,6 +5,7 @@ import java.nio.charset.StandardCharsets
import scala.util.Try
import scalevalapokalypsi.constants.*
import scala.io.StdIn.readLine
+import scala.math.{min,abs}
/** Converts this string to an array of bytes (probably for transmission).
*
@@ -24,6 +25,12 @@ def byteArrayToString(bytes: Array[Byte]): Option[String] =
Try(String(bytes, StandardCharsets.UTF_8))
.toOption
+/** Incredibly LÖRS string metric algorithm.
+ * LÖRSiness explained by there being 6 hours left to the DL
+ */
+def hammingDistance(s1: String, s2: String): Float =
+ s1.zip(s2).map(p => p(0) != p(1)).filter((b: Boolean) => b).length
+
/** Reads n characters from the given InputStream blockingly.
*
* @param input the InputStream to read from