[xquery-talk] longest sequence of monotonically increasingintegers
Michael Kay
mhk at mhk.me.uk
Sat Mar 4 11:14:18 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]))
>
I think this solution depends on the order of the results of
distinct-values() - Saxon provides the results in "order of first
appearance" but this isn't guaranteed by the language spec. Otherwise, a
nice solution.
Michael Kay
http://www.saxonica.com/
More information about the talk
mailing list