
-----------------------------------
we64
Thu Feb 05, 2004 6:27 pm

how to find and change duplicates in array?
-----------------------------------
If I have 10 random numbers between 1 to 15, such as 5,6,2,10,14,10,5,3,2,1. How do I replace the duplicate numbers?

-----------------------------------
Tony
Thu Feb 05, 2004 6:39 pm


-----------------------------------
just generate a unique list [url=http://www.compsci.ca/v2/viewtopic.php?t=2184]with this code

-----------------------------------
recneps
Thu Feb 05, 2004 6:43 pm


-----------------------------------
store them in an array,
and then go through each array number.
like

for a:1..15%makes it go throught a loop for each number.
for i:1..15%compares the number from large loop to each of the numbers.
if number(i)=number(a) and i not = a then 
put "number ",i," is the same as number (3)."
end for
end fortry that :)

-----------------------------------
sport
Thu Feb 05, 2004 6:45 pm


-----------------------------------
Here is a program how to create ten unique numbers, hope it helps you.

var num : array 1 .. 10 of int
for i : 1 .. 10
    num (i) := 0
end for
var temp : int
var exist : boolean

for i : 1 .. 10

    randomize
    loop
        exist := false
        randint (temp, 1, 15)
        for j : 1 .. 10
            if num (j) = temp then
                exist := true
                exit
            end if
        end for

        if exist = false then
            num (i) := temp
        end if

        exit when exist = false
    end loop
end for

for i : 1 .. 10
    put num (i)
end for


-----------------------------------
we64
Thu Feb 05, 2004 8:01 pm


-----------------------------------
thanks guys
