Text processing/Max licenses in use: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
|||
Line 96: | Line 96: | ||
[2010-06-06 01:06:07] process terminated successfully (elapsed time: 00.25s) |
[2010-06-06 01:06:07] process terminated successfully (elapsed time: 00.25s) |
||
</pre> |
</pre> |
||
=={{header|ALGOL 68}}== |
=={{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. |
{{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 192: | Line 193: | ||
2008/10/03_08:40:40</lang> |
2008/10/03_08:40:40</lang> |
||
=={{ |
=={{header|AutoHotkey}}== |
||
{{trans|Python}} |
{{trans|Python}} |
||
<lang autohotkey> |
<lang autohotkey> |
||
Line 412: | Line 413: | ||
}</lang>output<lang>2008/10/03_08:39:34 99 |
}</lang>output<lang>2008/10/03_08:39:34 99 |
||
2008/10/03_08:40:40 99</lang> |
2008/10/03_08:40:40 99</lang> |
||
=={{header|C sharp|C#}}== |
|||
<lang csharp> |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.IO; |
|||
namespace TextProc3 |
|||
{ |
|||
class Program |
|||
{ |
|||
static void Main(string[] args) |
|||
{ |
|||
string line; |
|||
int count = 0, maxcount = 0; |
|||
List<string> times = new List<string>(); |
|||
System.IO.StreamReader file = new StreamReader("mlijobs.txt"); |
|||
while ((line = file.ReadLine()) != null) |
|||
{ |
|||
string[] lineelements = line.Split(' '); |
|||
switch (lineelements[1]) |
|||
{ |
|||
case "IN": |
|||
count--; |
|||
break; |
|||
case "OUT": |
|||
count++; |
|||
if (count > maxcount) |
|||
{ |
|||
maxcount = count; |
|||
times.Clear(); |
|||
times.Add(lineelements[3]); |
|||
}else if(count == maxcount){ |
|||
times.Add(lineelements[3]); |
|||
} |
|||
break; |
|||
} |
|||
} |
|||
file.Close(); |
|||
Console.WriteLine(maxcount); |
|||
foreach (string time in times) |
|||
{ |
|||
Console.WriteLine(time); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
</lang> |
|||
<pre> |
|||
99 |
|||
2008/10/03_08:39:34 |
|||
2008/10/03_08:40:40 |
|||
</pre> |
|||
=={{header|C++}}== |
=={{header|C++}}== |
||
Line 468: | Line 524: | ||
2008/10/03_08:39:34 |
2008/10/03_08:39:34 |
||
2008/10/03_08:40:40</pre> |
2008/10/03_08:40:40</pre> |
||
=={{header|C sharp|C#}}== |
|||
<lang csharp> |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.IO; |
|||
namespace TextProc3 |
|||
{ |
|||
class Program |
|||
{ |
|||
static void Main(string[] args) |
|||
{ |
|||
string line; |
|||
int count = 0, maxcount = 0; |
|||
List<string> times = new List<string>(); |
|||
System.IO.StreamReader file = new StreamReader("mlijobs.txt"); |
|||
while ((line = file.ReadLine()) != null) |
|||
{ |
|||
string[] lineelements = line.Split(' '); |
|||
switch (lineelements[1]) |
|||
{ |
|||
case "IN": |
|||
count--; |
|||
break; |
|||
case "OUT": |
|||
count++; |
|||
if (count > maxcount) |
|||
{ |
|||
maxcount = count; |
|||
times.Clear(); |
|||
times.Add(lineelements[3]); |
|||
}else if(count == maxcount){ |
|||
times.Add(lineelements[3]); |
|||
} |
|||
break; |
|||
} |
|||
} |
|||
file.Close(); |
|||
Console.WriteLine(maxcount); |
|||
foreach (string time in times) |
|||
{ |
|||
Console.WriteLine(time); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
</lang> |
|||
<pre> |
|||
99 |
|||
2008/10/03_08:39:34 |
|||
2008/10/03_08:40:40 |
|||
</pre> |
|||
=={{header|Clojure}}== |
=={{header|Clojure}}== |
||
Line 722: | Line 723: | ||
println(` $time`) |
println(` $time`) |
||
}</lang> |
}</lang> |
||
=={{header|Eiffel}}== |
=={{header|Eiffel}}== |
||
<lang Eiffel> |
<lang Eiffel> |
||
Line 1,030: | Line 1,032: | ||
2008/10/03_08:40:40 |
2008/10/03_08:40:40 |
||
</pre> |
</pre> |
||
=={{header|Gema}}== |
=={{header|Gema}}== |
||
Start with ''gema -f licenses.gema mlijobs.txt'' |
Start with ''gema -f licenses.gema mlijobs.txt'' |
||
Line 1,307: | Line 1,310: | ||
2008/10/03_08:39:34 |
2008/10/03_08:39:34 |
||
2008/10/03_08:40:40</pre> |
2008/10/03_08:40:40</pre> |
||
=={{header|jq}}== |
=={{header|jq}}== |
||
{{works with|jq|1.4}} |
{{works with|jq|1.4}} |
||
Line 1,340: | Line 1,344: | ||
user 0m0.154s |
user 0m0.154s |
||
sys 0m0.005s |
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}}== |
=={{header|Julia}}== |
||
Line 1,379: | Line 1,372: | ||
- 2008/10/03_08:39:34 |
- 2008/10/03_08:39:34 |
||
- 2008/10/03_08:40:40</pre> |
- 2008/10/03_08:40:40</pre> |
||
=={{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|Kotlin}}== |
=={{header|Kotlin}}== |
||
Line 1,466: | Line 1,470: | ||
2008/10/03_08:39:34 |
2008/10/03_08:39:34 |
||
2008/10/03_08:40:40</pre> |
2008/10/03_08:40:40</pre> |
||
=={{header|M2000 Interpreter}}== |
=={{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). |
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). |
||
Line 1,747: | Line 1,752: | ||
2008/10/03_08:39:34 |
2008/10/03_08:39:34 |
||
2008/10/03_08:40:40 |
2008/10/03_08:40:40 |
||
</pre> |
|||
=={{header|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: |
|||
<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); |
|||
} |
|||
} |
|||
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;</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> |
</pre> |
||
Line 1,872: | Line 1,832: | ||
2008/10/03_08:40:40 |
2008/10/03_08:40:40 |
||
</pre> |
</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|PL/I}}== |
=={{header|PL/I}}== |
||
Line 1,918: | Line 1,905: | ||
It occurred at 2008/10/03_08:39:34 for job 1833 |
It occurred at 2008/10/03_08:39:34 for job 1833 |
||
</pre> |
</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}}== |
=={{header|PowerShell}}== |
||
Line 2,126: | Line 2,086: | ||
(for-each displayln max-used-when)</lang> |
(for-each displayln max-used-when)</lang> |
||
(Same output) |
(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: |
|||
<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); |
|||
} |
|||
} |
|||
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;</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|REXX}}== |
=={{header|REXX}}== |
||
Line 2,306: | Line 2,312: | ||
2008/10/03_08:40:40 |
2008/10/03_08:40:40 |
||
</pre> |
</pre> |
||
=={{header|Run BASIC}}== |
=={{header|Run BASIC}}== |
||
<lang lb>open "c:\data\temp\logFile.txt" for input as #f |
<lang lb>open "c:\data\temp\logFile.txt" for input as #f |
||
Line 2,557: | Line 2,564: | ||
Output matches Python |
Output matches Python |
||
=={{header|TUSCRIPT}}== |
=={{header|TUSCRIPT}}== |
||
<lang tuscript> |
<lang tuscript> |