[xquery-talk] longest sequence of monotonically increasing integers

David Carlisle davidc at nag.co.uk
Sat Mar 4 01:05:30 PST 2006


I note your initial sequence had 1952 duplicated but you still count
1951-1953 as a sequence of length 3 so I added in a couple of
distinct-values() calls here which might or might not be OK.
This returns 3.


declare variable $s:=  ( 1945, 1951, 1952, 1952, 1953, 1961, 1962, 1998);

max(
let $ss:=
for $i at $p in distinct-values($s)
return 
$i - $p
for $j in distinct-values($ss)
return count($ss[.=$j]))

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


More information about the talk mailing list