How to resolve the algorithm Text processing/Max licenses in use step by step in the Julia programming language
How to resolve the algorithm Text processing/Max licenses in use step by step in the Julia programming language
Table of Contents
Problem Statement
A company currently pays a fixed sum for the use of a particular licensed software package. In determining if it has a good deal it decides to calculate its maximum use of the software from its license management log file. Assume the software's licensing daemon faithfully records a checkout event when a copy of the software starts and a checkin event when the software finishes to its log file. An example of checkout and checkin events are:
Save the 10,000 line log file from here 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 here (offsite mirror).
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Text processing/Max licenses in use step by step in the Julia programming language
The provided code is written in Julia programming language and its purpose is to find the maximum simultaneous use of licenses and the time at which it occurred.The function maximumsimultlicenses(io::IO)
takes an input/output stream io
as its argument and returns the maximum simultaneous use of licenses and the times at which it occurred.
The function starts by initializing the variables out
, maxout
, and maxtimes
to 0
, -1
, and an empty array respectively.
It then iterates through the lines of the input stream io
using the readlines
function.
For each line in the input stream, it checks if the string OUT
occurs in the line. If it does, it increments the out
variable by 1
; otherwise, it decrements the out
variable by 1
.
After processing each line, it checks if the value of out
is greater than the value of maxout
. If it is, it sets maxout
to the value of out
and empties the maxtimes
array.
It then adds the time from the current line to the maxtimes
array if the value of out
is equal to the value of maxout
.
Finally, the function returns the values of maxout
and maxtimes
.
Outside the function, the code opens the file data/mlijobs.txt
and assigns the result of calling the maximumsimultlicenses
function to the variables maxout
and maxtimes
.
It then prints the maximum simultaneous license use and the times at which it occurred.
Source code in the julia programming language
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
You may also check:How to resolve the algorithm Tree traversal step by step in the EasyLang programming language
You may also check:How to resolve the algorithm Loops/Infinite step by step in the MAD programming language
You may also check:How to resolve the algorithm Sorting algorithms/Heapsort step by step in the D programming language
You may also check:How to resolve the algorithm Fibonacci word step by step in the 11l programming language
You may also check:How to resolve the algorithm Compiler/virtual machine interpreter step by step in the Perl programming language