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

The question posted in LinkedIn is different:

Given an increasing sequence of numbers from 1 to n with only one missing number, how can you find that missing number

The solution to that problem can be found using binary search in O(logN).

  • Comment on Re: Better way of writing "find the missing number(s)"

Replies are listed 'Best First'.
Re^2: Better way of writing "find the missing number" -- oneliner
by Discipulus (Canon) on Apr 04, 2017 at 07:29 UTC
    ah! given the above task the oneliner is much simpler!

    perl -E "@ar=(1..3,5,6,7);$h{$_}++for$ar[0]..$ar[-1];delete$h{$_}for@a +r;print keys %h" 4

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

      Slices, slices...

      perl -E '\@h{1..(@a=(1..3,5,6,7))+1};delete@h{@a};say%h'
      hey, let's play golf!
      perl -e'$_>++$i&&die"$i\n"for 1..3,5,6,7'

      Or an array version.

      perl -E '@b=0..(@a=(1..3,5,6,7))+1;@b[0,@a]="";say@b'
Re^2: Better way of writing "find the missing number(s)"
by pritesh_ugrankar (Monk) on Apr 04, 2017 at 11:20 UTC

    Hi Salva,

    Thanks for pointing that out. I missed that. :(

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