Powered by Invision Power Board

 
    Reply to this topicStart new topicStart Poll

> *solved*
United States
BurninLeo
Posted: Oct 27 2009, 11:11 AM
Quote Post


Member's Standard
[*][*]

Group Icon
Group: Members
Posts: 1617
Member No.: 2273
Joined: 3-July 06

Status: (0d) [--]


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
PMEmail PosterMSN
Top
United Kingdom
Kyori
Posted: Oct 27 2009, 12:42 PM
Quote Post


I'm a GUY >.<
[*][*]

Group Icon
Group: Members
Posts: 1467
Member No.: 6088
Joined: 13-March 09

Status: (0d) [--]


QUOTE
function sort(ByVal numbers as Integer()) as Integer()
Dim output as new ArrayList

for every number as Integer in numbers
  Dim found as bool = false
  for every item as Integer in output
  if number = item then
    found = true
    exit for
  end if
  next
 
  if found = false then
  output.Add(number)
  endif
next

return output.ToArray()
end function

This might not even work, but it might! All this should do is take an integer array and take out all the repeated numbers... maybe D: I haven't used vb.NET in ages!


--------------------
user posted image
PMEmail PosterAOLMSN
Top
Unspecified
ChaosEmerl
Posted: Oct 27 2009, 01:57 PM
Quote Post


You are our master!!
[*][*]

Group Icon
Group: Members
Posts: 1419
Member No.: 2765
Joined: 5-October 06

Status: (0d) [--]


Not familiar with Visual Basic

but assuming it's like any other language, what I would do is something like this (except with correct syntax)

CODE

For i = 0 To numbers.GetUpperBound(0)

           boolean Repeat = false

           For j = 0 To (i - 1)
                       if (numbers(i) == numbers(j))
                       {
                                   Repeat = true
                       }
           Next
           
           if (Repeat == false)
           {
                       Console.WriteLine(numbers(i))
           }

Next


Basically puts another FOR loop inside your FOR loop, checking each number up to the current one to see if it's equal to the current one, and if it is, turns on a boolean.

This post has been edited by ChaosEmerl on Oct 27 2009, 02:03 PM


--------------------
PMEmail Poster
Top
United States
Xgoff
Posted: Oct 27 2009, 02:35 PM
Quote Post


<):|
[*][*][*][*][*]
[*][*]

Group Icon
Group: Members
Posts: 52341
Member No.: 24
Joined: 13-October 03

Status: (0d) [--]


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

This post has been edited by Xgoff on Oct 27 2009, 02:36 PM


--------------------

This post may contain original research or unverified claims.
Please disregard the above information and contact an administrator.

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
PMEmail PosterUsers WebsiteAOLMSN
Top
United States
BurninLeo
Posted: Oct 27 2009, 02:57 PM
Quote Post


Member's Standard
[*][*]

Group Icon
Group: Members
Posts: 1617
Member No.: 2273
Joined: 3-July 06

Status: (0d) [--]


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.
PMEmail PosterMSN
Top
United States
BurninLeo
Posted: Oct 27 2009, 03:07 PM
Quote Post


Member's Standard
[*][*]

Group Icon
Group: Members
Posts: 1617
Member No.: 2273
Joined: 3-July 06

Status: (0d) [--]


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...
PMEmail PosterMSN
Top
Unspecified
Lightning
Posted: Oct 27 2009, 03:29 PM
Quote Post


Ignorance isn't stupidity but choosing to remain ignorant is
[*][*]

Group Icon
Group: IRC Operators
Posts: 6381
Member No.: 583
Joined: 31-August 04

Status: (0d) [--]


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 lightning
hacker, 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 linux 10
Fedora 10 Final!

Download today!
quality web comics (stories):
  1. girl genius: adventure! romance! mad science!
  2. punch an' pie: try a slice of life, then swallow.
  3. dresden codak: most interesting comic ever
quality web comics (one-shots):
  1. a softer world: truth and beauty bombs
  2. smbc: saturday morning breakfast cereal
  3. 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
PMUsers WebsiteMSN
Top
United States
Xgoff
Posted: Oct 27 2009, 04:58 PM
Quote Post


<):|
[*][*][*][*][*]
[*][*]

Group Icon
Group: Members
Posts: 52341
Member No.: 24
Joined: 13-October 03

Status: (0d) [--]


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


--------------------

This post may contain original research or unverified claims.
Please disregard the above information and contact an administrator.

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
PMEmail PosterUsers WebsiteAOLMSN
Top
United Kingdom
Kyori
Posted: Oct 27 2009, 05:10 PM
Quote Post


I'm a GUY >.<
[*][*]

Group Icon
Group: Members
Posts: 1467
Member No.: 6088
Joined: 13-March 09

Status: (0d) [--]


sdhfghsgdhfs I missed the part where you said you wanted to print it out, mine was way more than it needed to be ;_;


--------------------
user posted image
PMEmail PosterAOLMSN
Top
Unspecified
ChaosEmerl
Posted: Oct 27 2009, 07:16 PM
Quote Post


You are our master!!
[*][*]

Group Icon
Group: Members
Posts: 1419
Member No.: 2765
Joined: 5-October 06

Status: (0d) [--]


QUOTE (BurninLeo @ Oct 27 2009, 03: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.


CODE

For i = 0 To numbers.GetUpperBound(0)

           boolean Repeat = false

           if i > 0 Then
                       For j = 0 To (i - 1)
                                   if numbers(i) == numbers(j) Then
                                               Repeat = true
                                   End If
                       Next
           End If

           if i < numbers.GetUpperBound(0) Then
                       For j = i + 1 To numbers.GetUpperBound(0)
                                   if (numbers(i) == numbers(j)) Then
                                               Repeat = true
                                   End If
                       Next
           End If
           
           if (Repeat == false) Then
                       Console.WriteLine(numbers(i))
           End If

Next

change my example to this and it should do what you want. Now it checks everything before i for duplicates, assuming i isn't 0, because then you'd go out of the array's range. Then it checks everything after i, assuming i isn't the maximum, because then it would also go out of range.


--------------------
PMEmail Poster
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

  Topic Options Topic Options Reply to this topicStart new topicStart Poll

 




[ Script Execution time: 0.0771 ]   [ 13 queries used ]   [ GZIP Enabled ]   [ Server Load: 2.81 ]