45 lines
1.0 KiB
Plaintext
45 lines
1.0 KiB
Plaintext
sequence test
|
|
|
|
function alpha(integer i, integer j)
|
|
integer res
|
|
res = compare(test[i],test[j])
|
|
if res=0 then
|
|
res = compare(i,j)
|
|
end if
|
|
return res
|
|
end function
|
|
|
|
function unique(sequence s)
|
|
sequence at, valid = repeat(1,length(s))
|
|
object last, this
|
|
integer ai, nxt
|
|
|
|
test = s
|
|
at = custom_sort(routine_id("alpha"),tagset(length(test)))
|
|
last = test[at[1]]
|
|
for i=2 to length(at) do
|
|
ai = at[i]
|
|
this = test[ai]
|
|
valid[ai] = last!=this
|
|
last = this
|
|
end for
|
|
|
|
nxt = find(0,valid)
|
|
if nxt then
|
|
for i=nxt+1 to length(test) do
|
|
if valid[i] then
|
|
test[nxt] = test[i]
|
|
nxt += 1
|
|
end if
|
|
end for
|
|
test = test[1..nxt-1]
|
|
end if
|
|
return test
|
|
end function
|
|
|
|
?join(unique(split("Now is the time for all good men to come to the aid of the party.")))
|
|
?unique({1, 2, 1, 4, 5, 2, 15, 1, 3, 4})
|
|
?unique({1, 2, 3, "a", "b", "c", 2, 3, 4, "b", "c", "d"})
|
|
?unique({1,3,2,9,1,2,3,8,8,1,0,2})
|
|
?unique("chthonic eleemosynary paronomasiac")
|