Skip to content

Instantly share code, notes, and snippets.

@mikekwright
Created June 16, 2018 06:33
Show Gist options
  • Select an option

  • Save mikekwright/05f112c3ce8ff7dfd8e9e3d64d92f5e1 to your computer and use it in GitHub Desktop.

Select an option

Save mikekwright/05f112c3ce8ff7dfd8e9e3d64d92f5e1 to your computer and use it in GitHub Desktop.
Codingame Scala solution for Horse Racing Duals (https://www.codingame.com/training/easy/horse-racing-duals)
import math._
import scala.util._
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
object Solution extends App {
val n = readInt
val strengths = (1 to n).map(_ => readInt).sortWith(_ < _)
val diffs = strengths.sliding(2).map(l => Math.abs(l(0) - l(1)))
println(diffs.reduceLeft(_ min _))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment