Text processing/Max licenses in use: Difference between revisions

Content added Content deleted
(Added Kotlin)
Line 1,348: Line 1,348:
2008/10/03_08:39:34
2008/10/03_08:39:34
2008/10/03_08:40:40</lang>
2008/10/03_08:40:40</lang>

=={{header|Kotlin}}==
The link for downloading the file, mlijobs.txt, is currently broken so I've created a small file myself to test the program:
<lang scala>// 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>()
var 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"))
}</lang>

The file used for testing:
<pre>
License OUT @ 2008/10/03_23:51:05 for job 4974
License OUT @ 2008/10/03_23:57:00 for job 4975
License IN @ 2008/10/04_00:00:06 for job 4975
License OUT @ 2008/10/04_00:07:19 for job 4976
License IN @ 2008/10/04_00:11:32 for job 4976
License IN @ 2008/10/04_00:18:22 for job 4974
</pre>

{{out}}
<pre>
Maximum simultaneous license use is 2 at the following time(s):
2008/10/03_23:57:00
2008/10/04_00:07:19
</pre>


=={{header|Lua}}==
=={{header|Lua}}==