determine longest group of consecutive numbers INPUT:


10 random numbers
each number is greater than 0 and less than 100
list of numbers is presorted, lowest to highest
the list will not contain any duplicate numbers


CHALLENGE:

Write a function that would take in the numbers, and return the count of the longest group of consecutive numbers.

EXAMPLE OUTPUT:

1 2 33 44 55 66 77 88 90 98 =&gt; return of the function would be 2
1 3 23 24 30 48 49 70 75 80 =&gt; return of the function would be 2
6 9 50 51 52 72 81 83 90 92 =&gt; return of the function would be 3
APL, 26 21 characters

1+⌈/+/^\9 9⍴0,1=-2-/⎕


Here's the 26-character solution:

i←⎕⋄⌈/{1++/^\⍵↓1=-2-/i}¨⍳9


I used Dyalog APL as my interpreter, and ⎕IO should be set to 0 for the 26-character version.

Example:

      1+⌈/+/^\9 9⍴0,1=-2-/⎕
⎕:
      6 7 51 51 53 51 54 55 56 55
3


This answer explains most of what I in the 26-character solution, but I might have to write a new one up for the 21-character version.