Need help with creating, editing and exporting a list

Discussion in 'OT Technology' started by Biomechanoid, Nov 2, 2003.

  1. Biomechanoid

    Biomechanoid New Member

    Joined:
    Oct 21, 2003
    Messages:
    7,265
    Likes Received:
    0
    Location:
    In the Woodline.
    I managed to "borrow" a copy of VB from a friend since what I need to do is very impracticle in qbasic:

    I need to write a program to generate a list of prime numbers between 2 and x and work for middle to large values of x, say 30,000 to 50,000,000

    The most "efficient" way I can think of that involves a minimal of mathematical abstracts is like this (in pseudo programming language)


    f=0
    input x
    for i=2 to x
    output x to prime.lst
    next x

    10

    let y be the next number in prime.lst (starting with 2)
    if f=y then end
    i=y to x
    z=y

    if floor(i/z)=i/z then remove value of i from the list.
    next i
    let f=i
    goto 10

    what it does is generate a list of numbers.
    then starting with 2, eliminates all multiples of that number.

    so say I wanted a list of all primes between 1 and 16.

    heres what the program would do:

    it'll write out 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
    then it'll start with 2, and check each number to see if its a multiple of 2 which at the end of that step, the list would look like 2,3,5,7,9,11,13,15
    then it would take the next number in the list, 3 and remove its multiples, so your list looks like:
    2,3,5,7,11,13
    and it will continue doing the same thing with 5,7,11,... until the end of the list. at which point the list needs to be exported to a text file so that I can then print it out.

    I need this program to work for finding all the primes between 1 and 30,000.

    I am no programmer, and any help will greatly be appreciated.
     
  2. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
    This sounds like its for a class. Which class is this for?
     
  3. Biomechanoid

    Biomechanoid New Member

    Joined:
    Oct 21, 2003
    Messages:
    7,265
    Likes Received:
    0
    Location:
    In the Woodline.
    ultimately, its for advanced number theory.

    I'm trying to discover a way in which to partition the set of primes, and I need some way of getting LOTS of prime numbers.

    also, theory states that the density of primes numbers is zero as the set gets larger, so for very large lists (say 50,000,000) there should be relatively few primes maybe 2 or 3 thousand, which would be an ideal database for me to look at for this project.
     
    Last edited: Nov 3, 2003
  4. Biomechanoid

    Biomechanoid New Member

    Joined:
    Oct 21, 2003
    Messages:
    7,265
    Likes Received:
    0
    Location:
    In the Woodline.
  5. panzerfaust

    panzerfaust New Member

    Joined:
    Oct 13, 2003
    Messages:
    1,604
    Likes Received:
    0
    Location:
    Far far away
    i don't get it so what's the question?

    you have an integer value i from 0 to 30K and the formula for finding primes.

    Anyway here is a version using the sieve of eratosthenes from you first semester discrete mathematics course.


    Code:
    Private Function IsPrime(ByVal Number As Long)
    IsPrime = False
    Dim I As Long
    For I = LBound(Primes) To UBound(Primes)
    	 DoEvents
    	 If (Number Mod Primes(I) = 0) Then Exit Function
    	 If (Primes(I) >= Sqr(Number)) Then Exit For
    Next
    IsPrime = True
    End Function
     
    Private Sub BuildPrimes(ByVal Max As Long)
    If (Max < 3) Then Exit Sub
    Dim I As Long
    For I = 2 To Max
    	 If (IsPrime(I)) Then
    		 ReDim Preserve Primes(UBound(Primes) + 1) As Long
    		 Primes(UBound(Primes)) = I
    	 End If
    Next
    End Sub
     
    Private Sub DoIt()
    ReDim Primes(0)
    Primes(0) = 2
    BuildPrimes 30000
    End Sub
    
     

Share This Page