sol1.pl (444B) [raw]
1 #!/usr/bin/env perl 2 use strict; 3 use warnings; 4 5 my @adapters; 6 while (<ARGV>) { 7 chomp; 8 push(@adapters, $_); 9 } 10 11 @adapters = sort { $a <=> $b } @adapters; 12 13 my %spread; 14 my $last = 0; 15 for my $n (@adapters) { 16 my $delta = $n - $last; 17 if ($delta > 3) { 18 die "assert -- greater than 3 diff\n"; 19 } 20 $spread{$delta}++; 21 $last = $n; 22 } 23 24 $spread{3}++; # for the device 25 26 my $result = $spread{1} * $spread{3}; 27 print "$result\n";