How is this:
use strict; use warnings; my @a = qw(0 6:4 12:8 19:31); my %b; for (@a){ if (!/:/){ $b{$_}=1; } else { my($a,$b) = split(/:/, $_); ($a,$b)=($b,$a) if $a>$b; $b{$_}=1 for($a..$b); } } print join(" ", grep {!exists $b{$_}} (0..31)), "\n";
Update:
In avoidance of tax filing, I carried on... You asked for 13:18, and later 18:13. This converts 0 6:4 12:8 19:31 to 1:3 7 13:18.
use strict; use warnings; my @a = qw(0 6:4 12:8 19:31); my $s = ''; vec($s,0,32) = 0; for (@a){ if (/(\d+):(\d+)/){ vec($s,$_,1) = 1 for(($1<$2) ? $1..$2 : $2..$1); } else { vec($s,$_,1) = 1; } } my @bits = split(//,unpack("b*",$s)); my $series = 0; for(0..31){ if ($bits[$_] eq 0) { if (!$series) { print; $series = $_; } } else { if ($series) { print ( ($series+1 < $_) ? ':'.($_-1).' ' : ' '); } $series = 0; } }
In reply to Re: screen out an untained array from a special array
by hbm
in thread screen out an untained array from a special array
by Hanken
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |