in reply to Better way of writing "find the missing number(s)"

Hi pritesh_ugrankar

Not a better way perhaps, but a solution using Set::IntSpan.

#!/usr/bin/perl use strict; use warnings; use Set::IntSpan; my @arr = (19,17,22,23,24,15,16,25..35); my $set = Set::IntSpan->new(\@arr); print join ' ', $set->holes->elements;

Prints:

18 20 21

Replies are listed 'Best First'.
Re^2: Better way of writing "find the missing number(s)"
by pritesh_ugrankar (Monk) on Apr 03, 2017 at 18:44 UTC

    Hi,

    Thanks for the update. I didn't know about that module.

    Thinkpad T430 with Ubuntu 16.04.2 running perl 5.24.1 thanks to plenv!!