in reply to Better way of writing "find the missing number(s)"
In the spirit of TIMTOWTDI :)
#!/usr/bin/perl # http://perlmonks.org/?node_id=1186862 use strict; use warnings; my @arr = (19,17,22,23,24,15,16,25..35); my @sorted = sort {$a <=> $b} @arr; my @missing = map { $sorted[$_ - 1] + 1 .. $sorted[$_] - 1 } 1 .. $#so +rted; print "missing numbers are @missing\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Better way of writing "find the missing number(s)"
by Discipulus (Canon) on Apr 03, 2017 at 20:52 UTC |