Kernighans large earthquake problem: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add Bash) |
Not a robot (talk | contribs) (Add APL) |
||
Line 387: | Line 387: | ||
8/27/1883 Krakatoa 8.8 |
8/27/1883 Krakatoa 8.8 |
||
5/18/1980 MountStHelens 7.6</pre> |
5/18/1980 MountStHelens 7.6</pre> |
||
=={{header|APL}}== |
|||
{{works with|Dyalog APL}} |
|||
This runs from the APL prompt, taking the filename as the right argument |
|||
and the magnitude as an optional left argument (defaulting to 6). |
|||
<lang APL>quakes←{ |
|||
⍺←6 |
|||
nl←⎕UCS 13 10 |
|||
file←80 ¯1⎕MAP ⍵ |
|||
lines←((~file∊nl)⊆file)~¨⊂nl |
|||
keep←⍺{0::0 ⋄ ⍺ < ⍎3⊃(~⍵∊4↑⎕TC)⊆⍵}¨lines |
|||
↑keep/lines |
|||
}</lang> |
|||
{{out}} |
|||
<pre> quakes'data.txt' |
|||
8/27/1883 Krakatoa 8.8 |
|||
5/18/1980 MountStHelens 7.6 |
|||
5 quakes'data.txt' |
|||
8/27/1883 Krakatoa 8.8 |
|||
5/18/1980 MountStHelens 7.6 |
|||
3/13/2009 CostaRica 5.1 |
|||
8 quakes'data.txt' |
|||
8/27/1883 Krakatoa 8.8 |
|||
</pre> |
|||
=={{header|AWK}}== |
=={{header|AWK}}== |