Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Sorting the numbers: A little tricky.

by thundergnat (Deacon)
on Jan 25, 2013 at 14:40 UTC ( #1015357=note: print w/ replies, xml ) Need Help??


in reply to Sorting the numbers: A little tricky.

Your problem is poorly specified. When we have to make guesses as to how to derive your output from your input, it is likely that we will guess the simplest thing that could possibly work and do that, or, more likely, just ask for clarification. Since there have already been several of the latter, I'll take a shot at the former.

Using the following specs - for a file with 2 columns of numbers; let's call them pointer and value:

  • look for consecutive runs where the value (in the second column) is:
    1. Greater than 4
    2. Greater than the value of the previous entries. *** <-- ASSUMPTION
  • Print the pointer of the start of the run, the pointer + 50 of the end of the run, and the value of the end of the run

If it was me, I would do something like:

use warnings; use strict; my ($start, $lastp, $lastv); while ( my $line = <DATA> ){ my ( $pointer, $value ) = split /\s+/, $line; flush() if ( $value <= 4 or $value > 4 && $value < $lastv ); $start = $pointer unless ( defined $start || $value <= 4 ); ( $lastp, $lastv ) = ( $pointer, $value ); } flush(); sub flush { if ( defined $start ){ printf "%d %d (which is %d + 50) %d\n", $start, $lastp + 50, $ +lastp, $lastv; } undef $_ for ( $start, $lastp, $lastv ); } __DATA__ 109026 3 109027 28 109028 30 116958 15 116960 35 116961 39 116962 70 116963 72 147184 2 147588 1 153087 32

Yields:

109027 109078 (which is 109028 + 50) 30
116958 117013 (which is 116963 + 50) 72
153087 153137 (which is 153087 + 50) 32


Comment on Re: Sorting the numbers: A little tricky.
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1015357]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2014-07-24 09:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (158 votes), past polls