Jump to content

Kernighans large earthquake problem: Difference between revisions

(Added 11l)
Line 829:
if tonumber(magnitude) > 6 then print(line) end
end</lang>
 
=={{header|Nim}}==
Here is one way to do that:
 
<lang Nim>import strscans
 
for line in "data.txt".lines:
var date, name: string
var magnitude: float
if scanf(line, "$+ $s$+ $s$f", date, name, magnitude):
if magnitude > 6:
echo line
# else wrong line: ignore.</lang>
 
Here is another way with less checks:
 
<lang Nim>import strutils
 
for line in "data.txt".lines:
let magnitude = line.rsplit(' ', 1)[1]
if magnitude.parseFloat() > 6:
echo line</lang>
 
{{out}}
<pre>8/27/1883 Krakatoa 8.8
5/18/1980 MountStHelens 7.6</pre>
 
=={{header|Perl}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.