Text processing/Max licenses in use: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(20 intermediate revisions by 13 users not shown)
Line 16:
Mirror of log file available as a zip [https://github.com/thundergnat/rc/blob/master/resouces/mlijobs.zip here] (offsite mirror).
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">V out = 0
V max_out = -1
[String] max_times
L(job) File(‘mlijobs.txt’).read_lines()
out += I ‘OUT’ C job {1} E -1
I out > max_out
max_out = out
max_times.clear()
I out == max_out
max_times.append(job.split(‘ ’)[3])
 
print(‘Maximum simultaneous license use is #. at the following times:’.format(max_out))
print(‘ ’max_times.join("\n "))</syntaxhighlight>
 
{{out}}
<pre>
Maximum simultaneous license use is 99 at the following times:
2008/10/03_08:39:34
2008/10/03_08:40:40
</pre>
 
=={{header|Ada}}==
<langsyntaxhighlight Adalang="ada">-- licenselist.adb --
-- run under GPS 4.3-5 (Sidux/Debian)
-- process rosetta.org text_processing/3 example
Line 42 ⟶ 66:
-- to record the time of max OUT licenses
 
infile : File_Type; -- file handle
str : Unbounded_String; -- input string buffer of unknown length
outcnt, maxoutcnt : integer := 0;
infilename : string := "license.log";
Line 74 ⟶ 98:
if outcnt > maxoutcnt then
maxoutcnt := outcnt;
logtime.logtext := slice(str,15,33); -- date_time field
licenselog.clear; -- reset list for new time(s)
licenselog.append (logtime); -- put current time into list
Line 87 ⟶ 111:
trace_times;
close ( infile );
end licenselist;</langsyntaxhighlight>
Output:
<pre>
Line 96 ⟶ 120:
[2010-06-06 01:06:07] process terminated successfully (elapsed time: 00.25s)
</pre>
 
=={{header|ALGOL 68}}==
{{trans|C}} note: This specimen retains the original [http://rosettacode.org/mw/index.php?title=Text_processing%2F3&diff=87014&oldid=87011 C] coding style.
Line 101 ⟶ 126:
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny]}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of FORMATted transput}}
<langsyntaxhighlight lang="algol68">PROC report = (REF FILE file in)INT: (
 
MODE TIME = [19]CHAR;
Line 172 ⟶ 197:
FI;
exit main error: SKIP
)</langsyntaxhighlight>
Output:
<pre>
Line 182 ⟶ 207:
=={{header|APL}}==
{{works with|APL2}}{{trans|J}}
<langsyntaxhighlight lang="apl">⍝ Copy/paste file's contents into TXT (easiest), or TXT ← ⎕NREAD
I ← TXT[;8+⎕IO]
D ← TXT[;⎕IO+14+⍳19]
lu ← +\ ¯1 * 'OI' ⍳ I
mx ← (⎕IO+⍳⍴lu)/⍨lu= max ← ⌈/ lu
⎕ ← 'Maximum simultaneous license use is ' , ' at the following times:' ,⍨ ⍕max ⋄ ⎕←D[mx;]</langsyntaxhighlight>
<langsyntaxhighlight lang="apl">Maximum simultaneous license use is 99 at the following times:
2008/10/03_08:39:34
2008/10/03_08:40:40</langsyntaxhighlight>
 
=={{Headerheader|AutoHotkey}}==
{{trans|Python}}
<langsyntaxhighlight lang="autohotkey">
IfNotExist, mlijobs.txt
UrlDownloadToFile, http://rosettacode.org/mlijobs.txt, mlijobs.txt
Line 216 ⟶ 241:
 
MsgBox Maximum use is %max_out% at:`n`n%max_times%
</syntaxhighlight>
</lang>
<pre>
Maximum use is 99 at:
Line 226 ⟶ 251:
=={{header|AWK}}==
to be called with ''awk -f licenses.awk ./mlijobs.txt''
<langsyntaxhighlight lang="awk">$2=="OUT" {
count = count + 1
time = $4
Line 239 ⟶ 264:
}
$2=="IN" { count = count - 1 }
END {print "The biggest number of licenses is " maxcount " at " maxtimes " !"}</langsyntaxhighlight>
 
'''Sample output'''
Line 246 ⟶ 271:
On a 2.53MHz machine, these timings were obtained using GNU Awk 4.0.2:
 
user 0m0.015s
sys 0m0.008s
 
=={{header|BBC BASIC}}==
<langsyntaxhighlight lang="bbcbasic"> max% = 0
nlicence% = 0
file% = OPENIN("mlijobs.txt")
Line 276 ⟶ 301:
PRINT "Maximum licences checked out = " ; max%
PRINT "From " start$ " to " finish$
END</langsyntaxhighlight>
'''Output:'''
<pre>
Line 285 ⟶ 310:
=={{header|Bracmat}}==
 
<langsyntaxhighlight lang="bracmat">( 0:?N:?n
& :?Ts
& @( get$("mlijobs.txt",STR)
Line 304 ⟶ 329:
| out$(!N !Ts)
);
</syntaxhighlight>
</lang>
Output:
<pre>99 2008/10/03_08:39:34 2008/10/03_08:40:40</pre>
Line 310 ⟶ 335:
=={{header|C}}==
 
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Line 353 ⟶ 378:
if ( l_out == maxout ) {
if ( maxcount < MAX_MAXOUT ) {
strncpy(maxtime[maxcount], time, TIME_LEN);
maxcount++;
} else {
fprintf(stderr, "increase MAX_MAXOUT (now it is %u)\n", MAX_MAXOUT);
exit(1);
}
}
Line 369 ⟶ 394:
if ( in != stdin ) fclose(in);
exit(0);
}</langsyntaxhighlight>
 
Using mmap, no extra storage (think this as a search and replace):<langsyntaxhighlight lang="c">#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
Line 382 ⟶ 407:
int main()
{
struct stat s;
int fd = open("mlijobs.txt", O_RDONLY);
int cnt, max_cnt, occur;
char *buf, *ptr;
 
if (fd == -1) err(1, "open");
fstat(fd, &s);
ptr = buf = mmap(0, s.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
 
cnt = max_cnt = 0;
while(ptr - buf < s.st_size - 33) {
if (!strncmp(ptr, "License OUT", 11) && ++cnt >= max_cnt) {
if (cnt > max_cnt) {
max_cnt = cnt;
occur = 0;
}
}
/* can't sprintf time stamp: might overlap */
memmove(buf + 26 * occur, ptr + 14, 19);
sprintf(buf + 26 * occur + 19, "%6d\n", cnt);
occur++;
} else if (!strncmp(ptr, "License IN ", 11)) cnt --;
 
while (ptr < buf + s.st_size && *ptr++ != '\n');
}
 
printf(buf);
munmap(buf, s.st_size);
return close(fd);
}</lang>output<lang>2008/10/03_08:39:34 99
2008/10/03_08:40:40 99</lang>
 
