Almost Daily Contest #3

This is a discussion on Almost Daily Contest #3 within the Contests Board forums, part of the Community Boards category; For Everyone The task is very simple. Read a file of numbers and print the average. There are only two ...

  1. #1
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796

    Almost Daily Contest #3

    For Everyone

    The task is very simple. Read a file of numbers and print the average. There are only two rules.

    1) Run as fast as humanly possible.
    2) Use C or C++ (inline assembly allowed)

    Be sure to mention what compiler you use if you do anything nonportable. If I can't get your code to compile, it will be disqualified, so the more info I have on what worked for you the better.

    Contest Ends: Sunday, August 17, 2003
    My best code is written with the delete key.

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    does that mean we can use Windows API to accomplish it? It sounds like you're saying portability is not an issue on this one.

    also, file of numbers of what format. 32 bit integer? ASCII?
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    How is the file formatted?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    How much precision do we need in the average? How many significant decimal places, if you're requiring something other than what an int, float or double can return?
    Away.

  5. #5
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    Seems easy when we get the file format and specific specs. lol

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    10
    just taking a wild guess here, but I bet they can be of any size (as in you are to use the program from the previous contest).

    since i just found out about these that kinda bothers me because now I would need to go back and write the program for the contest in order to do well in this one. fortunately it won't be too much to do since I only need addition and division for now.
    ???

  7. #7
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    hmm... dosent this feel like a contest just for the sake of a contest... no hard feelings here..

  8. #8
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Ok, can someone give a quick lesson in assembly file handling
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >It sounds like you're saying portability is not an issue on this one.
    Portability is not an issue. Provided I can manage to get your entry compiled and running on one of my systems, all is well. Elegance is also ignored. You can write the ugliest program that uses undefined behavior to get what you want and win if it's the fastest.

    >How is the file formatted?
    Just a list of numbers separated by whitespace.

    >How much precision do we need in the average. A 32 bit variable should be able to handle it. I'll be treating the numbers as int though, so there will be no signifigant decimal places.

    >Seems easy when we get the file format and specific specs. lol
    If you go with an obvious (read as "slow") solution.

    >doesnt this feel like a contest just for the sake of a contest...
    Just keeping things interesting by thowing in a wildcard here and there.
    My best code is written with the delete key.

  10. #10
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    ascii integers separated by spaces then. ok.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  11. #11
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    can we have a sample test file?
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  12. #12
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >can we have a sample test file?
    You can make one using the same program I used. I can't post the actual file because it's too large:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(void)
    {
        FILE *out;
        int   i;
    
        out = fopen("numbers.txt", "w");
    
        if (out == NULL) {
            perror("fopen");
            return EXIT_FAILURE;
        }
    
        for (i = 0; i < 1000000; i++)
            fprintf(out, "%d ", rand() % 50 + 1);
    
        if (fclose(out) != 0) {
            perror("fclose");
            return EXIT_FAILURE;
        }
    
        return EXIT_SUCCESS;
    }
    The numbers really don't matter as long as the total is less than INT_MAX with no overflow.
    My best code is written with the delete key.

  13. #13
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    My program:
    Code:
    #include <stdio.h>
    #include <conio.h>
    
    int main (void)
    {
    printf("25");
    getche();
    }
    100% accurate since you never seeded your rand() for then number file.

  14. #14
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >100% accurate since you never seeded your rand() for then number file.
    Read a file of numbers and print the average.
    I do require that you actually read the file. But nice try.
    My best code is written with the delete key.

  15. #15
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    Originally posted by Thantos
    My program:
    Code:
    #include <stdio.h>
    #include <conio.h>
    
    int main (void)
    {
    printf("25");
    getche();
    }
    100% accurate since you never seeded your rand() for then number file.
    But the numbers don't need to be random. They're just a bunch of numbers to test with.

    //edit: oic, nm

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Almost Daily Contest Details
    By dagdarian in forum Contests Board
    Replies: 4
    Last Post: 01-25-2005, 04:03 AM
  2. Almost Daily Contest Details
    By Prelude in forum Contests Board
    Replies: 29
    Last Post: 09-19-2004, 10:32 PM
  3. Almost Daily Contest #4
    By Prelude in forum Contests Board
    Replies: 35
    Last Post: 08-25-2003, 08:54 AM
  4. Almost Daily Contest #2
    By Prelude in forum Contests Board
    Replies: 37
    Last Post: 08-09-2003, 10:51 PM
  5. Almost Daily Contest #1
    By Prelude in forum Contests Board
    Replies: 32
    Last Post: 08-05-2003, 08:34 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21