Berkeley CSUA MOTD:Entry 40473
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/24 [General] UID:1000 Activity:popular
5/24    

2005/11/7-8 [Computer/Theory] UID:40473 Activity:kinda low
11/7    Re: "Teaser: write an algorithm for finding prime numbers." on 11/1,
        I wrote some C code to find all prime numbers between 1 and 4294967295
        with 32-bit math (no 64-bit or floating-point math).  It took about 84
        hours on a 502MHz Sun-Blade-100.
        \_ Quickly thought through, totally untested alg.
           Make a list of (n, n^2) tuples for all n < 2^16 and n is prime.
           For all numbers from 2^16 to 2^32 go through the list
             if n^2 > number you are prime, break.
             if number % n = 0 you are not prime.
           \_ That's more or less what I do in my 13-KByte 83-hour algorithm,
              except that I only keep a list of n instead of (n, n^2).  I'll
              try the sieve method.  --- OP
        \_ So I ran: % nice +20 primes 1 4294967295 > primes.txt
           on my 800MHz Athlon.  It took 8 minutes on the nose.
           % wc -l primes.txt
           203280221 primes.txt
           --dbushong
           \_ Wow!  Must be a better algorithm.  Where's the source code?
              Better yet, what's the algorithm?  Thx.  -- OP
              \_ Pretty standard sieve of eratosthenes:
                 http://www.freebsd.org/cgi/cvsweb.cgi/src/games/primes
                 --dbushong
                 \_ What's the memory usage?  Mine is ~26KB.  -- OP
                 \_ What's the memory usage?  Mine is ~13KB.  -- OP
                    \_ IIRC, it was a few megs --dbushong
        \_ Did you go from 1 to N or 1 to sqrt(n). That would speed things up.
           \_ I go from 1 to sqrt(n).  -- OP
              \_ are you avoiding even #'s? how about factors of 3, 5, 7, etc.
                 that's basically what "primes" is doing.
                 \_ but there are easier tests for divisibility for smaller
                    primes than there are for larger ones.  also, a test for
                    divisibility by 2, 3, 5, 7 and other smaller primes do
                    more to knock out parts of the field.
2025/05/24 [General] UID:1000 Activity:popular
5/24    

You may also be interested in these entries...
2012/1/24-3/3 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Languages/Misc] UID:54296 Activity:nil
1/24    http://james-iry.blogspot.com/2009/05/brief-incomplete-and-mostly-wrong.html
        Amusing "history" of computer science.
        \_ Where's the mentioning of Al Gore the inventor of AlGorithm?
	...
2011/6/29-7/21 [Computer/SW/Database, Computer/SW] UID:54133 Activity:nil
6/29    "An Israeli algorithm sheds light on the Bible"
        http://www.csua.org/u/tq4 (news.yahoo.com)
        "Software developed by an Israeli team is giving intriguing new hints
        about what researchers believe to be the multiple hands that wrote the
        Bible."
        \_ "Hype developed by an American OnLine News Feed is giving
	...
2010/8/9-19 [Computer/SW/Security] UID:53917 Activity:nil
8/9     I got two files, one is size 522190848 and the other is size
        521648128.  Both sha256 to the same number.  (and sha1 too).
        I don't think this is supposed to happen, right? (least not with
        sha256).
        \_ how are you checking?
           \_ I burned one file to cd, so i mounted /cdrom and
	...
2010/3/7-30 [Computer/SW/Languages] UID:53743 Activity:nil
3/7     My sister is graduating soon with a decree in information management.
        She was orignally CS, but couldn't cut the math, so her GPA sucks.
        However, she has had a couple of internships and did fine.  She did
        desktop support at RockYou and is currently doing web programming
        at UC Santa Cruz, but they can't keep her on after graduation.
        Anyone got any jobs?  She wanted to be a network admin, but right now
	...
2010/1/20-29 [Computer/SW/Languages/Misc, Computer/SW/Security] UID:53649 Activity:nil
1/20    Did Chinese come up with new way of quicksort?
        http://www.nytimes.com/2010/01/20/technology/20cyber.html
        Joe Stewart, a malware specialist with SecureWorks, a computer
        security company based in Atlanta, said he determined the main
        program used in the attack contained a module based on an unusu
        al algorithm from a Chinese technical paper that has been
	...
Cache (176 bytes)
www.freebsd.org/cgi/cvsweb.cgi/src/games/primes -> www.freebsd.org/cgi/cvsweb.cgi/src/games/primes/
Support src/games/primes/ Click on a directory to enter that directory. Click on a file to display its revision history and to get a chance to display diffs between revisi ons.