Anonymous user
Kernighans large earthquake problem: Difference between revisions
Kernighans large earthquake problem (view source)
Revision as of 11:50, 30 January 2021
, 3 years ago→{{header|Lua}}
Alextretyak (talk | contribs) (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}}==
|