Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,29 @@
import java.io.{BufferedReader, InputStreamReader}
import java.net.URL
object License0 extends App {
val url = new URL("https://raw.githubusercontent.com/def-/nim-unsorted/master/mlijobs.txt")
val in = new BufferedReader(new InputStreamReader(url.openStream()))
val dates = new collection.mutable.ListBuffer[String]
var (count: Int, max: Int) = (0, Int.MinValue)
var line: String = _
while ( {line = in.readLine; line} != null) {
if (line.startsWith("License OUT ")) count += 1
if (line.startsWith("License IN ")) count -= 1 // Redundant test when "OUT"
if (count > max) { // Fruitless execution when "License IN "
max = count
val date = line.split(" ")(3)
dates.clear()
dates += date
} else if (count == max) {
val date = line.split(" ")(3)
dates += date
}
}
println("Max licenses out: " + max)
println("At time(s): " + dates.mkString(", "))
}

View file

@ -0,0 +1,25 @@
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(", "))
}

View file

@ -0,0 +1,47 @@
import scala.annotation.tailrec
object License2 extends App {
type resultTuple = (Int /*max*/, Int /*count*/, List[String] /*dates*/ )
val src = io.Source.fromURL(
"https://raw.githubusercontent.com/def-/nim-unsorted/master/mlijobs.txt")
val iter = src.getLines()
val (max, count, dates) = loop(Int.MinValue, 0, Nil)
def lineToResult(tuple: (resultTuple, String)): resultTuple = {
val ((max, count, dates), line) = tuple
def date = line.split(" ")(3)
if (line.startsWith("License OUT ")) {
if (count + 1 > max) (count + 1, count + 1, List(date))
else if (count + 1 == max) (max, max, dates :+ date)
else (max, count + 1, dates)
} else if (line.startsWith("License IN ")) tuple._1.copy(_2 = count - 1)
else tuple._1
}
@tailrec
private def loop(tuple: resultTuple): resultTuple = {
def lineToResult(tuple: (resultTuple, String)): resultTuple = {
val ((max, count, dates), line) = tuple
def date = line.split(" ")(3)
if (line.startsWith("License OUT ")) {
if (count + 1 > max) (count + 1, count + 1, List(date))
else if (count + 1 == max) (max, max, dates :+ date)
else (max, count + 1, dates)
} else if (line.startsWith("License IN ")) tuple._1.copy(_2 = count - 1)
else tuple._1
}
if (iter.hasNext)
loop(lineToResult(tuple, iter.next()))
else tuple
}
println("Max licenses out: " + max)
println("At time(s): " + dates.mkString(", "))
}

View file

@ -0,0 +1,26 @@
object License3 extends App {
type resultTuple = (Int /*max*/, Int /*count*/, List[String] /*dates*/ )
val src = io.Source.fromURL("https://raw.githubusercontent.com/def-/nim-unsorted/master/mlijobs.txt")
val (max, count, dates): resultTuple =
src.getLines().foldLeft(Int.MinValue, 0, Nil: List[String]) {
case ((max: Int, count: Int, dates: List[String]), line: String)
if line.startsWith("License OUT ") =>
def date = line.split(" ")(3)
if (count + 1 > max) (count + 1, count + 1, List(date))
else if (count + 1 == max) (max, max, dates :+ date)
else (max, count + 1, dates)
case (resultPart: resultTuple, line: String)
if line.startsWith("License IN ") =>
resultPart.copy(_2 = resultPart._2 - 1)
case (resultPart, _) => resultPart
}
println("Max licenses out: " + max)
println("At time(s): " + dates.mkString(", "))
}