June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -10,4 +10,6 @@ An example of checkout and checkin events are:
|
|||
|
||||
;Task:
|
||||
Save the 10,000 line log file from [http://rosettacode.org/resources/mlijobs.txt <big> here</big>] into a local file, then write a program to scan the file extracting both the maximum licenses that were out at any time, and the time(s) at which this occurs.
|
||||
|
||||
Mirror of log file available as a zip [https://github.com/thundergnat/rc/blob/master/resouces/mlijobs.zip here] (offsite mirror).
|
||||
<br><br>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
function maximumsimultlicenses(io::IO)
|
||||
out, maxout, maxtimes = 0, -1, String[]
|
||||
for job in readlines(io)
|
||||
out += ifelse(occursin("OUT", job), 1, -1)
|
||||
if out > maxout
|
||||
maxout = out
|
||||
empty!(maxtimes)
|
||||
end
|
||||
if out == maxout
|
||||
push!(maxtimes, split(job)[4])
|
||||
end
|
||||
end
|
||||
return maxout, maxtimes
|
||||
end
|
||||
|
||||
let (maxout, maxtimes) = open(maximumsimultlicenses, "data/mlijobs.txt")
|
||||
println("Maximum simultaneous license use is $maxout at the following times: \n - ", join(maxtimes, "\n - "))
|
||||
end
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
// version 1.1.51
|
||||
|
||||
import java.io.File
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val filePath = "mlijobs.txt"
|
||||
var licenses = 0
|
||||
var maxLicenses = 0
|
||||
val dates = mutableListOf<String>()
|
||||
val f = File(filePath)
|
||||
|
||||
f.forEachLine { line ->
|
||||
if (line.startsWith("License OUT")) {
|
||||
licenses++
|
||||
if (licenses > maxLicenses) {
|
||||
maxLicenses = licenses
|
||||
dates.clear()
|
||||
dates.add(line.substring(14, 33))
|
||||
}
|
||||
else if(licenses == maxLicenses) {
|
||||
dates.add(line.substring(14, 33))
|
||||
}
|
||||
}
|
||||
else if (line.startsWith("License IN")) {
|
||||
licenses--
|
||||
}
|
||||
}
|
||||
println("Maximum simultaneous license use is $maxLicenses at the following time(s):")
|
||||
println(dates.map { " $it" }.joinToString("\n"))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue