turugina #7715(2008/09/28 08:56 GMT) [ Perl ] Rating0/0=0.00
#7713 をperlに移植した感じになりました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
use strict; use warnings; my @list = (1, 3, 4, 5, 6, 12, 13, 15, 20, 25, 26, 27); my $prevd = $list[0]; my @result = ([+$list[0]]); for (my $idx = 1; $idx < @list; ++$idx) { my $d = $list[$idx] - $list[$idx - 1]; if ( $prevd && $prevd != $d ) { push @result, [$list[$idx]]; $prevd = 0; } else { push @{$result[$#result]}, $list[$idx]; $prevd = $d; } } @result = map { if ( @$_ > 2 ) { my $d = $_->[1] - $_->[0]; [@$_[0, $#$_], ($d>1)?($d):()]; } else { @$_; } } @result; use Data::Dumper; print Dumper(\@result);
Rating0/0=0.00-0+
[ reply ]
turugina
#7715()
[
Perl
]
Rating0/0=0.00
#7713 をperlに移植した感じになりました。
Rating0/0=0.00-0+
[ reply ]