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
No edit summary |
m (→{{header|Wren}}: Minor tidy) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 1:
{{task}}
[
;Problem:
Line 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="
*>▼
▲ *> Kernighan large earthquake problem
*>
*>
▲ *> ./kernighan-earth-quakes
*>▼
IDENTIFICATION DIVISION.
▲ >>SOURCE FORMAT IS FREE
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,110 ⟶ 1,108:
<syntaxhighlight lang="cobol"> *>
*> 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}}==
Line 1,246 ⟶ 1,243:
{{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">
Line 1,385 ⟶ 1,382:
13/04/2023 Canada_British_Columbia 6.00
</pre>
=={{header|D}}==
Line 2,344 ⟶ 2,340:
=={{header|Wren}}==
{{libheader|Wren-pattern}}
<syntaxhighlight lang="
import "os" for Process
import "./pattern" for Pattern
var args = Process.arguments
|