Vic D'Elfant Past Contributor
Joined: 26 Jun 2002 Posts: 673 Location: The Netherlands
|
Posted: Tue Sep 14, 2004 2:40 pm Post subject: Find number of double occurences in a list |
|
|
Hey guys,
Skit asked me if I could write a script that was able to count the number of double occurences of a list item in a list... I though I could share the script as well
Code: |
#
# © 2004 Vic D'Elfant
#--------------------------------------------------------
option decimalsep, ","
list create, 1
list create, 2
list create, 3
list loadtext, 1,
"Window1
"Window2
"Window4
"Window4a
"Window1
"Window1
"Window5
"Window4a
# List 1: list with double items
# List 2: temporary list
# List 3: will contain <item list 1>|<number of matches> after running the code below
list seek, 1, 0
list assign, 2, 1
while @ok()
%%Search_Item = @item(1)
%%Match_Count = 0
list seek, 2, 0
while @both(@match(2, %%Search_Item), @ok())
if @equal(%%Search_Item, @item(2))
%%Match_Count = @succ(%%Match_Count)
end
if @unequal(@count(2), @succ(@index(2)))
list seek, 2, @succ(@index(2))
else
error -1
end
wend
%%Causes_Double =
if @not(@zero(@count(3)))
list seek, 3, 0
while @both(@ok(), @not(%%Causes_Double))
parse "%%Window_Name", @item(3)
if @equal(%%Window_Name, %%Search_Item)
%%Causes_Double = 1
end
if @unequal(@count(3), @succ(@index(3)))
list seek, 3, @succ(@index(3))
else
error -1
end
wend
end
if @not(%%Causes_Double)
list add, 3, %%Search_Item|%%Match_Count
end
if @unequal(@count(1), @succ(@index(1)))
list seek, 1, @succ(@index(1))
else
error -1
end
wend
info @text(3)
|
Vic _________________ phpBB Development Team |
|