in reply to Better way of writing "find the missing number(s)"
Using the updated problem (numbers starting at 1 in order, only one missing), here's something completely DIFFerent :)
#!/usr/bin/perl -l # http://perlmonks.org/?node_id=1186862 use strict; use warnings; use Algorithm::Diff qw(traverse_sequences); my @arr = (1..3,5,6,7); traverse_sequences( \@arr, [ 1 .. @arr + 1 ], { DISCARD_B => sub { print "missing: ", 1 + $_[1] } } );
|
|---|