inspired by your use of sum, the expected sum(1..n) = n*(n+1)/2, so take the found sum from the expected sum:
use List::Util qw(sum); my @arr=(1..3,5..7); print +(1+@arr)*(2+@arr)/2 - sum(@arr);
update: clarification = use 1+ and 2+ here because an element is missing from @arr
In reply to Re^2: Find the missing number
by pryrt
in thread Better way of writing "find the missing number(s)"
by pritesh_ugrankar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |