in reply to Re: Find the missing number
in thread Better way of writing "find the missing number(s)"
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
|
|---|