Skip to content

Commit

Permalink
Run scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippus committed Sep 25, 2023
1 parent dbefdb2 commit e8bcf90
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name := "osita"
name := "osita"
organization := "nl.gn0s1s"
startYear := Some(2022)
homepage := Some(url("https://github.com/philippus/osita"))
startYear := Some(2022)
homepage := Some(url("https://github.com/philippus/osita"))
licenses += ("MPL-2.0", url("https://www.mozilla.org/MPL/2.0/"))

developers := List(
Expand All @@ -14,9 +14,9 @@ developers := List(
)

crossScalaVersions := List("2.12.18", "2.13.12")
scalaVersion := crossScalaVersions.value.last
scalaVersion := crossScalaVersions.value.last

ThisBuild / versionScheme := Some("semver-spec")
ThisBuild / versionScheme := Some("semver-spec")
ThisBuild / versionPolicyIntention := Compatibility.None

Compile / packageBin / packageOptions += Package.ManifestAttributes(
Expand All @@ -26,6 +26,6 @@ Compile / packageBin / packageOptions += Package.ManifestAttributes(
scalacOptions += "-deprecation"

libraryDependencies ++= Seq(
"org.scalameta" %% "munit" % "0.7.29" % Test,
"org.scalameta" %% "munit" % "0.7.29" % Test,
"org.scalameta" %% "munit-scalacheck" % "0.7.29" % Test
)
24 changes: 12 additions & 12 deletions src/main/scala/nl/gn0s1s/osita/Osita.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ object Osita {
}

private def simpleSubstitutionCost[A](a: A, b: A): Double =
if (a == b) 0.0d else 1.0d
if (a == b) 0.0D else 1.0D

private def findPos(c: Char): (Double, Double) = {
val t = qwertyKeyboardGrid.map(row => row.indexOf(c))
val t = qwertyKeyboardGrid.map(row => row.indexOf(c))
val column = t.max
val row = t.indexOf(column)
val row = t.indexOf(column)
// compensate for the difference between rows on a keyboard
// idea taken from https://codegolf.stackexchange.com/questions/233618/distances-between-keys-on-a-qwerty-keyboard
val factor = row match {
case 0 => 0.0d
case 1 => 0.25d
case 2 => 0.75d
case 0 => 0.0D
case 1 => 0.25D
case 2 => 0.75D
}
(column + factor, row)
}
Expand All @@ -44,9 +44,9 @@ object Osita {
osaWithSubstitutionCost(a, b)(simpleSubstitutionCost)

def osaWithSubstitutionCost[A](a: Seq[A], b: Seq[A])(substitutionCost: (A, A) => Double): Double = {
val deletionCost = 1.0d
val insertionCost = 1.0d
val transpositionCost = 1.0d
val deletionCost = 1.0D
val insertionCost = 1.0D
val transpositionCost = 1.0D

val d = Array.ofDim[Double](a.size + 1, b.size + 1)

Expand All @@ -55,16 +55,16 @@ object Osita {
for (j <- 0 to b.size)
d(0)(j) = j * insertionCost
for {
i <- 1 to a.size
j <- 1 to b.size
i <- 1 to a.size
j <- 1 to b.size
} {
d(i)(j) = min(
min(
d(i - 1)(j) + deletionCost, // deletion
d(i)(j - 1) + insertionCost
), // insertion
d(i - 1)(j - 1) + substitutionCost(a(i - 1), b(j - 1))
) // substitution
) // substitution
if (i > 1 && j > 1 && a(i - 1) == b(j - 2) && a(i - 2) == b(j - 1))
d(i)(j) = min(d(i)(j), d(i - 2)(j - 2) + transpositionCost) // transposition
}
Expand Down

0 comments on commit e8bcf90

Please sign in to comment.