| |
*solved*
BurninLeo |
|

Member's Standard
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![MFGG Awards 2006 Winner [*]](https://archive.mfgg.net/html/badges/award06.gif)

Group: Members
Posts: 1617
Member No.: 2273
Joined: 3-July 06
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
OK, so I what I want to do is create a 1-dimensional array that prints integers but only if the integer is not repeated. The problem is that I do not know how to check for integers that are duplicates. Here is the code I have for it so far:
| QUOTE | Module Module1
Sub Main()
Dim numbers As Integer() = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 15, 25, 35, 45, 55, 65, 75, 85, 95, 100}
Array.Sort(numbers) 'sort numbers smallest to greatest
For i = 0 To numbers.GetUpperBound(0)
Console.WriteLine(numbers(i))
Next
End Sub
End Module |
The integer value "100" is repeated in this case. Anybody know what I should do?
This post has been edited by BurninLeo on Oct 27 2009, 04:15 PM
|
|
|
Xgoff |
|

<):|
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![Sprite Comp Winner Badge (1) [*]](https://archive.mfgg.net/html/badges/scg1.gif) ![Drawing Comp Winner Badge (1) [*]](https://archive.mfgg.net/html/badges/dcg1.gif) ![Drawing Comp Runner Up Badge (1) [*]](https://archive.mfgg.net/html/badges/dcr1.gif) ![MFGG Awards 2006 Winner [*]](https://archive.mfgg.net/html/badges/award06.gif)
![MFGG Awards 2007 Winner [*]](https://archive.mfgg.net/html/badges/award07.gif) ![Forum Event Badge [*]](https://archive.mfgg.net/html/badges/event.gif)

Group: Members
Posts: 52341
Member No.: 24
Joined: 13-October 03
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
i want to try something that's less than O(n 2)!!! anyway so you don't want to print out any number that is duplicated (so in this case it won't print any 100s at all)? or just one instance of each set of duplicates? numbers = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 15, 25, 35, 45, 55, 65, 75, 85, 95, 100}
table.sort(numbers)
dupes = { }
for index = 1, #numbers do
local current, next = numbers[index], numbers[index + 1]
if not (current == next) and not dupes[current] then
print(current)
else
dupes[current] = true
end
end for example that won't print out any 100s obviously not vb and yeah EDIT: however this way only works reliably when you use it on a pre-sorted list which is what is being done in your example so This post has been edited by Xgoff on Oct 27 2009, 02:36 PM
--------------------
 DISCLAIMER: by sending me (xgoff) a private message, you agree to the directives and their terms specified henceforth: DIRECTIVE 1 (APPLE): i may or may not reply promptly or at all; and there are no guarantees to the usefulness of the reply. i may not acknowledge whether i have even received your private message DIRECTIVE 2 (CHILE CON CARNE): as per my view, "private" applies only to the initial transaction, and the material of your message may or may not be made public at my discretion; as this will more than likely be a post in the CCC or IRC, you may not be able to view it DIRECTIVE 3 (FEATHER DUSTER): you must address me (xgoff) as "Sir Master Xgofficus his Highest and Most Awesome the Third"; failure to comply with this term may invoke one or both of the above directives, and i will leave a burning bag of **** on your doorstep DIRECTIVE 4 (BOOTSTRAP): if you have read this disclaimer, please private message me promptly, in compliance with the above terms, so i can ensure you are capable of following directions you idiot this concludes the test of the emergency disclaimer system, your scheduled programming will now continue. satisfaction guaranteed, and 100% cash back available under certain circumstances; restrictions may or may not apply within your place of residence NOTICE: these directives and their terms may change at any time, without notice; as a private message transaction to myself assumes an understanding and full compliance of the above, you should ensure you are fully aware of the above terms at any point before sending a private message; any message received is assumed to have been sent in compliance with the above| QUOTE | (5:25:58 PM) Mikau: xgoff (5:26:00 PM) Mikau: guess what (5:26:04 PM) Xgoff: chicken butt (5:26:09 PM) Mikau: **** you |
|
|
|
BurninLeo |
|

Member's Standard
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![MFGG Awards 2006 Winner [*]](https://archive.mfgg.net/html/badges/award06.gif)

Group: Members
Posts: 1617
Member No.: 2273
Joined: 3-July 06
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
| QUOTE (Xgoff @ Oct 27 2009, 01:35 PM) | i want to try something that's less than O(n2)!!!
anyway so you don't want to print out any number that is duplicated (so in this case it won't print any 100s at all)? or just one instance of each set of duplicates?
numbers = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 15, 25, 35, 45, 55, 65, 75, 85, 95, 100}
table.sort(numbers)
dupes = { }
for index = 1, #numbers do
local current, next = numbers[index], numbers[index + 1]
if not (current == next) and not dupes[current] then
print(current)
else
dupes[current] = true
end
end for example that won't print out any 100s
obviously not vb and yeah
EDIT: however this way only works reliably when you use it on a pre-sorted list which is what is being done in your example so |
Yeah that's what I need right thur but the whole "next, current, previous" concepts aren't exactly present in VB
what I could do I suppose is check the sum of every index value to see whether or not it equals twice the number of the index value, and if it is, don't write it. But that seems rather tedious.
|
|
|
BurninLeo |
|

Member's Standard
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![MFGG Awards 2006 Winner [*]](https://archive.mfgg.net/html/badges/award06.gif)

Group: Members
Posts: 1617
Member No.: 2273
Joined: 3-July 06
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
| QUOTE | Module Module1
Sub Main()
Dim numbers As Integer() = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 15, 25, 35, 45, 55, 65, 75, 85, 95, 100} Dim output As New ArrayList 'get output
Array.Sort(numbers) 'sort numbers smallest to greatest
For i = 0 To numbers.GetUpperBound(0) If Not numbers(i) = numbers(i + 1) Then Console.WriteLine(numbers(i)) End If Next
End Sub
End Module |
So this piece of code works, but the console window crashes cause I go out of the array range....um....how do I fix that...
|
|
|
Lightning |
|

Ignorance isn't stupidity but choosing to remain ignorant is
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![MFGG Awards 2008 Winner [*]](https://archive.mfgg.net/html/badges/award08.gif)

Group: IRC Operators
Posts: 6381
Member No.: 583
Joined: 31-August 04
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
| CODE | A = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 15, 25, 35, 45, 55, 65, 75, 85, 95, 100] A.sort() print A[0] for i in range(1,len(A)): if A[i] != A[i-1]: print A[i]
|
This post has been edited by Lightning on Oct 27 2009, 03:29 PM
--------------------
click here to change my avatar. / gosh why are you even here lightninghacker, n.an individual who enjoys learning computer system details and how to capitalize on his or her capabilities...not a criminal. (from webster's new world hacker dictionary) |  Fedora 10 Final! Download today! | quality web comics (stories):- girl genius: adventure! romance! mad science!
- punch an' pie: try a slice of life, then swallow.
- dresden codak: most interesting comic ever
quality web comics (one-shots):- a softer world: truth and beauty bombs
- smbc: saturday morning breakfast cereal
- buttersafe: pictures and probably some words
|
"Religion is comparable to a childhood neurosis." - Sigmund Freud “It is not by delusion, however exalted, that mankind can prosper, but only by unswerving courage in the pursuit of truth.” - Bertrand Russell “To kill an error is as good a service as, and sometimes better than, the establishing of a new truth or fact.” - Charles Darwin
|
|
|
Xgoff |
|

<):|
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![Sprite Comp Winner Badge (1) [*]](https://archive.mfgg.net/html/badges/scg1.gif) ![Drawing Comp Winner Badge (1) [*]](https://archive.mfgg.net/html/badges/dcg1.gif) ![Drawing Comp Runner Up Badge (1) [*]](https://archive.mfgg.net/html/badges/dcr1.gif) ![MFGG Awards 2006 Winner [*]](https://archive.mfgg.net/html/badges/award06.gif)
![MFGG Awards 2007 Winner [*]](https://archive.mfgg.net/html/badges/award07.gif) ![Forum Event Badge [*]](https://archive.mfgg.net/html/badges/event.gif)

Group: Members
Posts: 52341
Member No.: 24
Joined: 13-October 03
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
| QUOTE (BurninLeo @ Oct 27 2009, 01:57 PM) | Yeah that's what I need right thur but the whole "next, current, previous" concepts aren't exactly present in VB
what I could do I suppose is check the sum of every index value to see whether or not it equals twice the number of the index value, and if it is, don't write it. But that seems rather tedious. |
well they're just variables storing references to a[x] and a[x+1] so they aren't anything special
--------------------
 DISCLAIMER: by sending me (xgoff) a private message, you agree to the directives and their terms specified henceforth: DIRECTIVE 1 (APPLE): i may or may not reply promptly or at all; and there are no guarantees to the usefulness of the reply. i may not acknowledge whether i have even received your private message DIRECTIVE 2 (CHILE CON CARNE): as per my view, "private" applies only to the initial transaction, and the material of your message may or may not be made public at my discretion; as this will more than likely be a post in the CCC or IRC, you may not be able to view it DIRECTIVE 3 (FEATHER DUSTER): you must address me (xgoff) as "Sir Master Xgofficus his Highest and Most Awesome the Third"; failure to comply with this term may invoke one or both of the above directives, and i will leave a burning bag of **** on your doorstep DIRECTIVE 4 (BOOTSTRAP): if you have read this disclaimer, please private message me promptly, in compliance with the above terms, so i can ensure you are capable of following directions you idiot this concludes the test of the emergency disclaimer system, your scheduled programming will now continue. satisfaction guaranteed, and 100% cash back available under certain circumstances; restrictions may or may not apply within your place of residence NOTICE: these directives and their terms may change at any time, without notice; as a private message transaction to myself assumes an understanding and full compliance of the above, you should ensure you are fully aware of the above terms at any point before sending a private message; any message received is assumed to have been sent in compliance with the above| QUOTE | (5:25:58 PM) Mikau: xgoff (5:26:00 PM) Mikau: guess what (5:26:04 PM) Xgoff: chicken butt (5:26:09 PM) Mikau: **** you |
|
|
|
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Track this topic
Receive email notification when a reply has been made to this topic and you are not active on the board.
Subscribe to this forum
Receive email notification when a new topic is posted in this forum and you are not active on the board.
Download / Print this Topic
Download this topic in different formats or view a printer friendly version.
[ Script Execution time: 0.0805 ] [ 14 queries used ] [ GZIP Enabled ] [ Server Load: 1.12 ]
| |