=={{header|C++}}==
<lang cpp>#include <fstream>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
 
int main()
{
const char logfilename[] = "mlijobs.txt";
std::ifstream logfile(logfilename);
 
while (ptr < buf + s.st_size && *ptr++ != '\n');
if (!logfile.is_open())
{
std::cerr << "Error opening: " << logfilename << "\n";
return -1;
}
 
printf(buf);
int license = 0, max_license = 0;
munmap(buf, s.st_size);
std::vector<std::string> max_timestamp;
return close(fd);
 
}</syntaxhighlight>output<syntaxhighlight lang="text">2008/10/03_08:39:34 99
for (std::string logline; std::getline(logfile, logline); )
2008/10/03_08:40:40 99</syntaxhighlight>
{
std::string action(logline.substr(8,3));
 
if (action == "OUT")
{
if (++license >= max_license)
{
if (license > max_license)
{
max_license = license;
max_timestamp.clear();
}
max_timestamp.push_back(logline.substr(14, 19));
}
}
else if (action == "IN ")
{
--license;
}
}
 
std::cout << "License count at log end: " << license
<< "\nMaximum simultaneous license: " << max_license
<< "\nMaximum license time(s):\n";
 
std::copy(max_timestamp.begin(), max_timestamp.end(),
std::ostream_iterator<std::string>(std::cout, "\n"));
}</lang>
Output:<pre>License count at log end: 0
Maximum simultaneous licenses: 99
Maximum license time(s):
2008/10/03_08:39:34
2008/10/03_08:40:40</pre>
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang="csharp">
using System;
using System.Collections.Generic;
Line 517 ⟶ 486:
}
}
</syntaxhighlight>
</lang>
<pre>
99
Line 523 ⟶ 492:
2008/10/03_08:40:40
</pre>
 
=={{header|C++}}==
<syntaxhighlight lang="cpp">#include <fstream>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
 
int main()
{
const char logfilename[] = "mlijobs.txt";
std::ifstream logfile(logfilename);
 
if (!logfile.is_open())
{
std::cerr << "Error opening: " << logfilename << "\n";
return -1;
}
 
int license = 0, max_license = 0;
std::vector<std::string> max_timestamp;
 
for (std::string logline; std::getline(logfile, logline); )
{
std::string action(logline.substr(8,3));
 
if (action == "OUT")
{
if (++license >= max_license)
{
if (license > max_license)
{
max_license = license;
max_timestamp.clear();
}
max_timestamp.push_back(logline.substr(14, 19));
}
}
else if (action == "IN ")
{
--license;
}
}
 
std::cout << "License count at log end: " << license
<< "\nMaximum simultaneous license: " << max_license
<< "\nMaximum license time(s):\n";
 
std::copy(max_timestamp.begin(), max_timestamp.end(),
std::ostream_iterator<std::string>(std::cout, "\n"));
}</syntaxhighlight>
Output:<pre>License count at log end: 0
Maximum simultaneous licenses: 99
Maximum license time(s):
2008/10/03_08:39:34
2008/10/03_08:40:40</pre>
 
=={{header|Clojure}}==
 
