RosettaCodeData/Task/Text-processing-Max-licenses-in-use/Scala/text-processing-max-licenses-in-use-2.scala
2023-07-01 13:44:08 -04:00

25 lines
648 B
Scala

import scala.collection.mutable.ListBuffer
object License1 extends App {
val src = io.Source.fromURL("https://raw.githubusercontent.com/def-/nim-unsorted/master/mlijobs.txt")
val dates = new ListBuffer[String]
var (max, count) = (Int.MinValue, 0)
src.getLines.foreach { line =>
def date = line.split(" ")(3)
if (line.startsWith("License OUT ")) {
count += 1
if (count > max) {
max = count
dates.clear
}
if (count == max) dates += date
} else if (line.startsWith("License IN ")) count -= 1
}
println("Max licenses out: " + max)
println("At time(s): " + dates.mkString(", "))
}