How to resolve the algorithm Kernighans large earthquake problem step by step in the D programming language

Published on 12 May 2024 09:40 PM
#D

How to resolve the algorithm Kernighans large earthquake problem step by step in the D 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 D programming language

Source code in the d programming language

import std.conv : to;
import std.regex : ctRegex, split;
import std.stdio : File, writeln;

void main() {
    auto ctr = ctRegex!"\\s+";

    writeln("Those earthquakes with a magnitude > 6.0 are:");
    foreach (line; File("data.txt").byLineCopy) {
        auto parts = split(line, ctr);
        if (parts[2].to!double > 6.0) {
            writeln(line);
        }
    }
}


  

You may also check:How to resolve the algorithm Comments step by step in the KonsolScript programming language
You may also check:How to resolve the algorithm Kaprekar numbers step by step in the Scheme programming language
You may also check:How to resolve the algorithm Flow-control structures step by step in the MUMPS programming language
You may also check:How to resolve the algorithm Duffinian numbers step by step in the C++ programming language
You may also check:How to resolve the algorithm Imaginary base numbers step by step in the Raku programming language