Text processing/Max licenses in use: Difference between revisions
m
syntax highlighting fixup automation
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
Line 20:
{{trans|Python}}
<
V max_out = -1
[String] max_times
Line 32:
print(‘Maximum simultaneous license use is #. at the following times:’.format(max_out))
print(‘ ’max_times.join("\n "))</
{{out}}
Line 42:
=={{header|Ada}}==
<
-- run under GPS 4.3-5 (Sidux/Debian)
-- process rosetta.org text_processing/3 example
Line 111:
trace_times;
close ( infile );
end licenselist;</
Output:
<pre>
Line 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}}
<
MODE TIME = [19]CHAR;
Line 197:
FI;
exit main error: SKIP
)</
Output:
<pre>
Line 207:
=={{header|APL}}==
{{works with|APL2}}{{trans|J}}
<
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;]</
<
2008/10/03_08:39:34
2008/10/03_08:40:40</
=={{header|AutoHotkey}}==
{{trans|Python}}
<
IfNotExist, mlijobs.txt
UrlDownloadToFile, http://rosettacode.org/mlijobs.txt, mlijobs.txt
Line 241:
MsgBox Maximum use is %max_out% at:`n`n%max_times%
</syntaxhighlight>
<pre>
Maximum use is 99 at:
Line 251:
=={{header|AWK}}==
to be called with ''awk -f licenses.awk ./mlijobs.txt''
<
count = count + 1
time = $4
Line 264:
}
$2=="IN" { count = count - 1 }
END {print "The biggest number of licenses is " maxcount " at " maxtimes " !"}</
'''Sample output'''
Line 275:
=={{header|BBC BASIC}}==
<
nlicence% = 0
file% = OPENIN("mlijobs.txt")
Line 301:
PRINT "Maximum licences checked out = " ; max%
PRINT "From " start$ " to " finish$
END</
'''Output:'''
<pre>
Line 310:
=={{header|Bracmat}}==
<
& :?Ts
& @( get$("mlijobs.txt",STR)
Line 329:
| out$(!N !Ts)
);
</syntaxhighlight>
Output:
<pre>99 2008/10/03_08:39:34 2008/10/03_08:40:40</pre>
Line 335:
=={{header|C}}==
<
#include <stdlib.h>
#include <string.h>
Line 394:
if ( in != stdin ) fclose(in);
exit(0);
}</
Using mmap, no extra storage (think this as a search and replace):<
#include <unistd.h>
#include <fcntl.h>
Line 435:
munmap(buf, s.st_size);
return close(fd);
}</
2008/10/03_08:40:40 99</
=={{header|C sharp|C#}}==
<
using System;
using System.Collections.Generic;
Line 486:
}
}
</syntaxhighlight>
<pre>
99
Line 494:
=={{header|C++}}==
<
#include <iostream>
#include <iterator>
Line 542:
std::copy(max_timestamp.begin(), max_timestamp.end(),
std::ostream_iterator<std::string>(std::cout, "\n"));
}</
Output:<pre>License count at log end: 0
Maximum simultaneous licenses: 99
Line 551:
=={{header|Clojure}}==
<
(case (second (re-find #"\ (.*)\ @" entry))
"IN " -1
Line 566:
(keep-indexed #(when (= m %2) %1) in-use))]
(println "Maximum simultaneous license use is" m "at the following times:")
(map println times))</
<pre>
Line 576:
=={{header|COBOL}}==
{{works with|OpenCOBOL}}
<
PROGRAM-ID. max-licenses-in-use.
Line 665:
GOBACK
.</
=={{header|Common Lisp}}==
Line 671:
{{libheader|CL-PPCRE}}
<
(with-open-file (log logfile :direction :input)
(do ((current-logs 0) (max-logs 0) (max-log-times '())
Line 688:
max-log-times (list time)))
((= current-logs max-logs)
(push time max-log-times)))))))</
<pre>> (max-licenses)
Line 697:
=={{header|D}}==
<
import std.stdio;
int nOut, maxOut = -1;
Line 714:
writefln("Maximum simultaneous license use is %d at" ~
" the following times:\n%( %s\n%)", maxOut, maxTimes);
}</
{{out}}
<pre>Maximum simultaneous license use is 99 at the following times:
Line 724:
{{trans|Python}}
<
var maxOut := 0
var maxTimes := []
Line 746:
for time in maxTimes {
println(` $time`)
}</
=={{header|Eiffel}}==
<syntaxhighlight lang="eiffel">
class
APPLICATION
Line 803:
end
</syntaxhighlight>
{{out}}
<pre>
Line 811:
=={{header|Erlang}}==
<syntaxhighlight lang="erlang">
-module( text_processing_max_licenses ).
Line 840:
out_dates_n( N, <<"OUT">> ) -> N + 1;
out_dates_n( N, <<"IN">> ) -> N - 1.
</syntaxhighlight>
{{out}}
<pre>
Line 848:
=={{header|Euphoria}}==
<
sequence out
integer first, delim
Line 902:
for i = 1 to length(maxtime) do
printf(1, "%s\n", {maxtime[i]})
end for</
Output:
Line 913:
Placing the file in resource:work/mlijobs.txt:
<
io.files math.parser io ;
IN: maxlicenses
Line 963:
number>string write
" at the following times: " print
[ print ] each ;</
<
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</
=={{header|Forth}}==
<
20 constant date-size
create max-dates date-size 100 * allot
Line 1,006:
main bye
</syntaxhighlight>
=={{header|Fortran}}==
{{Works with|Fortran|90 and later}}
<
PROGRAM MAX_LICENSES
IMPLICIT NONE
Line 1,049:
END PROGRAM MAX_LICENSES
</syntaxhighlight>
Output
<pre>
Line 1,060:
=={{header|FreeBASIC}}==
{{trans|PureBasic}}
<
Dim As String currline, maxtime
Dim As Integer counter = 0, max = 0
Line 1,084:
Close #1
Print !"\nPress ENTER to exit"
Sleep</
{{out}}
<pre>
Line 1,093:
=={{header|Gema}}==
Start with ''gema -f licenses.gema mlijobs.txt''
<
@set{count;0};@set{max;0}
Line 1,103:
report:*,*=Maximum simultaneous license use is * at\n*
</syntaxhighlight>
Output:
<pre>
Line 1,112:
=={{header|Go}}==
<
import (
Line 1,171:
fmt.Println(" ", t)
}
}</
{{out}}
<pre>
Line 1,181:
=={{header|Groovy}}==
<
def dates = []
def licenses = [:]
Line 1,210:
println "Maximum Licenses $max"
dates.each { date -> println " $date" }
</syntaxhighlight>
Output:
<pre>
Line 1,219:
=={{header|Haskell}}==
<
import Data.List
Line 1,229:
putStrLn $ "Maximum simultaneous license use is " ++ show mo ++ " at:"
mapM_ (putStrLn . (dt!!)) . elemIndices mo $ cio
</syntaxhighlight>
=={{header|HicEst}}==
Line 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).
<
REAL :: counts(1), Top10(10)
Line 1,252:
ENDDO
END</
<pre>99 2008/10/03_08:40:40
99 2008/10/03_08:39:34
Line 1,267:
The following solution works in both languages:
<
maxCount := count := 0
Line 1,280:
write("There were ",maxCount," licenses out at:")
every write("\t",!maxTime)
end</
And a run of the program:
Line 1,291:
=={{header|J}}==
<
'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,297:
NB. Output results
(mx { D) ,~ 'Maximum simultaneous license use is ' , ' at the following times:' ,~ ": {. ,mx { lu</
<pre>
Maximum simultaneous license use is 99 at the following times:
Line 1,306:
=={{header|Java}}==
{{works with|Java|1.5+}}
<
import java.io.FileNotFoundException;
import java.io.FileReader;
Line 1,335:
System.out.println("At time(s): "+dates);
}
}</
<pre>Max licenses out: 99
At time(s): [2008/10/03_08:39:34, 2008/10/03_08:40:40]</pre>
Line 1,341:
=={{header|JavaScript}}==
{{works with|JScript}} for the file i/o
<
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,362:
fh.close();
WScript.echo("Max licenses out: " + max_in_use + "\n " + max_in_use_at.join('\n '));</
output:
Line 1,371:
=={{header|jq}}==
{{works with|jq|1.4}}
<
def max_licenses_in_use:
# state: [in_use = 0, max_in_use = -1, max_in_use_at = [] ]
Line 1,392:
# The file is read in as a single string and so must be split at newlines:
split("\n") | max_licenses_in_use</
{{Out}}
$ time /usr/local/bin/jq -M -R -r -s -f Max_licences_in_use.jq mlijobs.txt
Line 1,407:
{{trans|Python}}
<
out, maxout, maxtimes = 0, -1, String[]
for job in readlines(io)
Line 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</
{{out}}
Line 1,432:
=={{header|K}}==
<
`0:,/"Maximum simultaneous license use is ",$x;
`0:" at the following times:\n";`0:r[;14+!19]</
Output:
<
2008/10/03_08:39:34
2008/10/03_08:40:40</
=={{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:
<
import java.io.File
Line 1,473:
println("Maximum simultaneous license use is $maxLicenses at the following time(s):")
println(dates.map { " $it" }.joinToString("\n"))
}</
The file used for testing:
Line 1,493:
=={{header|Lua}}==
<
filename = "mlijobs.txt"
io.input( filename )
Line 1,522:
for i = 1, #occurr_dates do
print( "", occurr_dates[i] )
end</
Output:
<pre>Maximum licenses in use: 99
Line 1,534:
In Wine 1.8 can't download.
<syntaxhighlight lang="m2000 interpreter">
Module Checkit {
Document a$, max_time$
Line 1,555:
}
Checkit
</syntaxhighlight>
Output
<pre>Maximum simultaneous license use is 99 at the following times:
Line 1,562:
=={{header|M4}}==
<syntaxhighlight lang="m4">
divert(-1)
define(`current',0)
Line 1,575:
max
undivert(1)
</syntaxhighlight>
Output:
Line 1,584:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
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]</
{{out}}
<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}}==
<
(
local logFile = openFile "mlijobs.txt"
Line 1,635:
)
licencesInUse()</
Output
<pre>Maximum simultaneous license use is 99 at the following times:
Line 1,643:
=={{header|Nim}}==
{{trans|Python}}
<
var
Line 1,659:
echo "Maximum simultaneous license use is ", maxOut, " at the following times:"
for i in maxTimes: echo " ", i</
{{out}}
Line 1,668:
=={{header|OCaml}}==
<
let out = ref 0 in
let max_out = ref(-1) in
Line 1,694:
at the following times:\n" !max_out;
List.iter print_endline !max_times;
;;</
=={{header|Oz}}==
{{trans|Python}}
<
fun {MaxLicenses Filename ?Times}
InUse = {NewCell 0}
Line 1,747:
{System.showInfo
"Maximum simultaneous license use is "#MaxInUse#" at the following times:"}
{ForAll Times System.showInfo}</
Output:
Line 1,757:
=={{header|PARI/GP}}==
<
my(v=externstr("type mlijobs.txt"),u,cur,rec,t);
for(i=1,#v,
Line 1,774:
print(apply(s->concat(vecextract(Vec(s),"15..33")), t));
rec
};</
<pre>["2008/10/03_08:39:34", "2008/10/03_08:40:40"]
%1 = 99</pre>
=={{header|Perl}}==
<
use strict;
Line 1,805:
print "Maximum simultaneous license use is $max_out at the following times:\n";
print " $_\n" foreach @max_times;</
Example output:
<pre>Maximum simultaneous license use is 99 at the following times:
Line 1,813:
=={{header|Phix}}==
<!--<
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Max_licences.exw</span>
<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>
Line 1,853:
<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>
<!--</
{{out}}
<pre>
Line 1,863:
=={{header|PHP}}==
<
$maxcount = 0;
$count = 0;
Line 1,891:
for($i=0;$i<count($times);$i++){
echo $times[$i] . '<br>';
}</
<pre>
99
Line 1,899:
=={{header|Picat}}==
<
go =>
Line 1,921:
Asum0 = [Last|_],
C = cond(slice(H,9,11) == "OUT", 1, -1),
asum(T,[Last+C|Asum0],Asum).</
{{out}}
Line 1,934:
Put the following into an executable file "licenses":
<
(zero Count MaxCount)
Line 1,952:
(prinl "The biggest number of licenses is " MaxCount " at " MaxTimes " !")
(bye)</
Then it can be called as
<pre>$ ./licenses mlijobs.txt
Line 1,958:
=={{header|PL/I}}==
<
text3: procedure options (main); /* 19 November 2011 */
declare line character (80) varying;
Line 1,995:
end;
end text3;
</syntaxhighlight>
OUTPUT:
<pre>
Line 2,004:
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
[int]$count = 0
[int]$maxCount = 0
Line 2,050:
EndTime = $times[1]
}
</syntaxhighlight>
{{Out}}
<pre>
Line 2,059:
=={{header|PureBasic}}==
<
If ReadFile(0, OpenFileRequester("Text processing/3","mlijobs.txt","All files",1))
Line 2,083:
PrintN(#CRLF$+"Press ENTER to exit"): Input()
CloseConsole()</
<pre>
99 license(s) used at ;
Line 2,093:
=={{header|Python}}==
<
for job in open('mlijobs.txt'):
out += 1 if "OUT" in job else -1
Line 2,102:
print("Maximum simultaneous license use is %i at the following times:" % max_out)
print(' ' + '\n '.join(max_times))</
{{out}}
Line 2,111:
=={{header|R}}==
<syntaxhighlight lang="r">
# Read in data, discard useless bits
dfr <- read.table("mlijobs.txt")
Line 2,122:
# As a bonus, plot license use
plot(times, n.checked.out, type="s")
</syntaxhighlight>
=={{header|Racket}}==
<
;;; reads a licence file on standard input
;;; returns max licences used and list of times this occurred
Line 2,151:
max-used)
(for-each displayln max-used-when)
</syntaxhighlight>
Output:
<pre>Maximum licences in simultaneously used is 99 at the following times:
Line 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)'':
<
;;; reads a licence file on standard input
;;; returns max licences used and list of times this occurred
Line 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)</
(Same output)
Line 2,190:
Redirecting the mlijobs.txt file to STDIN:
<syntaxhighlight lang="raku"
%licenses<count max> = 0,0;
Line 2,221:
say "Maximum concurrent licenses in use: {%licenses<max>}, in the time period{$plural}:";
say join ",\n", %licenses<times>.list;</
Example output:
Line 2,232:
=={{header|REXX}}==
===version 1===
<
iFID= 'LICENSE.LOG' /*the fileID of the input file. */
high=0 /*highest number of licenses (so far). */
Line 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. */</
'''output''' when using the default input file:
<pre>
Line 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)
<
* 19.11.2012 Walter Pachl transcribed from PL/I
* and dual-coded (for PC (Windows) and TSO)
Line 2,337:
store.z=line
store.0=z
Return</
{{out}} on Windows
<pre>
Line 2,388:
=={{header|Ruby}}==
<
max_out = -1
max_times = []
Line 2,402:
puts "Maximum simultaneous license use is #{max_out} at the following times:"
max_times.each {|time| puts " #{time}"}</
Example output:
Line 2,411:
=={{header|Run BASIC}}==
<
while not(eof(#f))
line input #f, a$
Line 2,423:
if count = maxCount then theDate$ = theDate$ + " | " + word$(a$,4," ") + " Job:";word$(a$,7," ")
wend
print maxCount;" ";theDate$</
=={{header|Rust}}==
<
fn compute_usage<R, S, E>(lines: R) -> Result<(u32, Vec<Timestamp>), E>
Line 2,469:
println!("At time(s): {:?}", timestamps);
Ok(())
}</
=={{header|Scala}}==
===Translated imperative version===
Can be seen running in your browser [https://scastie.scala-lang.org/a31Q3P5gQ36VcAre5i4I7g Scastie (remote JVM)].
<
import java.net.URL
Line 2,502:
println("At time(s): " + dates.mkString(", "))
}</
===Smart Imperative Scala with dirty side effects===
{{Out}}Best seen running in your browser [https://scastie.scala-lang.org/2bdByPOUSICgRIMx4KJ29A Scastie (remote JVM)].
<
object License1 extends App {
Line 2,530:
println("At time(s): " + dates.mkString(", "))
}</
===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)].
<
object License2 extends App {
Line 2,579:
println("At time(s): " + dates.mkString(", "))
}</
===Totally [[functional_programming|FP]] with foldLeft===
{{Out}}Best seen running in your browser [https://scastie.scala-lang.org/h8CgsFx8TJGtRy1B5KVSOg Scastie (remote JVM)].
<
type resultTuple = (Int /*max*/, Int /*count*/, List[String] /*dates*/ )
Line 2,607:
println("At time(s): " + dates.mkString(", "))
}</
=={{header|Seed7}}==
<
const proc: main is func
Line 2,642:
writeln(eventTime);
end for;
end func;</
Output:
Line 2,653:
=={{header|Sidef}}==
{{trans|Perl}}
<
var max_out = -1
var max_times = []
Line 2,669:
say "Maximum simultaneous license use is #{max_out} at the following times:"
max_times.each {|t| say " #{t}" }</
{{out}}
<pre>
Line 2,682:
{{trans|Python}}
<
set max_out -1
set max_times {}
Line 2,704:
foreach t $max_times {
puts " $t"
}</
Output matches Python
=={{header|TUSCRIPT}}==
<
$$ MODE TUSCRIPT
joblog="mlijobs.txt",jobnrout=0
Line 2,728:
PRINT "The max. number of licences out is ", maxlicout
PRINT "at these times: ", times
</syntaxhighlight>
Output:
<pre>
Line 2,737:
=={{header|TXR}}==
Working with Version 266.
<syntaxhighlight lang="txr">
@(bind *times* #H((:eql-based) nil))
@(bind *licenses-out* 0)
Line 2,759:
Peak time(s): @{(reverse (gethash *times* *maximum-licenses-out*))}
@(end)
</syntaxhighlight>
Output:
<pre>
Line 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">
#import std
#import nat
Line 2,780:
#show+
main = format search scan log</
output:
<pre>99 licenses in use at
Line 2,788:
=={{header|Vedit macro language}}==
<
File_Open("|(PATH_ONLY)\data\mlijobs.txt", BROWSE)
Line 2,816:
Buf_Quit(OK)
</syntaxhighlight>
Output:
Line 2,826:
=={{header|Wren}}==
<
var lines = File.read("mlijobs.txt").replace("\r", "").split("\n")
Line 2,849:
System.print("The maximum licenses that were out = %(max) at time(s):")
System.print(" " + times.join("\n "))</
{{out}}
Line 2,861:
{{trans|D}}
The referenced log file is no longer available, so, using the example log:
<
foreach job in (File("mlijobs.txt")){
_,status,_,date:=job.split();
Line 2,869:
}
println(("Maximum simultaneous license use is %d at"
" the following times:\n %s").fmt(maxOut,maxTimes.concat("\n")));</
{{out}}
<pre>
|