sub format_number_list {
   my ($prev, @list) = @_;
   my $result = $prev;

   for my $cur (@list) {
     if ($cur - abs($prev) == 1) {
       $prev = - $cur;
     } elsif ($prev < 0) {
       $result .= "$prev, $cur";
       $prev = $cur;
     } else {
       $result .= ", $cur";
       $prev = $cur;
     }
   }

   $result .= $prev if $prev < 0;
   $result;
}


sub expand_number_list {
   return map {(m/(\d+)-(\d+)/)?($1..$2):$_} split /, /, shift;
}
