YAPC::EU 2018 Glasgow Update!

This commit is contained in:
Ingy döt Net 2018-08-17 15:15:24 +01:00
parent 22f33d4004
commit 4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions

View file

@ -15,12 +15,15 @@ for $*IN.lines -> $line {
%licenses<times>.push($date_time);
}
}
else {
elsif $license eq 'IN' {
if %licenses<count> == %licenses<max> {
%licenses<times>[*-1] ~= " through " ~ $date_time;
}
%licenses<count>--;
}
else {
# Not a licence OUT or IN event, do nothing
}
};
my $plural = %licenses<times>.elems == 1 ?? '' !! 's';

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(", "))
}

View file

@ -1,17 +1,17 @@
var out = 0;
var max_out = -1;
var max_times = [];
var out = 0
var max_out = -1
var max_times = []
ARGF.each { |line|
out += (line ~~ /OUT/ ? 1 : -1);
out > max_out && (
max_out = out;
max_times = [];
);
out == max_out && (
max_times << line.split(' ')[3];
);
out += (line ~~ /OUT/ ? 1 : -1)
if (out > max_out) {
max_out = out
max_times = []
}
if (out == max_out) {
max_times << line.split(' ')[3]
}
}
say "Maximum simultaneous license use is #{max_out} at the following times:";
max_times.each {|t| " #{t}".say };
say "Maximum simultaneous license use is #{max_out} at the following times:"
max_times.each {|t| say " #{t}" }