Anonymous user
Kernighans large earthquake problem: Difference between revisions
Kernighans large earthquake problem (view source)
Revision as of 20:36, 18 September 2020
, 3 years agoAdd source for Rust
(Add source for Rust) |
|||
Line 406:
file >> s1 >> s2 >> rate;
if (rate > 6.0) {
}
}
Line 779:
[dup split 3 get tonum 6 > ( [drop print nl] [drop drop] ) if]
[$f fgets dup -1 #]
while
Line 842:
<lang Phixmonti>argument tail nip len dup
if
else
endif
Line 853:
true
while
endwhile
fclose</lang>
Line 869:
// make sure filename was specified on command line
if ( ! isset( $argv[1] ) )
// open file and check for success
if ( ! $fh = fopen( $argv[1], 'r' ) )
while ( list( $date, $loc, $mag ) = fscanf( $fh, "%s %s %f" ) ) {
}
}
Line 900:
(until (eof)
(let (Date (read) Quake (read) Mag (read))
(bye)
</lang>
Line 1,211:
1849-09-09 Pym 9.0
</pre>
=={{header|Rust}}==
<lang Rust>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(())
}</lang>
=={{header|Scala}}==
Line 1,245 ⟶ 1,266:
=={{header|Tcl}}==
Inspired by awk.
<lang tcl>catch {console show}
catch {wm withdraw .}
set filename "data.txt"
set fh [open $filename]
set NR 0
while {[gets $fh line]>=0} {
incr NR
set line2 [regexp -all -inline {\S+} $line] ;# reduce multiple whitespace
set fld [split $line2]
set f3 [lindex $fld 2]
#set NF [llength $fld]
if {$f3 > 6} { puts "$line" }
|