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

Published on 12 May 2024 09:40 PM

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

Source code in the rust programming language

fn main() -> Result<(), Box<dyn std::error::Error>> {
    use std::io::{BufRead, BufReader};

    for line in BufReader::new(std::fs::OpenOptions::new().read(true).open("data.txt")?).lines() {
        let line = line?;

        let magnitude = line
            .split_whitespace()
            .nth(2)
            .and_then(|it| it.parse::<f32>().ok())
            .ok_or_else(|| format!("Could not parse scale: {}", line))?;

        if magnitude > 6.0 {
            println!("{}", line);
        }
    }

    Ok(())
}


  

You may also check:How to resolve the algorithm Real constants and functions step by step in the Octave programming language
You may also check:How to resolve the algorithm Random number generator (included) step by step in the Elixir programming language
You may also check:How to resolve the algorithm Arena storage pool step by step in the Go programming language
You may also check:How to resolve the algorithm Distance and Bearing step by step in the Java programming language
You may also check:How to resolve the algorithm Roman numerals/Encode step by step in the Scala programming language