<langsyntaxhighlight lang="clojure">(defn delta [entry]
(case (second (re-find #"\ (.*)\ @" entry))
"IN " -1
Line 541 ⟶ 566:
(keep-indexed #(when (= m %2) %1) in-use))]
(println "Maximum simultaneous license use is" m "at the following times:")
(map println times))</langsyntaxhighlight>
 
<pre>
Line 551 ⟶ 576:
=={{header|COBOL}}==
{{works with|OpenCOBOL}}
<langsyntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. max-licenses-in-use.
 
Line 640 ⟶ 665:
 
GOBACK
.</langsyntaxhighlight>
 
=={{header|Common Lisp}}==
Line 646 ⟶ 671:
{{libheader|CL-PPCRE}}
 
<langsyntaxhighlight lang="lisp">(defun max-licenses (&optional (logfile "mlijobs.txt"))
(with-open-file (log logfile :direction :input)
(do ((current-logs 0) (max-logs 0) (max-log-times '())
Line 663 ⟶ 688:
max-log-times (list time)))
((= current-logs max-logs)
(push time max-log-times)))))))</langsyntaxhighlight>
 
<pre>> (max-licenses)
Line 672 ⟶ 697:
 
=={{header|D}}==
<langsyntaxhighlight lang="d">void main() {
import std.stdio;
int nOut, maxOut = -1;
Line 689 ⟶ 714:
writefln("Maximum simultaneous license use is %d at" ~
" the following times:\n%( %s\n%)", maxOut, maxTimes);
}</langsyntaxhighlight>
{{out}}
<pre>Maximum simultaneous license use is 99 at the following times:
Line 699 ⟶ 724:
{{trans|Python}}
 
<langsyntaxhighlight lang="e">var out := 0
var maxOut := 0
var maxTimes := []
Line 721 ⟶ 746:
for time in maxTimes {
println(` $time`)
}</langsyntaxhighlight>
 
=={{header|Eiffel}}==
<syntaxhighlight lang="eiffel">
<lang Eiffel>
class
APPLICATION
 
create
make
 
feature
 
make
-- Max Licences used.
local
count: INTEGER
max_count: INTEGER
date: STRING
do
do
read_list
create date.make_empty
across
data as d
loop
if d.item.has_substring ("OUT") then
count := count + 1
if count > max_count then
max_count := count
date := d.item
end
end
elseif d.item.has_substring ("IN") then
count := count - 1
end
end
end
end
io.put_string ("Max Licences OUT: " + max_count.out)
io.new_line
io.put_string ("Date: " + date.substring (15, 33))
end
 
original_list: STRING = "mlijobs.txt"
 
feature {NONE}
 
read_list
-- Data read into 'data.
local
l_file: PLAIN_TEXT_FILE
do
do
create l_file.make_open_read_write (original_list)
l_file.read_stream (l_file.count)
data := l_file.last_string.split ('%N')
l_file.close
end
 
data: LIST [STRING]
 
end
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 785 ⟶ 811:
 
=={{header|Erlang}}==
<syntaxhighlight lang="erlang">
<lang Erlang>
-module( text_processing_max_licenses ).
 
Line 791 ⟶ 817:
 
out_dates_from_file( Name ) ->
{ok, Binary} = file:read_file( Name ),
Lines = binary:split( Binary, <<"\n">>, [global] ),
{_N, _Date, Dict} = lists:foldl( fun out_dates/2, {0, "", dict:new()}, Lines ),
[{X, dict:fetch(X, Dict)} || X <- dict:fetch_keys( Dict )].
 
task() ->
Line 804 ⟶ 830:
out_dates( <<>>, Acc ) -> Acc;
out_dates( Line, {N, Date, Dict} ) ->
[_License, Direction, <<"@">>, New_date | _T] = [X || X <- binary:split(Line, <<" ">>, [global]), X =/= <<>>],
New_n = out_dates_n( N, Direction ),
New_dict = out_dates_dict( N, New_n, Date, Dict ),
{New_n, New_date, New_dict}.
 
out_dates_dict( N, New_n, Date, Dict ) when N > New_n -> dict:append( N, Date, Dict );
Line 814 ⟶ 840:
out_dates_n( N, <<"OUT">> ) -> N + 1;
out_dates_n( N, <<"IN">> ) -> N - 1.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 822 ⟶ 848:
 
=={{header|Euphoria}}==
<langsyntaxhighlight lang="euphoria">function split(sequence s, integer c)
sequence out
integer first, delim
Line 876 ⟶ 902:
for i = 1 to length(maxtime) do
printf(1, "%s\n", {maxtime[i]})
end for</langsyntaxhighlight>
 
Output:
Line 887 ⟶ 913:
Placing the file in resource:work/mlijobs.txt:
 
<langsyntaxhighlight lang="factor">USING: kernel sequences splitting math accessors io.encodings.ascii
io.files math.parser io ;
IN: maxlicenses
Line 937 ⟶ 963:
number>string write
" at the following times: " print
[ print ] each ;</langsyntaxhighlight>
 
<langsyntaxhighlight lang="factor">( scratchpad ) [ find-max-licenses print-max-licenses ] time
Maximum simultaneous license use is 99 at the following times:
2008/10/03_08:39:34
2008/10/03_08:40:40
Running time: 0.16164423 seconds</langsyntaxhighlight>
 
=={{header|Forth}}==
<langsyntaxhighlight lang="forth">
20 constant date-size
create max-dates date-size 100 * allot
Line 980 ⟶ 1,006:
 
main bye
</syntaxhighlight>
</lang>
 
== {{header|Fortran}} ==
{{Works with|Fortran|90 and later}}
 
<langsyntaxhighlight lang="fortran">
PROGRAM MAX_LICENSES
IMPLICIT NONE
Line 1,023 ⟶ 1,049:
END PROGRAM MAX_LICENSES
</syntaxhighlight>
</lang>
Output
<pre>
Line 1,030 ⟶ 1,056:
2008/10/03_08:40:40
</pre>
 
 
=={{header|FreeBASIC}}==
{{trans|PureBasic}}
<syntaxhighlight lang="freebasic">Const CRLF = Chr(13) & Chr(10)
Dim As String currline, maxtime
Dim As Integer counter = 0, max = 0
Dim As String filename = "mlijobs.txt"
 
Open filename For Input As #1
While Not Eof(1)
Line Input #1, currline
If Mid(currline,9,3) = "OUT" Then
counter += 1
Else
counter -= 1
End If
If counter > max Then
max = counter
maxtime = Mid(currline,15,19)
Elseif counter = max Then
maxtime &= CRLF & Mid(currline,15,19)
End If
Wend
Print Str(max); " license(s) used at ;"; CRLF; maxtime
Close #1
Print !"\nPress ENTER to exit"
Sleep</syntaxhighlight>
{{out}}
<pre>
Igual que la entrada de PureBasic.
</pre>
 
 
=={{header|Gema}}==
Start with ''gema -f licenses.gema mlijobs.txt''
<langsyntaxhighlight lang="gema">
@set{count;0};@set{max;0}
 
Line 1,042 ⟶ 1,103:
 
report:*,*=Maximum simultaneous license use is * at\n*
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,051 ⟶ 1,112:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
"bufio"
"bytes"
"fmt"
"log"
"os"
)
 
const (
filename = "mlijobs.txt"
inoutField = 1
timeField = 3
numFields = 7
)
 
func main() {
file, err := os.Open(filename)
if err != nil {
log.Fatal(err)
}
}
defer file.Close()
var ml, out int
var mlTimes []string
in := []byte("IN")
s := bufio.NewScanner(file)
for s.Scan() {
f := bytes.Fields(s.Bytes())
if len(f) != numFields {
log.Fatal("unexpected format,", len(f), "fields.")
}
}
if bytes.Equal(f[inoutField], in) {
out--
if out < 0 {
log.Fatalf("negative license use at %s", f[timeField])
}
}
continue
}
}
out++
if out < ml {
continue
}
}
 
if out > ml {
ml = out
mlTimes = mlTimes[:0]
}
}
mlTimes = append(mlTimes, string(f[timeField]))
}
}
if err = s.Err(); err != nil {
log.Fatal(err)
}
}
 
fmt.Println("max licenses:", ml)
fmt.Println("at:")
for _, t := range mlTimes {
fmt.Println(" ", t)
}
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,120 ⟶ 1,181:
 
=={{header|Groovy}}==
<langsyntaxhighlight lang="groovy">def max = 0
def dates = []
def licenses = [:]
Line 1,149 ⟶ 1,210:
println "Maximum Licenses $max"
dates.each { date -> println " $date" }
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,157 ⟶ 1,218:
</pre>
 
== {{header|Haskell}} ==
<langsyntaxhighlight lang="haskell">
import Data.List
 
Line 1,168 ⟶ 1,229:
putStrLn $ "Maximum simultaneous license use is " ++ show mo ++ " at:"
mapM_ (putStrLn . (dt!!)) . elemIndices mo $ cio
</syntaxhighlight>
</lang>
 
