Kernighans large earthquake problem: Difference between revisions
Kernighans large earthquake problem (view source)
Revision as of 11:10, 12 December 2023
, 5 months ago→{{header|Wren}}: Minor tidy
Puppydrum64 (talk | contribs) |
m (→{{header|Wren}}: Minor tidy) |
||
(8 intermediate revisions by 6 users not shown) | |||
Line 1:
{{task}}
[
;Problem:
Line 21:
{{trans|Python}}
<
I Float(ln.split(‘ ’, group_delimiters' 1B)[2]) > 6
print(ln)</
{{out}}
Line 34:
I'm going to make the assumption that all magnitudes are given as floating points rounded to one decimal place, e.g. "6.0" when the magnitude is exactly 6. That way I don't need to actually use floating point logic. The hardware print routines were omitted to keep things short, since the Sega Genesis doesn't have a built-in kernel and so I'd have to manually write to the video chip. Chances are you're not interested in seeing all that fluff when you'd rather look at the actual algorithm for the task.
<
macro pushRegs 1
MOVEM.L \1,-(SP)
Line 43:
endm
;---------------------------------------------------------------------------
;Ram Variables
Line 156 ⟶ 149:
bra lineseek
.done:
RTS</
{{out}}
<pre>8/27/1883 Krakatoa 8.8
5/18/1980 MountStHelens 7.6</pre>
=={{header|8080 Assembly}}==
Line 172 ⟶ 164:
automatically.
<
puts: equ 9 ; CP/M syscall to print a string
fopen: equ 15 ; CP/M syscall to open a file
Line 238 ⟶ 230:
jmp 5
emsg: db 'Error!$'
line: equ $ ; Line buffer after program </
{{out}}
Line 260 ⟶ 252:
{{libheader|Action! Tool Kit}}
{{libheader|Action! Real Math}}
<
BYTE FUNC FindFirstNonspace(CHAR ARRAY s BYTE start)
Line 322 ⟶ 314:
PrintRE(value) PutE()
Process(fname,value,1)
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Kernighans_large_earthquake_problem.png Screenshot from Atari 8-bit computer]
Line 347 ⟶ 339:
=={{header|Ada}}==
<
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
Line 379 ⟶ 371:
end loop;
Close (Inpt_File);
end Main;</
The file data.txt contains a 0 length line as well as a line composed of only blanks.
<pre>
Line 399 ⟶ 391:
=={{header|ALGOL 68}}==
<
STRING file name = "data.txt";
open( input file, file name, stand in channel ) /= 0
Line 469 ⟶ 461:
# close the file #
close( input file )
FI</
=={{header|Amazing Hopper}}==
<syntaxhighlight lang="amazing hopper">
/* Kernighans large earthquake problem. */
Line 499 ⟶ 491:
CEND
END
</syntaxhighlight>
{{out}}
<pre>
Line 542 ⟶ 534:
<p>On the other hand, HOPPER processes dates in DD/MM/YYYY format, and the file records dates in MM/DD/YYYY format: therefore, it is necessary to exchange "DD" for "MM", because HOPPER does not allow other types of format for "dates".</p>
<p>The final program would be as follows:</p>
<syntaxhighlight lang="amazing hopper">
/* Kernighans large earthquake problem. */
Line 576 ⟶ 568:
CEND
END
</syntaxhighlight>
<p>And this is fast!</p>
<p>If you want to print the original dates, just add the line "Swap Day By Month(1,2)" before printing the result. In this case, the results are printed with the dates changed.</p>
Line 589 ⟶ 581:
=={{header|AppleScript}}==
<
-- A local "owner" for the long AppleScript lists. Speeds up references to their items and properties.
script o
Line 624 ⟶ 616:
end kernighansEarthquakes
kernighansEarthquakes(6)</
===Functional===
Line 631 ⟶ 623:
while emphasising code reuse, and speed of writing and refactoring:
<
use framework "Foundation"
use scripting additions
Line 770 ⟶ 762:
set my text item delimiters to dlm
str
end unlines</
{{Out}}
<pre>Magnitudes above 6.0 in ~/Desktop/data.txt:
Line 783 ⟶ 775:
and the magnitude as an optional left argument (defaulting to 6).
<
⍺←6
nl←⎕UCS 13 10
Line 790 ⟶ 782:
keep←⍺{0::0 ⋄ ⍺ < ⍎3⊃(~⍵∊4↑⎕TC)⊆⍵}¨lines
↑keep/lines
}</
{{out}}
Line 807 ⟶ 799:
=={{header|Arturo}}==
<
3/13/2009 CostaRica 5.1
8/27/1883 Krakatoa 8.8
Line 816 ⟶ 808:
print first sort.descending.by:'magnitude map split.lines data =>
[to :earthquake split.words &]</
{{out}}
Line 823 ⟶ 815:
=={{header|AWK}}==
<
=={{header|Bash}}==
<
while read line
do
[[ ${line##* } =~ ^([7-9]|6\.0*[1-9]).*$ ]] && echo "$line"
done < data.txt</
{{out}}
Line 848 ⟶ 840:
=={{header|BASIC256}}==
<syntaxhighlight lang="basic256">
f = freefile
filename$ = "data.txt"
Line 860 ⟶ 852:
close f
end
</syntaxhighlight>
=={{header|C}}==
<
#include <string.h>
#include <stdlib.h>
Line 891 ⟶ 883:
if (line) free(line);
return 0;
}</
{{output}}
Line 903 ⟶ 895:
=={{header|C sharp}}==
<
using System.IO;
using System.Linq;
Line 921 ⟶ 913:
select parts;
}</
=={{header|C++}}==
<
#include <iostream>
#include <fstream>
Line 967 ⟶ 959:
return 0;
}</
New version:
<
#include <iostream>
#include <iomanip>
Line 992 ⟶ 984:
cout << endl << "Number of quakes greater than 6 is " << count_quake << endl;
return 0;
}</
=={{header|Cixl}}==
<
use: cx;
Line 1,003 ⟶ 995:
$m1 6 >= $m2 0 > and {[$time @@s $place @@s $mag] say} if
} for
</syntaxhighlight>
{{output}}
Line 1,015 ⟶ 1,007:
First, with a data file. This adds a fair amount of verbosity to COBOL. For something this one-off, a simpler cut using ACCEPT from standard in is shown.
<syntaxhighlight lang="cobolfree">*>
*> Kernighan large earthquake problem
*> Tectonics: cobc -xj kernighan-earth-quakes.cob
*>
*>
>>SOURCE FORMAT IS FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. quakes.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
FUNCTION ALL INTRINSIC.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
ASSIGN
ORGANIZATION IS
STATUS
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
01 quake-fd-status
88 ok
"05", "06", "07", "08", "09".
88 no-more
88 io-error
01 line-length USAGE IS BINARY-LONG.
01 date-time PICTURE IS X(10).
01 quake PICTURE IS X(20).
01 magnitude PICTURE IS 99V99.
01 command-filename
PROCEDURE DIVISION.
show-big-ones.
OPEN
DISPLAY
PERFORM
IF magnitude
*>
IF
EXIT
END
{{output}}
Line 1,116 ⟶ 1,106:
A slighter shorter-version.
<
*> Tectonics: ./kerighan-earth-quakes <quakes.txt
01 data-line
88 no-more
01 date-time
01 quake
01 magnitude
show-big-ones.
That cut would be used as <pre>prompt$ ./kernighans-large-earthquakes <quakes.txt</pre>
=={{header|Cowgol}}==
<
include "file.coh";
Line 1,234 ⟶ 1,224:
end if;
ForEachLine(&quakes, PrintIfGt6); </
{{out}}
Line 1,248 ⟶ 1,238:
5/18/1980 MountStHelens 7.6
1/25/4567 EdgeCase3 6.1</pre>
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|Controls,SysUtils,Classes,StdCtrls,ExtCtrls}}
This code takes advantage of the standard Delphi "TStringGrid" object to do most of the heavy lifting. It is initially used to read the earthquake file into memory, breaking it up into of individual lines as it goes. Then the individual fields are stored in structurs/records attached to the data. finally, the data is sorted by magnitude so the earthquakes of magnitudes greater than six can be extracted. Because the data is now neatly organized in memory, all kinds of other process could be done, including sorting it by date or location. To make the problem more realistic, I extracted actual earthquake data from the first few months of 2023. I've post the data for other people to test here: [https://fountainware.com/download/EarthQuakes.txt EarthQuakes.txt]
<syntaxhighlight lang="Delphi">
{Structure used to contain all the earthquake data}
type TQuakeInfo = record
Date: TDate;
Name: string;
Mag: double;
end;
type PQuakeInfo = ^TQuakeInfo;
{Used to contain individual fields of the earthquake data}
type TStringArray = array of string;
function SortCompare(List: TStringList; Index1, Index2: Integer): Integer;
{Custom sort routine to sort data by magnitude }
var QI1,QI2: TQuakeInfo;
begin
QI1:=PQuakeInfo(List.Objects[Index1])^;
QI2:=PQuakeInfo(List.Objects[Index2])^;
Result:=Round(QI2.Mag*10)-Round(QI1.Mag*10);
end;
procedure GetFields(S: string; var SA: TStringArray);
{Extract the three fields from each row of data}
var I,F: integer;
begin
SetLength(SA,3);
for I:=0 to High(SA) do SA[I]:='';
F:=0;
for I:=1 to Length(S) do
if S[I] in [#$09,#$20] then Inc(F)
else SA[F]:=SA[F]+S[I];
end;
procedure AnalyzeEarthQuakes(Filename: string; Memo: TMemo);
{Read earhtquake data from specified file}
{Extract the individual fields and sort and display it}
var SL: TStringList;
var I: integer;
var S: string;
var FA: TStringArray;
var QI: PQuakeInfo;
begin
SL:=TStringList.Create;
try
{Read file, separating it into rows}
SL.LoadFromFile(Filename);
{Process each row}
for I:=0 to SL.Count-1 do
begin
S:=SL[I];
{Separate row into fields}
GetFields(S,FA);
{Store data as objects in TStringList}
New(QI);
QI.Date:=StrToDate(FA[0]);
QI.Name:=FA[1];
QI.Mag:=StrToFloat(FA[2]);
SL.Objects[I]:=TObject(QI);
end;
{Sort data by magnitude}
SL.CustomSort(SortCompare);
{Display sorted data}
for I:=0 to SL.Count-1 do
begin
if PQuakeInfo(SL.Objects[I]).Mag<6 then break;
S:=FormatDateTime('dd/mm/yyyy', PQuakeInfo(SL.Objects[I]).Date);
S:=S+Format(' %-34s',[PQuakeInfo(SL.Objects[I]).Name]);
S:=S+Format(' %5f',[PQuakeInfo(SL.Objects[I]).Mag]);
Memo.Lines.Add(S);
end;
{Dispose of memory}
finally
for I:=0 to SL.Count-1 do Dispose(PQuakeInfo(SL.Objects[I]));
SL.Free;
end;
end;
procedure ShowEarthQuakes(Memo: TMemo);
begin
AnalyzeEarthQuakes('EarthQuakes.txt',Memo);
end;
</syntaxhighlight>
{{out}}
<pre>
06/02/2023 Turkey_Kahramanmaras 7.80
09/01/2023 Indonesia_Maluku 7.60
06/02/2023 Turkey_Kahramanmaras 7.50
02/04/2023 Papua_New_Guinea_East_Sepik 7.00
16/03/2023 New_Zealand_Kermadec_Islands 7.00
18/01/2023 Indonesia_North_Maluku 7.00
14/04/2023 Indonesia_East_Java 7.00
08/01/2023 Vanuatu_Sanma 7.00
04/03/2023 New_Zealand_Kermadec_Islands 6.90
23/02/2023 Tajikistan_Gorno-Badakhshan 6.90
18/03/2023 Ecuador_Guayas 6.80
20/01/2023 Argentina_Santiago_del_Estero 6.80
18/04/2023 South_of_theFiji_Islands 6.70
06/02/2023 Turkey_Gaziantep 6.70
01/03/2023 Papua_New_Guinea_West_New_Britain 6.60
02/03/2023 Vanuatu_Sanma 6.50
03/04/2023 Russia_Kamchatka_Krai 6.50
22/03/2023 Argentina_Jujuy 6.50
21/03/2023 Afghanistan_Badakhshan 6.50
24/01/2023 Argentina_Santiago_del_Estero 6.40
19/04/2023 Papua_New_Guinea_West_New_Britain 6.30
16/01/2023 Japan_Bonin_Islands 6.30
20/02/2023 Turkey_Hatay 6.30
23/02/2023 Indonesia_North_Maluku 6.30
21/04/2023 Indonesia_Southeast_Sulawesi 6.30
14/03/2023 Papua_New_Guinea_Madang 6.30
30/03/2023 Chile_Maule 6.30
04/04/2023 Panama_Chiriqu- 6.30
25/02/2023 Papua_New_Guinea_West_New_Britain 6.20
04/04/2023 Philippines_Bicol 6.20
27/03/2023 Solomon_Islands_Isabel 6.10
03/04/2023 Indonesia_North_Sumatra 6.10
17/02/2023 Indonesia_Maluku 6.10
15/02/2023 Philippines_Bicol 6.10
13/02/2023 New_Zealand_Kermadec_Islands 6.10
20/01/2023 France_Guadeloupe 6.10
15/01/2023 Indonesia_Aceh 6.10
28/03/2023 Japan_Hokkaido 6.00
18/01/2023 Indonesia_Gorontalo 6.00
01/02/2023 Philippines_Davao 6.00
05/01/2023 Afghanistan_Badakhshan 6.00
26/01/2023 New_Zealand_Kermadec_Islands 6.00
06/02/2023 Turkey_Kahramanmaras 6.00
06/02/2023 Turkey_Malatya 6.00
25/02/2023 Japan_Hokkaido 6.00
13/04/2023 Canada_British_Columbia 6.00
</pre>
=={{header|D}}==
{{trans|Kotlin}}
<
import std.regex : ctRegex, split;
import std.stdio : File, writeln;
Line 1,265 ⟶ 1,399:
}
}
}</
{{out}}
<pre>Those earthquakes with a magnitude > 6.0 are:
Line 1,272 ⟶ 1,406:
=={{header|Emacs Lisp}}==
<
(insert-file-contents "data.txt")
(goto-char (point-min))
Line 1,281 ⟶ 1,415:
(when (> (string-to-number magn) 6.0)
(message line)))
(forward-line 1)))</
=={{header|Factor}}==
<code>lines</code> is a convenience word that reads lines from standard input. If you don't want to type them all in yourself, it is suggested that you give the program a file to read. For example, on the Windows command line: <code>factor kernighan.factor < earthquakes.txt</code>
<
IN: rosetta-code.kernighan
lines [ "\s" split last string>number 6 > ] filter .</
=={{header|FreeBASIC}}==
<
Dim As Long f
f = Freefile
Line 1,309 ⟶ 1,443:
Close #f
Sleep
</syntaxhighlight>
=={{header|Go}}==
<
import (
Line 1,344 ⟶ 1,478:
}
}
}</
{{out}}
Line 1,356 ⟶ 1,490:
=={{header|Groovy}}==
{{trans|Kotlin}}
<
class LargeEarthquake {
Line 1,369 ⟶ 1,503:
}
}
}</
{{out}}
<pre>Those earthquakes with a magnitude > 6.0 are:
Line 1,377 ⟶ 1,511:
=={{header|Haskell}}==
<
main :: IO ()
Line 1,386 ⟶ 1,520:
(\x ->
[ x
| 6 < (read (last (C.unpack <$> C.words x)) :: Float) ])</
{{Out}}
<pre>"8/27/1883 Krakatoa 8.8"
Line 1,392 ⟶ 1,526:
=={{header|J}}==
<syntaxhighlight lang="j">
NB. this program is designed for systems where the line ending is either LF or CRLF
Line 1,407 ⟶ 1,541:
(y <: magnitudes) # lines
)
</syntaxhighlight>
<pre>
Line 1,417 ⟶ 1,551:
=={{header|Java}}==
Input file contains sample data shown in the task
<syntaxhighlight lang="java">
import java.io.BufferedReader;
import java.io.FileReader;
Line 1,438 ⟶ 1,572:
}
</syntaxhighlight>
{{out}}
Line 1,448 ⟶ 1,582:
=={{header|JavaScript}}==
Input file contains sample data shown in the task. The code below uses Nodejs to read the file.
<syntaxhighlight lang="javascript">
const fs = require("fs");
const readline = require("readline");
Line 1,471 ⟶ 1,605:
}
});
</syntaxhighlight>
{{out}}
Line 1,495 ⟶ 1,629:
where data.txt is as for [[#Snobol|Snobol]].
<
| "The earthquakes from \(input_filename) with a magnitude greater than 6 are:\n",
( $one, inputs
Line 1,506 ⟶ 1,640:
| $line) catch "WARNING: column 3 is not a recognized number in the line:\n\($line)"
end )
</syntaxhighlight>
{{out}}
<pre>
Line 1,518 ⟶ 1,652:
=={{header|Julia}}==
Using the example data as a small text file.
<
df = CSV.File("kernighansproblem.txt", delim=" ", ignorerepeated=true,
Line 1,525 ⟶ 1,659:
println(filter(row -> row[:Magnitude] > 6, df))
</
2×3 DataFrame
│ Row │ Date │ Location │ Magnitude │
Line 1,535 ⟶ 1,669:
=={{header|Klingphix}}==
<
( [get nip]
Line 1,552 ⟶ 1,686:
$f fclose
"End " input</
=={{header|Kotlin}}==
<
import java.io.File
Line 1,565 ⟶ 1,699:
if (it.split(r)[2].toDouble() > 6.0) println(it)
}
}</
{{output}}
Line 1,578 ⟶ 1,712:
=={{header|Lua}}==
For each line, the Lua pattern "%S+$" is used to capture between the final space character and the end of the line.
<
for line in io.lines(arg[1] or "data.txt") do -- use data.txt if arg[1] is nil
magnitude = line:match("%S+$")
if tonumber(magnitude) > 6 then print(line) end
end</
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
Module Find_Magnitude {
data$={8/27/1883 Krakatoa 8.8
Line 1,607 ⟶ 1,741:
</syntaxhighlight>
Line 1,618 ⟶ 1,752:
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
=={{header|Nim}}==
Here is one way to do that:
<
for line in "data.txt".lines:
Line 1,631 ⟶ 1,765:
if magnitude > 6:
echo line
# else wrong line: ignore.</
Here is another way with less checks:
<
for line in "data.txt".lines:
let magnitude = line.rsplit(' ', 1)[1]
if magnitude.parseFloat() > 6:
echo line</
{{out}}
Line 1,647 ⟶ 1,781:
=={{header|Perl}}==
<
=={{header|Phix}}==
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">filename</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"data.txt"</span>
Line 1,664 ⟶ 1,798:
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</
{{out}}
<pre>
Line 1,672 ⟶ 1,806:
=={{header|Phixmonti}}==
<
if
get nip
Line 1,693 ⟶ 1,827:
endif
endwhile
fclose</
=={{header|PHP}}==
Parse using PHP's fscanf().
<
// make sure filename was specified on command line
Line 1,714 ⟶ 1,848:
fclose( $fh );
</syntaxhighlight>
Usage: Specify file name on command line. Ex:
Line 1,726 ⟶ 1,860:
=={{header|PicoLisp}}==
<syntaxhighlight lang="picolisp">
(load "@lib/misc.l")
Line 1,735 ⟶ 1,869:
(prinl (align -10 Date) " " (align -15 Quake) " " Mag)))))
(bye)
</syntaxhighlight>
{{Out}}
<pre>
Line 1,745 ⟶ 1,879:
{{works with|SWI Prolog}}
Example command line: <code>swipl kernighans_earthquake.pl earthquake.txt</code>.
<
process_line(Line):-
Line 1,773 ⟶ 1,907:
main(_):-
swritef(Message, 'File argument is missing\n', []),
write(user_error, Message).</
{{out}}
Line 1,782 ⟶ 1,916:
=={{header|PureBasic}}==
<
PrintN("Those earthquakes with a magnitude > 6.0 are:")
While Not Eof(0)
Line 1,792 ⟶ 1,926:
CloseFile(0)
Input()
EndIf</
{{out}}
<pre>Those earthquakes with a magnitude > 6.0 are:
Line 1,800 ⟶ 1,934:
=={{header|Python}}==
Typed into a bash shell or similar:
<
with open("data.txt") as f:
for ln in f:
if float(ln.strip().split()[2]) > 6:
print(ln.strip())'</
Or, if scale permits a file slurp and a parse retained for further processing, we can combine the parse and filter with a concatMap abstraction:
<
from functools import (reduce)
from itertools import (chain)
Line 1,846 ⟶ 1,980:
# MAIN ---
if __name__ == '__main__':
main()</
{{Out}}
<pre>[('8/27/1883', 'Krakatoa', '8.8'), ('5/18/1980', 'MountStHelens', '7.6')]</pre>
Line 1,856 ⟶ 1,990:
This is just a file filter, matching lines are printed out.
<
(with-input-from-file "data/large-earthquake.txt"
Line 1,862 ⟶ 1,996:
(for ((s (in-port read-line))
#:when (> (string->number (third (string-split s))) 6))
(displayln s))))</
Or, defining a list -> list function in terms of '''filter''':
<
; largeQuakes :: Int -> [String] -> [String]
Line 1,897 ⟶ 2,031:
; unlines :: [String] -> String
(define (unlines xs)
(string-join xs "\n"))</
{{out}}
Line 1,904 ⟶ 2,038:
To combine filtering with more pre-processing, we can use '''concatMap''' in place of '''filter''':
<
(require gregor) ; Date parsing
Line 1,943 ⟶ 2,077:
(define (readFile fp)
(file->string
(expand-user-path fp)))</
{{Out}}
<pre>(#<date 1883-08-27> "Krakatoa" 8.8)
Line 1,952 ⟶ 2,086:
{{works with|Rakudo|2018.03}}
Pass in a file name, or use default for demonstration purposes.
<syntaxhighlight lang="raku"
8/27/1883 Krakatoa 8.8
5/18/1980 MountStHelens 7.6
Line 1,958 ⟶ 2,092:
END
map { .say if .words[2] > 6 }, .lines;</
=={{header|REXX}}==
Line 1,967 ⟶ 2,101:
:::* the number of records that met the qualifying magnitude
:::* the qualifying magnitude
<
parse arg iFID mMag . /*obtain optional arguments from the CL*/
if iFID=='' | iFID=="," then iFID= 'earthquakes.dat' /*Not specified? Then use default*/
Line 1,985 ⟶ 2,119:
say
if j==0 then say er 'file ' iFID " is empty or not found."
else say # ' earthquakes listed whose magnitude is ≥ ' mMag</
{{out|output|text= when using the default inputs:}}
<pre>
Line 2,001 ⟶ 2,135:
=={{header|Ring}}==
<
# Project : Kernighans large earthquake problem
Line 2,027 ⟶ 2,161:
ok
next
</syntaxhighlight>
Output:
<pre>
Line 2,062 ⟶ 2,196:
=={{header|Rust}}==
<
use std::io::{BufRead, BufReader};
Line 2,080 ⟶ 2,214:
Ok(())
}</
=={{header|Scala}}==
<
.map("\\s+".r.split(_))
.filter(_(2).toDouble > 6.0)
.map(_.mkString("\t"))
.foreach(println)</
=={{header|Snobol}}==
Line 2,093 ⟶ 2,227:
This is hard-coded to read the input from "data.txt".
<
num = '.0123456789'
Line 2,101 ⟶ 2,235:
err output = 'Error!'
end</
{{output}}
Line 2,121 ⟶ 2,255:
Expects the program to be started with the path to the data file.
<
guard let path = Array(CommandLine.arguments.dropFirst()).first else {
Line 2,139 ⟶ 2,273:
print(line)
}</
=={{header|Tcl}}==
Inspired by awk.
<
catch {wm withdraw .}
Line 2,159 ⟶ 2,293:
if {$f3 > 6} { puts "$line" }
}
close $fh </
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<
Module Module1
Line 2,180 ⟶ 2,314:
End Sub
End Module</
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">import os
fn main() {
lines := os.read_lines('data.txt')?
Line 2,194 ⟶ 2,328:
}
}
}</
{{out}}
Line 2,206 ⟶ 2,340:
=={{header|Wren}}==
{{libheader|Wren-pattern}}
<
import "os" for Process
import "./pattern" for Pattern
var args = Process.arguments
Line 2,221 ⟶ 2,355:
var mag = Num.fromString(data[2])
if (mag > 6) System.print(line)
}</
{{out}}
Line 2,233 ⟶ 2,367:
=={{header|XPL0}}==
Usage: quake <data.txt
<
[loop [OpenO(8); \get line from input file
repeat C:= ChIn(1);
Line 2,250 ⟶ 2,384:
];
];
]</
{{out}}
Line 2,268 ⟶ 2,402:
=={{header|Yabasic}}==
<
filename$ = peek$("argument")
else
Line 2,282 ⟶ 2,416:
if val(tok$(3)) > 6 print a$
wend
close a</
=={{header|zkl}}==
Line 2,288 ⟶ 2,422:
is bad practice so I don't do it (written so text is automatically
converted to float).
<
data.pump(out,fcn(line){ 6.0line.split()[-1] },Void.Filter)
}</
<
#<<<
"8/27/1883 Krakatoa 8.8\n"
Line 2,297 ⟶ 2,431:
"3/13/2009 CostaRica 5.1\n"
#<<<
));</
or
<
or
<
{{out}}
<pre>
|