How to resolve the algorithm Kernighans large earthquake problem step by step in the REXX programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Kernighans large earthquake problem step by step in the REXX programming language
Table of Contents
Problem Statement
Brian Kernighan, in a lecture at the University of Nottingham, described a problem on which this task is based.
You are given a a data file of thousands of lines; each of three whitespace
separated fields: a date, a one word name and the magnitude of the event.
Example lines from the file would be lines like:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Kernighans large earthquake problem step by step in the REXX programming language
Source code in the rexx programming language
/*REXX program to read a file containing a list of earthquakes: date, site, magnitude.*/
parse arg iFID mMag . /*obtain optional arguments from the CL*/
if iFID=='' | iFID=="," then iFID= 'earthquakes.dat' /*Not specified? Then use default*/
if mMag=='' | mMag=="," then mMag= 6 /* " " " " " */
#=0 /*# of earthquakes that meet criteria. */
do j=0 while lines(iFID)\==0 /*read all lines in the input file. */
if j==0 then say 'Reading from file: ' iFID /*show the name of the file being read.*/
parse value linein(iFID) with date site mag . /*parse three words from an input line.*/
if mag<=mMag then iterate /*Is the quake too small? Then skip it*/
#= # + 1; if j==0 then say /*bump the number of qualifying quakes.*/
if #==1 then say center('date', 20, "═") '=magnitude=' center("site", 20, '═')
say center(date, 20) center(mag/1, 11) ' ' site
end /*j*/ /*stick a fork in it, we're all done. */
say
say
if j\==0 then say j 'records read from file: ' iFID
say
if j==0 then say er 'file ' iFID " is empty or not found."
else say # ' earthquakes listed whose magnitude is ≥ ' mMag
You may also check:How to resolve the algorithm Almost prime step by step in the Phix programming language
You may also check:How to resolve the algorithm Classes step by step in the Lasso programming language
You may also check:How to resolve the algorithm Greatest element of a list step by step in the 11l programming language
You may also check:How to resolve the algorithm Sorting algorithms/Bubble sort step by step in the Lambdatalk programming language
You may also check:How to resolve the algorithm Chinese zodiac step by step in the FreeBASIC programming language