=={{header|HicEst}}==
Line 1,174 ⟶ 1,235:
We open Licenses.txt in [http://www.HicEst.com/MatrixExplorer.htm MatrixExplorer mode] with 3 columns: IN/OUT, date_time, ID_nr.
This allows to adress single file elements by Licenses(row, column).
<langsyntaxhighlight HicEstlang="hicest">CHARACTER Licenses="Licenses.txt"
REAL :: counts(1), Top10(10)
 
Line 1,191 ⟶ 1,252:
ENDDO
 
END</langsyntaxhighlight>
<pre>99 2008/10/03_08:40:40
99 2008/10/03_08:39:34
Line 1,206 ⟶ 1,267:
 
The following solution works in both languages:
<langsyntaxhighlight lang="unicon">procedure main(A)
maxCount := count := 0
 
Line 1,219 ⟶ 1,280:
write("There were ",maxCount," licenses out at:")
every write("\t",!maxTime)
end</langsyntaxhighlight>
 
And a run of the program:
Line 1,229 ⟶ 1,290:
 
 
== {{header|J}} ==
<langsyntaxhighlight lang="j"> require 'files'
'I D' =: (8 ; 14+i.19) {"1 &.> <'m' fread 'licenses.txt' NB. read file as matrix, select columns
lu =: +/\ _1 ^ 'OI' i. I NB. Number of licenses in use at any given time
Line 1,236 ⟶ 1,297:
 
NB. Output results
(mx { D) ,~ 'Maximum simultaneous license use is ' , ' at the following times:' ,~ ": {. ,mx { lu</langsyntaxhighlight>
<pre>
Maximum simultaneous license use is 99 at the following times:
Line 1,245 ⟶ 1,306:
=={{header|Java}}==
{{works with|Java|1.5+}}
<langsyntaxhighlight lang="java5">import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
Line 1,274 ⟶ 1,335:
System.out.println("At time(s): "+dates);
}
}</langsyntaxhighlight>
<pre>Max licenses out: 99
At time(s): [2008/10/03_08:39:34, 2008/10/03_08:40:40]</pre>
Line 1,280 ⟶ 1,341:
=={{header|JavaScript}}==
{{works with|JScript}} for the file i/o
<langsyntaxhighlight lang="javascript">var file_system = new ActiveXObject("Scripting.FileSystemObject");
var fh = file_system.openTextFile('mlijobs.txt', 1); // 1 == open for reading
var in_use = 0, max_in_use = -1, max_in_use_at = [];
Line 1,301 ⟶ 1,362:
fh.close();
 
WScript.echo("Max licenses out: " + max_in_use + "\n " + max_in_use_at.join('\n '));</langsyntaxhighlight>
 
output:
Line 1,307 ⟶ 1,368:
2008/10/03_08:39:34
2008/10/03_08:40:40</pre>
 
=={{header|jq}}==
{{works with|jq|1.4}}
<langsyntaxhighlight lang="jq"># Input: an array of strings
def max_licenses_in_use:
# state: [in_use = 0, max_in_use = -1, max_in_use_at = [] ]
Line 1,330 ⟶ 1,392:
 
# The file is read in as a single string and so must be split at newlines:
split("\n") | max_licenses_in_use</langsyntaxhighlight>
{{Out}}
$ time /usr/local/bin/jq -M -R -r -s -f Max_licences_in_use.jq mlijobs.txt
Line 1,337 ⟶ 1,399:
2008/10/03_08:40:40
real 0m0.163s
user 0m0.154s
sys 0m0.005s
 
=={{header|K}}==
<lang K> r:m@&a=x:|/a:+\{:[x[8+!3]~"OUT";1;-1]}'m:0:"mlijobs.txt";
`0:,/"Maximum simultaneous license use is ",$x;
`0:" at the following times:\n";`0:r[;14+!19]</lang>
 
Output:
 
<lang K>Maximum simultaneous license use is 99 at the following times:
2008/10/03_08:39:34
2008/10/03_08:40:40</lang>
 
=={{header|Julia}}==
Line 1,356 ⟶ 1,407:
{{trans|Python}}
 
<langsyntaxhighlight lang="julia">function maximumsimultlicenses(io::IO)
out, maxout, maxtimes = 0, -1, String[]
for job in readlines(io)
Line 1,373 ⟶ 1,424:
let (maxout, maxtimes) = open(maximumsimultlicenses, "data/mlijobs.txt")
println("Maximum simultaneous license use is $maxout at the following times: \n - ", join(maxtimes, "\n - "))
end</langsyntaxhighlight>
 
{{out}}
Line 1,379 ⟶ 1,430:
- 2008/10/03_08:39:34
- 2008/10/03_08:40:40</pre>
 
=={{header|K}}==
<syntaxhighlight lang="k"> r:m@&a=x:|/a:+\{:[x[8+!3]~"OUT";1;-1]}'m:0:"mlijobs.txt";
`0:,/"Maximum simultaneous license use is ",$x;
`0:" at the following times:\n";`0:r[;14+!19]</syntaxhighlight>
 
Output:
 
<syntaxhighlight lang="k">Maximum simultaneous license use is 99 at the following times:
2008/10/03_08:39:34
2008/10/03_08:40:40</syntaxhighlight>
 
=={{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:
<langsyntaxhighlight lang="scala">// version 1.1.51
 
import java.io.File
Line 1,411 ⟶ 1,473:
println("Maximum simultaneous license use is $maxLicenses at the following time(s):")
println(dates.map { " $it" }.joinToString("\n"))
}</langsyntaxhighlight>
 
The file used for testing:
Line 1,431 ⟶ 1,493:
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">
filename = "mlijobs.txt"
io.input( filename )
Line 1,460 ⟶ 1,522:
for i = 1, #occurr_dates do
print( "", occurr_dates[i] )
end</langsyntaxhighlight>
Output:
<pre>Maximum licenses in use: 99
Occurrences:
2008/10/03_08:39:34
2008/10/03_08:40:40</pre>
 
=={{header|M2000 Interpreter}}==
Load.Doc load txt in any format of UTF-16LE, UTF16-BE, UTF-8, ANSI, in any line separator CRLF, CR, LF and place text in paragraphs in a document object. A document object return a string containing text (as utf16le using CRLF), but for some specific functions and statements treated as object. So changing paragraphs done with Paragraph$(a$, (m)) where m is by reference with a special syntax for this function (using without m we place order number, but m is a valid paragraph id, which always point to same paragraph until removing it).
 
In Wine 1.8 can't download.
<lang M2000 Interpreter>
 
<syntaxhighlight lang="m2000 interpreter">
Module Checkit {
Document a$, max_time$
Line 1,490 ⟶ 1,555:
}
Checkit
</syntaxhighlight>
</lang>
Output
<pre>Maximum simultaneous license use is 99 at the following times:
Line 1,497 ⟶ 1,562:
 
=={{header|M4}}==
<syntaxhighlight lang="m4">
<lang M4>
divert(-1)
define(`current',0)
Line 1,510 ⟶ 1,575:
max
undivert(1)
</syntaxhighlight>
</lang>
 
Output:
Line 1,518 ⟶ 1,583:
</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">LC = 0; LCMax = 0; Scan[
If[MemberQ[#, "OUT"], LC++;
If[LCMax < LC, LCMax = LC; LCMaxtimes = {};];
If[LCMax == LC, AppendTo[LCMaxtimes, #[[4]]]],
LC--;] &, Import["mlijobs.txt", "Table"]]
Print["The maximum number of licenses used was ", LCMax, ", at ", LCMaxtimes]</langsyntaxhighlight>
{{out}}
 
Output:
<pre>-> The maximum number of licenses used was 99, at {2008/10/03_08:39:34,2008/10/03_08:40:40}</pre>
 
=={{header|MAXScript}}==
<langsyntaxhighlight lang="maxscript">fn licencesInUse =
(
local logFile = openFile "mlijobs.txt"
Line 1,536 ⟶ 1,600:
local maxOut = -1
local maxTimes = #()
while not EOF logFile do
(
Line 1,571 ⟶ 1,635:
)
 
licencesInUse()</langsyntaxhighlight>
Output
<pre>Maximum simultaneous license use is 99 at the following times:
Line 1,579 ⟶ 1,643:
=={{header|Nim}}==
{{trans|Python}}
<langsyntaxhighlight lang="nim">import strutils
 
var
Line 1,590 ⟶ 1,654:
if curOut > maxOut:
maxOut = curOut
maxTimes = @[].setLen(0)
if curOut == maxOut:
maxTimes.add job.split[3]
 
echo "Maximum simultaneous license use is ", maxOut, " at the following times:"
for i in maxTimes: echo " ", i</langsyntaxhighlight>
 
Output:
{{out}}
<pre>Maximum simultaneous license use is 99 at the following times:
2008/10/03_08:39:34
Line 1,603 ⟶ 1,668:
=={{header|OCaml}}==
 
<langsyntaxhighlight lang="ocaml">let () =
let out = ref 0 in
let max_out = ref(-1) in
Line 1,629 ⟶ 1,694:
at the following times:\n" !max_out;
List.iter print_endline !max_times;
;;</langsyntaxhighlight>
 
=={{header|Oz}}==
{{trans|Python}}
 
<langsyntaxhighlight lang="oz">declare
fun {MaxLicenses Filename ?Times}
InUse = {NewCell 0}
Line 1,642 ⟶ 1,707:
for Job in {ReadLines Filename} do
case {List.take Job 11} of "License OUT" then
InUse := @InUse + 1
if @InUse > @MaxInUse then
MaxInUse := @InUse
MaxTimes := nil
end
if @InUse == @MaxInUse then
JobTime = {Nth {String.tokens Job & } 4}
in
MaxTimes := JobTime|@MaxTimes
end
[] "License IN " then
InUse := @InUse - 1
end
end
Line 1,682 ⟶ 1,747:
{System.showInfo
"Maximum simultaneous license use is "#MaxInUse#" at the following times:"}
{ForAll Times System.showInfo}</langsyntaxhighlight>
 
Output:
Line 1,692 ⟶ 1,757:
 
=={{header|PARI/GP}}==
<langsyntaxhighlight lang="parigp">license()={
my(v=externstr("type mlijobs.txt"),u,cur,rec,t);
for(i=1,#v,
u=Vec(v[i]);
if(#u>9 && u[9] == "O",
if(cur++>rec,
rec=cur;
t=[v[i]]
,
,
if(cur == rec,t=concat(t,[v[i]]))
)
)
,
,
cur--
)
)
);
print(apply(s->concat(vecextract(Vec(s),"15..33")), t));
rec
};</langsyntaxhighlight>
<pre>["2008/10/03_08:39:34", "2008/10/03_08:40:40"]
%1 = 99</pre>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">#!/usr/bin/perl -w
use strict;
 
Line 1,740 ⟶ 1,805:
 
print "Maximum simultaneous license use is $max_out at the following times:\n";
print " $_\n" foreach @max_times;</langsyntaxhighlight>
Example output:
<pre>Maximum simultaneous license use is 99 at the following times:
2008/10/03_08:39:34
2008/10/03_08:40:40
</pre>
 
=={{header|Perl 6}}==
Redirecting the mlijobs.txt file to STDIN:
<lang perl6>my %licenses;
 
%licenses<count max> = 0,0;
 
for $*IN.lines -> $line {
my ( $license, $date_time );
( *, $license, *, $date_time ) = split /\s+/, $line;
if $license eq 'OUT' {
%licenses<count>++;
if %licenses<count> > %licenses<max> {
%licenses<max> = %licenses<count>;
%licenses<times> = [$date_time];
}
elsif %licenses<count> == %licenses<max> {
%licenses<times>.push($date_time);
}
}
else {
if %licenses<count> == %licenses<max> {
%licenses<times>[*-1] ~= " through " ~ $date_time;
}
%licenses<count>--;
}
};
 
my $plural = %licenses<times>.elems == 1 ?? '' !! 's';
 
say "Maximum concurrent licenses in use: {%licenses<max>}, in the time period{$plural}:";
say join ",\n", %licenses<times>.list;</lang>
 
Example output:
<pre>
Maximum concurrent licenses in use: 99, in the time periods:
2008/10/03_08:39:34 through 2008/10/03_08:39:45,
2008/10/03_08:40:40 through 2008/10/03_08:40:47
</pre>
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
Modified copy of [[Max_licenses_in_use#Euphoria|Euphoria]]
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Max_licences.exw</span>
<lang Phix>constant fn = open("mlijobs.txt", "r")
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> <span style="color: #000080;font-style:italic;">-- (include version/first of next three lines only)</span>
integer maxout = 0, jobnumber
<span style="color: #008080;">include</span> <span style="color: #000000;">mlijobs</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> <span style="color: #000080;font-style:italic;">-- global constant lines, or:
sequence jobs = {}, maxtime, scanres
--assert(write_lines("mlijobs.txt",lines)!=-1) -- first run, or get from link above, then:
string inout, jobtime
--constant lines = read_lines("mlijobs.txt")</span>
object line
while 1 do
line = gets(fn)
if atom(line) then exit end if
scanres = scanf(line,"License %s @ %s for job %d\n")
if length(scanres)!=1 then
printf(1,"error scanning line: %s\n",{line})
{} = wait_key()
abort(0)
end if
{{inout,jobtime,jobnumber}} = scanres
if inout="OUT" then
jobs &= jobnumber
if length(jobs)>maxout then
maxout = length(jobs)
maxtime = {jobtime}
elsif length(jobs)=maxout then
maxtime = append(maxtime, jobtime)
end if
else
jobs[find(jobnumber,jobs)] = jobs[$]
jobs = jobs[1..$-1]
end if
end while
close(fn)
<span style="color: #004080;">integer</span> <span style="color: #000000;">maxout</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">jobnumber</span>
printf(1, "Maximum simultaneous license use is %d at the following times:\n", maxout)
<span style="color: #004080;">sequence</span> <span style="color: #000000;">jobs</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{},</span> <span style="color: #000000;">maxtime</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">scanres</span>
for i = 1 to length(maxtime) do
<span style="color: #004080;">string</span> <span style="color: #000000;">inout</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">jobtime</span>
printf(1, "%s\n", {maxtime[i]})
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">lines</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
end for</lang>
<span style="color: #004080;">string</span> <span style="color: #000000;">line</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">lines</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
<span style="color: #000000;">scanres</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">scanf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">line</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"License %s @ %s for job %d"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">scanres</span><span style="color: #0000FF;">)!=</span><span style="color: #000000;">1</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"error scanning line: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">line</span><span style="color: #0000FF;">})</span>
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">abort</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #0000FF;">{{</span><span style="color: #000000;">inout</span><span style="color: #0000FF;">,</span><span style="color: #000000;">jobtime</span><span style="color: #0000FF;">,</span><span style="color: #000000;">jobnumber</span><span style="color: #0000FF;">}}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">scanres</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">inout</span><span style="color: #0000FF;">=</span><span style="color: #008000;">"OUT"</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">jobs</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">jobnumber</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">jobs</span><span style="color: #0000FF;">)></span><span style="color: #000000;">maxout</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">maxout</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">jobs</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">maxtime</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">jobtime</span><span style="color: #0000FF;">}</span>
<span style="color: #008080;">elsif</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">jobs</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">maxout</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">maxtime</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">maxtime</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">jobtime</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">else</span>
<span style="color: #000000;">jobs</span><span style="color: #0000FF;">[</span><span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #000000;">jobnumber</span><span style="color: #0000FF;">,</span><span style="color: #000000;">jobs</span><span style="color: #0000FF;">)]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">jobs</span><span style="color: #0000FF;">[$]</span>
<span style="color: #000000;">jobs</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">jobs</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..$-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Maximum simultaneous license use is %d at the following times:\n"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">maxout</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">maxtime</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"%s\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">maxtime</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #0000FF;">?</span><span style="color: #008000;">"done"</span>
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
Line 1,828 ⟶ 1,860:
2008/10/03_08:40:40
</pre>
<small>Note the version of mlijobs.e shipped in the distribution is cropped at 20 lines (not all 457K) and will need reconstructing from the above download to get matching results</small>
 
=={{header|PHP}}==
<langsyntaxhighlight lang="php">$handle = fopen ("mlijobs.txt", "rb");
$maxcount = 0;
$count = 0;
Line 1,837 ⟶ 1,870:
$buffer = fgets($handle);
$op = trim(substr($buffer,8,3));
switch ($op){
case 'IN':
$count--;
break;
case 'OUT':
$count++;
preg_match('/([\d|\/|_|:]+)/',$buffer,$time);
if($count>$maxcount){
$maxcount = $count;
$times = Array($time[0]);
}elseif($count == $maxcount){
$times[] = $time[0];
}
}
break;
}
}
}
fclose ($handle);
Line 1,857 ⟶ 1,890:
echo $maxcount . '<br>';
for($i=0;$i<count($times);$i++){
echo $times[$i] . '<br>';
}</langsyntaxhighlight>
<pre>
99
Line 1,864 ⟶ 1,897:
2008/10/03_08:40:40
</pre>
 
=={{header|Picat}}==
<syntaxhighlight lang="picat">import util.
 
go =>
Jobs = read_file_lines("mlijobs.txt"),
Counts = asum(Jobs).to_array, % convert to array for speed
Max = max(Counts),
MaxIxs = [I : I in 1..Counts.length, Counts[I] == Max],
printf("Max number of licenses is %d.\n", Max),
printf("Interval:\n%w\n", [Jobs[J,15..33] : J in MaxIxs].join("\n")),
nl.
 
% Accumulative sum
asum(List) = Asum =>
asum(List,[],Asum).
asum([],Asum0,Asum) =>
Asum = Asum0.reverse().
asum([H|T],[],Asum) =>
C = cond(slice(H,9,11) == "OUT", 1, -1),
asum(T,[C],Asum).
asum([H|T],Asum0,Asum) =>
Asum0 = [Last|_],
C = cond(slice(H,9,11) == "OUT", 1, -1),
asum(T,[Last+C|Asum0],Asum).</syntaxhighlight>
 
{{out}}
<pre>Max number of licenses is 99.
Interval:
2008/10/03_08:39:34
2008/10/03_08:40:40</pre>
 
 
=={{header|PicoLisp}}==
{{trans|AWK}}
 
Put the following into an executable file "licenses":
<syntaxhighlight lang="picolisp">#!/usr/bin/picolisp /usr/lib/picolisp/lib.l
 
(zero Count MaxCount)
 
(in (opt)
(while (split (line) " ")
(case (pack (cadr (setq Line @)))
(IN
(dec 'Count) )
(OUT
(let Time (cadddr Line)
(cond
((> (inc 'Count) MaxCount)
(setq MaxCount Count MaxTimes Time) )
((= Count MaxCount)
(setq MaxTimes (pack MaxTimes " and " Time)) ) ) ) ) ) ) )
 
(prinl "The biggest number of licenses is " MaxCount " at " MaxTimes " !")
(bye)</syntaxhighlight>
Then it can be called as
<pre>$ ./licenses mlijobs.txt
The biggest number of licenses is 99 at 2008/10/03_08:39:34 and 2008/10/03_08:40:40 !</pre>
 
=={{header|PL/I}}==
<langsyntaxhighlight lang="pli">
text3: procedure options (main); /* 19 November 2011 */
declare line character (80) varying;
Line 1,903 ⟶ 1,995:
end;
end text3;
</syntaxhighlight>
</lang>
OUTPUT:
<pre>
Line 1,910 ⟶ 2,002:
It occurred at 2008/10/03_08:39:34 for job 1833
</pre>
 
=={{header|PicoLisp}}==
{{trans|AWK}}
 
Put the following into an executable file "licenses":
<lang PicoLisp>#!/usr/bin/picolisp /usr/lib/picolisp/lib.l
 
(zero Count MaxCount)
 
(in (opt)
(while (split (line) " ")
(case (pack (cadr (setq Line @)))
(IN
(dec 'Count) )
(OUT
(let Time (cadddr Line)
(cond
((> (inc 'Count) MaxCount)
(setq MaxCount Count MaxTimes Time) )
((= Count MaxCount)
(setq MaxTimes (pack MaxTimes " and " Time)) ) ) ) ) ) ) )
 
(prinl "The biggest number of licenses is " MaxCount " at " MaxTimes " !")
(bye)</lang>
Then it can be called as
<pre>$ ./licenses mlijobs.txt
The biggest number of licenses is 99 at 2008/10/03_08:39:34 and 2008/10/03_08:40:40 !</pre>
 
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
<lang PowerShell>
[int]$count = 0
[int]$maxCount = 0
Line 1,985 ⟶ 2,050:
EndTime = $times[1]
}
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 1,994 ⟶ 2,059:
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">OpenConsole()
 
If ReadFile(0, OpenFileRequester("Text processing/3","mlijobs.txt","All files",1))
Line 2,018 ⟶ 2,083:
 
PrintN(#CRLF$+"Press ENTER to exit"): Input()
CloseConsole()</langsyntaxhighlight>
<pre>
99 license(s) used at ;
Line 2,028 ⟶ 2,093:
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">out, max_out, max_times = 0, -1, []
for job in open('mlijobs.txt'):
out += 1 if "OUT" in job else -1
Line 2,037 ⟶ 2,102:
print("Maximum simultaneous license use is %i at the following times:" % max_out)
print(' ' + '\n '.join(max_times))</langsyntaxhighlight>
 
{{out}}
Line 2,046 ⟶ 2,111:
 
=={{header|R}}==
<syntaxhighlight lang="r">
<lang R>
# Read in data, discard useless bits
dfr <- read.table("mlijobs.txt")
Line 2,057 ⟶ 2,122:
# As a bonus, plot license use
plot(times, n.checked.out, type="s")
</syntaxhighlight>
</lang>
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">#lang racket
;;; reads a licence file on standard input
;;; returns max licences used and list of times this occurred
Line 2,086 ⟶ 2,151:
max-used)
(for-each displayln max-used-when)
</syntaxhighlight>
</lang>
Output:
<pre>Maximum licences in simultaneously used is 99 at the following times:
Line 2,094 ⟶ 2,159:
The following takes advantage of a combination of ''for/fold'' and ''(in-lines)'' (and is possible more in the Racket idiom, rather than just using ''(read-line)'' and ''(regexp-match)'':
 
<langsyntaxhighlight lang="racket">#lang racket
;;; reads a licence file on standard input
;;; returns max licences used and list of times this occurred
Line 2,116 ⟶ 2,181:
(define-values (max-used max-used-when) (with-input-from-file "mlijobs.txt" count-licences))
(printf "Maximum licences in simultaneously used is ~a at the following times:~%" max-used)
(for-each displayln max-used-when)</langsyntaxhighlight>
(Same output)
 
=={{header|Raku}}==
(formerly Perl 6)
Add some error trapping as recommended by [[Dijkstra]]. Not particularly necessary for this specific example but it doesn't hurt to be proactive.
 
 
Redirecting the mlijobs.txt file to STDIN:
<syntaxhighlight lang="raku" line>my %licenses;
 
%licenses<count max> = 0,0;
 
for $*IN.lines -> $line {
my ( $license, $date_time );
( *, $license, *, $date_time ) = split /\s+/, $line;
if $license eq 'OUT' {
%licenses<count>++;
if %licenses<count> > %licenses<max> {
%licenses<max> = %licenses<count>;
%licenses<times> = [$date_time];
}
elsif %licenses<count> == %licenses<max> {
%licenses<times>.push($date_time);
}
}
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';
 
say "Maximum concurrent licenses in use: {%licenses<max>}, in the time period{$plural}:";
say join ",\n", %licenses<times>.list;</syntaxhighlight>
 
Example output:
<pre>
Maximum concurrent licenses in use: 99, in the time periods:
2008/10/03_08:39:34 through 2008/10/03_08:39:45,
2008/10/03_08:40:40 through 2008/10/03_08:40:47
</pre>
 
=={{header|REXX}}==
===version 1===
<langsyntaxhighlight lang="rexx">/*REXX program processes instrument data as read from a time sorted data file.*/
iFID= 'LICENSE.LOG' /*the fileID of the input file. */
high=0 /*highest number of licenses (so far). */
Line 2,140 ⟶ 2,251:
do j=1 for n /*show what/when max licenses occurred.*/
say left('',20) job.j /*indent the information displayed. */
end /*j*/ /*stick a fork in it, we're all done. */</langsyntaxhighlight>
'''output''' &nbsp; when using the default input file:
<pre>
Line 2,161 ⟶ 2,272:
<br>I am sure it has worked for Regina.
Maybe this is now correct for all the WIN (and xxDOS) situations (pun intended)
<langsyntaxhighlight lang="rexx">/* REXX **************************************************************
* 19.11.2012 Walter Pachl transcribed from PL/I
* and dual-coded (for PC (Windows) and TSO)
Line 2,226 ⟶ 2,337:
store.z=line
store.0=z
Return</langsyntaxhighlight>
{{out}} on Windows
<pre>
Line 2,277 ⟶ 2,388:
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">out = 0
max_out = -1
max_times = []
Line 2,291 ⟶ 2,402:
puts "Maximum simultaneous license use is #{max_out} at the following times:"
max_times.each {|time| puts " #{time}"}</langsyntaxhighlight>
 
Example output:
Line 2,298 ⟶ 2,409:
2008/10/03_08:40:40
</pre>
 
=={{header|Run BASIC}}==
<langsyntaxhighlight lang="lb">open "c:\data\temp\logFile.txt" for input as #f
while not(eof(#f))
line input #f, a$
Line 2,311 ⟶ 2,423:
if count = maxCount then theDate$ = theDate$ + " | " + word$(a$,4," ") + " Job:";word$(a$,7," ")
wend
print maxCount;" ";theDate$</langsyntaxhighlight>
 
=={{header|Rust}}==
<syntaxhighlight lang="rust">type Timestamp = String;
 
fn compute_usage<R, S, E>(lines: R) -> Result<(u32, Vec<Timestamp>), E>
where
S: AsRef<str>,
R: Iterator<Item = Result<S, E>>,
{
let mut timestamps = Vec::new();
let mut current = 0;
let mut maximum = 0;
 
for line in lines {
let line = line?;
let line = line.as_ref();
 
if line.starts_with("License IN") {
current -= 1;
} else if line.starts_with("License OUT") {
current += 1;
 
if maximum <= current {
let date = line.split_whitespace().nth(3).unwrap().to_string();
 
if maximum < current {
maximum = current;
timestamps.clear();
}
 
timestamps.push(date);
}
}
}
 
Ok((maximum, timestamps))
}
 
fn main() -> std::io::Result<()> {
use std::io::{BufRead, BufReader};
let file = std::fs::OpenOptions::new().read(true).open("mlijobs.txt")?;
let (max, timestamps) = compute_usage(BufReader::new(file).lines())?;
println!("Maximum licenses out: {}", max);
println!("At time(s): {:?}", timestamps);
Ok(())
}</syntaxhighlight>
 
=={{header|Scala}}==
===Translated imperative version===
Can be seen running in your browser [https://scastie.scala-lang.org/a31Q3P5gQ36VcAre5i4I7g Scastie (remote JVM)].
<langsyntaxhighlight Scalalang="scala">import java.io.{BufferedReader, InputStreamReader}
import java.net.URL
 
Line 2,344 ⟶ 2,502:
println("At time(s): " + dates.mkString(", "))
 
}</langsyntaxhighlight>
 
===Smart Imperative Scala with dirty side effects===
{{Out}}Best seen running in your browser [https://scastie.scala-lang.org/2bdByPOUSICgRIMx4KJ29A Scastie (remote JVM)].
<langsyntaxhighlight Scalalang="scala">import scala.collection.mutable.ListBuffer
 
object License1 extends App {
Line 2,372 ⟶ 2,530:
println("At time(s): " + dates.mkString(", "))
 
}</langsyntaxhighlight>
===Clean coded [[functional_programming|FP]] with (tail) recursion, no side effects===
{{Out}}Best seen running in your browser [https://scastie.scala-lang.org/MvwfLtnFTcqBoNHwB4aURg Scastie (remote JVM)].
<langsyntaxhighlight Scalalang="scala">import scala.annotation.tailrec
 
object License2 extends App {
Line 2,421 ⟶ 2,579:
println("At time(s): " + dates.mkString(", "))
 
}</langsyntaxhighlight>
===Totally [[functional_programming|FP]] with foldLeft===
{{Out}}Best seen running in your browser [https://scastie.scala-lang.org/h8CgsFx8TJGtRy1B5KVSOg Scastie (remote JVM)].
<langsyntaxhighlight Scalalang="scala">object License3 extends App {
type resultTuple = (Int /*max*/, Int /*count*/, List[String] /*dates*/ )
 
Line 2,449 ⟶ 2,607:
println("At time(s): " + dates.mkString(", "))
 
}</langsyntaxhighlight>
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const proc: main is func
Line 2,484 ⟶ 2,642:
writeln(eventTime);
end for;
end func;</langsyntaxhighlight>
 
Output:
Line 2,495 ⟶ 2,653:
=={{header|Sidef}}==
{{trans|Perl}}
<langsyntaxhighlight lang="ruby">var out = 0
var max_out = -1
var max_times = []
Line 2,511 ⟶ 2,669:
 
say "Maximum simultaneous license use is #{max_out} at the following times:"
max_times.each {|t| say " #{t}" }</langsyntaxhighlight>
{{out}}
<pre>
Line 2,524 ⟶ 2,682:
{{trans|Python}}
 
<langsyntaxhighlight lang="tcl"> set out 0
set max_out -1
set max_times {}
Line 2,546 ⟶ 2,704:
foreach t $max_times {
puts " $t"
}</langsyntaxhighlight>
 
Output matches Python
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
joblog="mlijobs.txt",jobnrout=0
Line 2,569 ⟶ 2,728:
PRINT "The max. number of licences out is ", maxlicout
PRINT "at these times: ", times
</syntaxhighlight>
</lang>
Output:
<pre>
The max. number of licences out is 99
at these times: 2008/10/03_08:39:34 2008/10/03_08:40:40
</pre>
 
=={{header|TXR}}==
Working with Version 266.
<syntaxhighlight lang="txr">
@(bind *times* #H((:eql-based) nil))
@(bind *licenses-out* 0)
@(bind *maximum-licenses-out* 0)
@(collect)
License @statuses @@ @dateTimes for job @jobNumbers
@(end)
@(do (each ((status statuses)
(dateTime dateTimes)
(jobNumber jobNumbers))
(set *licenses-out*
(if (equal status "OUT")
(progn
(when (>= (+ *licenses-out* 1) *maximum-licenses-out*)
(set *maximum-licenses-out* (+ *licenses-out* 1))
(pushhash *times* *maximum-licenses-out* dateTime))
(+ *licenses-out* 1))
(+ *licenses-out* -1)))))
@(output)
Maximum # of licenses out: @{*maximum-licenses-out*}
Peak time(s): @{(reverse (gethash *times* *maximum-licenses-out*))}
@(end)
</syntaxhighlight>
Output:
<pre>
Maximum # of licenses out: 99
Peak time(s): 2008/10/03_08:39:34 2008/10/03_08:40:40
</pre>
 
Line 2,579 ⟶ 2,769:
Four functions are defined. Log lexes the log file, which can be accessed as a pre-declared constant without explicit I/O by being given as a compile-time command line parameter. Scan accumulates running totals of licenses in use. Search identifies the maxima, and format transforms the results to human readable form.
 
<syntaxhighlight lang="ursala">
<lang Ursala>
#import std
#import nat
Line 2,590 ⟶ 2,780:
#show+
 
main = format search scan log</langsyntaxhighlight>
output:
<pre>99 licenses in use at
Line 2,598 ⟶ 2,788:
 
=={{header|Vedit macro language}}==
<langsyntaxhighlight lang="vedit">
File_Open("|(PATH_ONLY)\data\mlijobs.txt", BROWSE)
 
Line 2,626 ⟶ 2,816:
 
Buf_Quit(OK)
</syntaxhighlight>
</lang>
 
Output:
Line 2,633 ⟶ 2,823:
2008/10/03_08:39:34 for job 1833
2008/10/03_08:40:40 for job 1837
</pre>
 
=={{header|Wren}}==
<syntaxhighlight lang="wren">import "io" for File
 
var lines = File.read("mlijobs.txt").replace("\r", "").split("\n")
var out = 0
var max = 0
var times = []
for (line in lines) {
if (line.startsWith("License OUT")) {
out = out + 1
if (out >= max) {
var sp = line.split(" ")
if (out > max) {
max = out
times.clear()
}
times.add(sp[3])
}
} else if (line.startsWith("License IN")) {
out = out - 1
}
}
 
System.print("The maximum licenses that were out = %(max) at time(s):")
System.print(" " + times.join("\n "))</syntaxhighlight>
 
{{out}}
<pre>
The maximum licenses that were out = 99 at time(s):
2008/10/03_08:39:34
2008/10/03_08:40:40
</pre>
 
=={{header|XPL0}}==
To run: maxlic < mlijobs.txt
<syntaxhighlight lang "XPL0">string 0; \use zero-terminated strings
char TimeMax(100, 25);
int Out, OutMax, I, Ch, ListInx;
[Out:= 0; OutMax:= 0; ListInx:= 0;
loop [for I:= 0 to 9-1 do
[Ch:= ChIn(1);
if Ch = $1A \EOF\ then quit;
];
if Ch = ^O then
[Out:= Out+1;
if Out >= OutMax then
[if Out > OutMax then ListInx:= 0;
OutMax:= Out;
for I:= 0 to 5-1 do Ch:= ChIn(1);
for I:= 0 to 19-1 do
TimeMax(ListInx, I):= ChIn(1);
TimeMax(ListInx, I):= 0;
ListInx:= ListInx+1;
];
]
else \Ch = ^I as in "IN"
Out:= Out-1;
repeat Ch:= ChIn(1) until Ch = $0A; \LF
];
Text(0, "Maximum simultaneous license use is ");
IntOut(0, OutMax);
Text(0, " at the following time(s):^m^j");
for I:= 0 to ListInx-1 do
[Text(0, @TimeMax(I,0)); CrLf(0)];
]</syntaxhighlight>
{{out}}
<pre>
Maximum simultaneous license use is 99 at the following time(s):
2008/10/03_08:39:34
2008/10/03_08:40:40
</pre>
 
Line 2,638 ⟶ 2,900:
{{trans|D}}
The referenced log file is no longer available, so, using the example log:
<langsyntaxhighlight lang="zkl">nOut,maxOut,maxTimes:=0,-1,List();
foreach job in (File("mlijobs.txt")){
_,status,_,date:=job.split();
Line 2,646 ⟶ 2,908:
}
println(("Maximum simultaneous license use is %d at"
" the following times:\n %s").fmt(maxOut,maxTimes.concat("\n")));</langsyntaxhighlight>
{{out}}
<pre>
9,476

edits