in reply to Adjacent numbers
#!/usr/bin/perl use warnings; use strict; my $previous_num = -1; my $previous_line; my $print_next = 0; sub output { my $num = shift; my $adjacent = abs($previous_num - $num) == 1; if ($print_next || $adjacent) { print $previous_line; $print_next = $adjacent; } } while (<>) { my ($num) = /([0-9]+$)/; output($num); $previous_num = $num; $previous_line = $_; } output($previous_num); # Process the last line.
Update: Fixed to catch decreasing numbers, too. Thanks GotToBTru.
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Adjacent numbers
by GotToBTru (Prior) on Nov 19, 2015 at 21:56 UTC | |
by BrowserUk (Patriarch) on Nov 19, 2015 at 22:09 UTC | |
by soonix (Chancellor) on Nov 20, 2015 at 12:06 UTC | |
by BrowserUk (Patriarch) on Nov 20, 2015 at 12:19 UTC |