Updates from July, 2008 Toggle Comment Threads | Keyboard Shortcuts

  • tech0x20 4:34 pm on July 20, 2008 Permalink | Reply  

    Optimized prime number generator 

    Same specs as previous system, 8 hours to find all primes to ULONG_MAX.


    #include <stdio.h>
    #include <malloc.h>
    #include <limits.h>
    #include <math.h>

    struct linked_list
    {
    unsigned long number;
    struct linked_list *next;
    };

    int main(int argc, char **argv)
    {
    unsigned long divisor, max_divisor, prime_test;
    unsigned long max_prime_to_store;
    struct linked_list *first=NULL, *current=NULL, *last=NULL;

    first=(struct linked_list *)malloc(sizeof(struct linked_list));
    first->number = 2L;
    first->next = NULL;
    last = first;
    printf("%lun", 2L);

    max_prime_to_store = 1L + sqrt(ULONG_MAX);

    for(prime_test = 3L; prime_test < ULONG_MAX; prime_test+=2L)
    {
    max_divisor=1L+sqrt(prime_test);
    for(current = first; current && current->number <= max_divisor; current = current->next)
    {
    if(prime_test % current->number == 0)
    {
    break;
    }
    }
    if(!current || current->number > max_divisor)
    {
    if(prime_test <= max_prime_to_store)
    {
    last->next = (struct linked_list *)malloc(sizeof(struct linked_list));
    last = last->next;
    last->next = NULL;
    last->number = prime_test;
    }
    printf("%lun", prime_test);
    }
    }
    return 0;
    }
     
  • tech0x20 8:23 am on July 18, 2008 Permalink | Reply  

    I miss C programming. Program to find prime numbers 

    Uses unsigned long long, goes up to ULONG_LONG_MAX.

    Intel Core Duo 2 processor, running Cygwin on Windows XP, and compiled using gcc 3.4.4. Stops at first million results due to time. Can reasonably get to 10 million, if you’re willing to wait.


    #include <stdio.h>
    #include <math.h>
    #include <limits.h>

    int main(int argc, char **argv)
    {
    unsigned long long divisor, max_divisor, prime_test;
    int break_time = 0;

    printf("%llun", 2LL);
    for(prime_test = 3LL; prime_test < ULONG_LONG_MAX; prime_test+=2LL)
    {
    max_divisor=1LL+sqrt(prime_test);
    for(divisor=3LL;divisor <= max_divisor; divisor+=2LL)
    {
    if(prime_test % divisor == 0)
    {
    break;
    }
    }
    if(divisor >= max_divisor)
    {
    printf("%llun", prime_test);
    }
    else
    {
    continue;
    }
    break_time++;
    if(break_time == 999999)
    {
    break;
    }
    }
    return 0;
    }
     
  • tech0x20 8:41 pm on March 7, 2008 Permalink | Reply  

    “Playtime” project: Porting Didiwiki to C#.NET 

    I’m hoping to find time to throw at least a quick port of DidiWiki to C#.NET together.

    Reference 1: Creating your own Web Server using C# – This article is from 2001, so there might be a significantly better way of doing things.

    Update: This CodeGuru page looks like a more original version of the same page.

    Reference 2: Didiwiki Source Code that I’ve saved off. Original maintainer is no longer maintaining.

     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel
%d bloggers like this: