aboutsummaryrefslogtreecommitdiff
path: root/src/scalevalapokalypsi/utils/utils.scala
diff options
context:
space:
mode:
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