>From the hip

   >./(1&,+/@:*;.1~(1,(0>])+.1<]))(}.-}:)1 2 2 2 3 5 6 7 8 10 11 12
4


R.E. Boss


-----Oorspronkelijk bericht-----
Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Namens Paul Moore
Verzonden: vrijdag 26 september 2008 13:04
Aan: J Programming
Onderwerp: [Jprogramming] Longest run from a list

I've got a sorted list of numbers, and I want to find the longest run
of consecutive integers:

2 4 5 6 12  --> 3
1 2 3 4 5 6  --> 6

Other constraints ensure that there will only ever be 1 such run (for
example 2 3 4 6 7 8, with 2 runs of 3, is not possible). However,
duplicates are: 1 12 13 13 14 - the longest run here is length 3. For
extra credit, I need to know about the duplicates (so that I can
calculate how many combinations make a run of 3).

To save people guessing, this is scoring the runs in a Cribbage hand.

I can see some ways of doing this, using shifts, increments and
comparisons, but things get more complex than I can fathom before I
reach a solution :-)

Paul.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to