in reply to screen out an untained array from a special array
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; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: screen out an untained array from a special array
by Hanken (Acolyte) on Feb 08, 2009 at 02:05 UTC | |
by toolic (Bishop) on Feb 08, 2009 at 02:16 UTC | |
by Lawliet (Curate) on Feb 08, 2009 at 02:09 UTC | |
|
Re^2: screen out an untained array from a special array
by Hanken (Acolyte) on Feb 08, 2009 at 11:46 UTC | |
by hbm (Hermit) on Feb 08, 2009 at 16:32 UTC |