Programming Challenges - Page 12


Page 12 of 19 FirstFirst ... 28910111213141516 ... LastLast
Results 166 to 180 of 279

Thread: Programming Challenges

  1. #166
    Join Date
    May 2001
    Location
    Uh, I'm somewhere where I don't know where I am.
    Posts
    1,228
    here's a fun one for any computer/math nerd, how about a virtual enigma? no need for a plugboard, but 3 encoding disks plus the reflection disk.

    FYI - for those who don't know the Enigma was a German encryption machine used in WWII. But it's relatively simple in construct.
    if (i_forgot && this_is_about_code)
    language = c++;

  2. #167
    Join Date
    Aug 2002
    Location
    Cayman Islands
    Posts
    681
    Scotty: Captain, we din' can reference it!
    Kirk: Analysis, Mr. Spock?
    Spock: Captain, it doesn't appear in the symbol table.
    Kirk: Then it's of external origin?
    Spock: Affirmative.
    Kirk: Mr. Sulu, go to pass two.
    Sulu: Aye aye, sir, going to pass two.

  3. #168
    Join Date
    May 2001
    Location
    Uh, I'm somewhere where I don't know where I am.
    Posts
    1,228
    Hey now, is that yours or are you just showing someone else's final project?

    A lot of these challenges have already been done, like the next perm one I did around the beginning of last year. But it gives people who want a challenge something to do....like myself.
    if (i_forgot && this_is_about_code)
    language = c++;

  4. #169
    Join Date
    Aug 2002
    Location
    Cayman Islands
    Posts
    681
    Oops, sorry, I didn't mean to give the impression that that was mine. Never mind. I'll go away now.

    Scotty: Captain, we din' can reference it!
    Kirk: Analysis, Mr. Spock?
    Spock: Captain, it doesn't appear in the symbol table.
    Kirk: Then it's of external origin?
    Spock: Affirmative.
    Kirk: Mr. Sulu, go to pass two.
    Sulu: Aye aye, sir, going to pass two.

  5. #170
    Join Date
    Nov 2003
    Posts
    81
    Random Quote program
    <><

  6. #171
    Join Date
    Nov 2003
    Posts
    81
    #include <iostream>
    #include <string>
    #include <time>
    #include <math>
    #include <vector>
    #include <fstream>

    using namespace std;
    void error(const char*p, const char *p2="")
    {
    cerr << p << " " << p2 << "\n";
    exit(1);
    }
    int main(int argc, char *argv[])
    {
    vector<string> quotes(0);
    int items=0;
    string q;
    if (argc < 2)
    error("no filename given");
    ifstream file(argv[1]);
    if(!file)
    error("can't open", argv[1]);
    char ch;
    while (file.get(ch)) {
    if (ch=='\n'){
    if(items % 100 == 0)
    quotes.resize(quotes.size()+100); //increase the size of the vector
    quotes[items++]=q;
    q="";
    }else
    q+=ch;
    }
    int n;
    srand(time(0));
    n=rand()%items;
    cout << quotes[n] <<endl;

    return 0;
    }
    <><

  7. #172
    Join Date
    Mar 2003
    Location
    Tampa, FL USA
    Posts
    2,193
    Originally posted by Enlighted One
    Random Quote program
    Code:
    #!/bin/bash
    # pass the file with quotes as an argument
    
    # range = the lenth of quote file
    range=`cat $1 |  wc -l`
    # line = a random number between one and range
    let "line=($RANDOM%$range)+1"
    # output the random line
    sed $line'!d' $1
    Can it get any simpler than that?
    I must admit that I'm pretty proud of myself.

    Now somebody else will come along and make it simpler... heheh

  8. #173
    Join Date
    Apr 2001
    Location
    SF Bay Area, CA
    Posts
    14,936
    Code:
    /usr/games/fortune

  9. #174
    Join Date
    Dec 2003
    Location
    Colorado
    Posts
    149
    damn I love slackware.... making program challenges easier every day.
    Registered Linux User: #342515

    Slackware 10 - kernel 2.6.10

    AMD Athlon 3000+
    512 RAM pc2700
    NVIDIA GeForce2 Integrated

    www.rex-pro.com For life!!!

  10. #175
    Join Date
    Sep 2002
    Posts
    974
    There's a theorem from graph theory that sums this um very nicely, no need to do brute search methods...

    ::goes to track down his graph theory book::

    darn can't find it. Something to do with the degree of every vertex added together is 2 times the total number of edges. Therefore when doing person-person relationships, it's only possible for an even amount (it's impossible for there to be 7 people at a party and each one to know exactly 3 others).

    Something like that


    Originally posted by duncanbojangles
    Okay, I read this book "Archimede's Revenge" a couple weeks ago and it has a buttload of stuff like this, basically all this number and geometry thoery and stuff. Good reading. Here's one of the problems:
    "Suppose there are 100 people in a group, and you want to find out if 50 of them know each other".

    This can be done on paper by drawing 100 dots, connecting lines between people that know each other, and looking for all the people that know 49 others that all know the other 49.

    Yeah, it's one of those problems that as the set of people gets larger, the amount of work that it would require to find the answer increases exponentially.

    Find an algorithm that finds the answer in a manner such that the answer is found in an amount of work like n * number of people, rather than number of people ^ n.

    I was working on a method where you make a table, with all the people in the columns and all the people in the rows. Mark an X in the appropriate spot where people know one another(including that person knowing themself). Then remove all people that have less than the needed number of associations. Then you are left with all the people knowing the amount of people needed to associate with. Then, if all the spaces are filled, the answer is 'yes', they all know each other. I belive this approach is not exponential, but I could be wrong.

  11. #176
    Join Date
    Oct 2004
    Posts
    28
    Originally posted by grady
    You can waste alot of multiplications evaluating a polynomial such as a x^3+b x^2+ c x + d , but its possible to evaluate an n degree polynomial with only n multiplications. Can you figure it out? Don't forget that computing x^3 takes 3 multiplications in itself.
    Don't know if it has been said before, and I am really late on this thread...but anyway. Just learned how to do this in high school....

    say z is what you are evaluating for

    ax^3+bx^2+cx+d

    a*z = m
    m+b = n
    n*z = o
    o+c = p
    p*z = q
    q+d = r

    and r is the answer.


    example-

    2x^3+x^3+4x+2

    For 3

    putting it in = 77

    2 * 3 = 6
    6 + 1 = 7
    7 * 3 = 21
    21 + 4 = 25
    25 * 3 = 75
    75 + 2 = 77

    Anyway, it was probably already done, and I probably explained it way too much...but I'm bored anyway .
    Last edited by gobeavers; 11-21-2004 at 02:32 AM.

  12. #177
    Join Date
    Apr 2001
    Location
    SF Bay Area, CA
    Posts
    14,936
    Originally posted by gobeavers
    say z is what you are evaluating for

    ax^3+bx^2+cx+d

    a*z = m
    m+b = n
    n*z = o
    o+c = p
    p*z = q
    q+d = r

    and r is the answer.
    So in other words, you "factor" ax^3 + bx^2 + cx + d into:

    (((ax + b)x + c)x + d

    It's not a true factorization, but it does reduce into n multiplications.

    (FWIW: This question was asked so long ago that I don't remember if there was an answer to it posted already either! )

  13. #178
    Join Date
    Oct 2004
    Posts
    28
    Originally posted by bwkaz
    So in other words, you "factor" ax^3 + bx^2 + cx + d into:

    (((ax + b)x + c)x + d

    It's not a true factorization, but it does reduce into n multiplications.

    (FWIW: This question was asked so long ago that I don't remember if there was an answer to it posted already either! )
    I don't konw...its something called "synthetic substitution" using some guys root theorem (or something like that)....we just learned it in pre-calc.

    Basically, you divide the polynomial by x-z, z being what you are evaluating for, and the remainder is the answer.

  14. #179
    Join Date
    Nov 2003
    Posts
    81
    This piece of code is awesome! Compile it and run it!

    //The Beapanator!!!!!!!

    #include <iostream>

    using namespace std;

    int main()
    {
    int w, n;
    char y;
    cout << "Would you like to annoy the people around you?";
    cin >> y;
    if(y=='y')
    {
    cout << "How many times?";
    cin >> n;
    for(n; n!=0; n--)
    {
    cout << "\a";
    }
    }
    else
    return 0;
    }
    <><

  15. #180
    Join Date
    Mar 2003
    Location
    Tampa, FL USA
    Posts
    2,193
    Enlighted One:
    using namespace std;
    bwkaz, don't you have anything to say about this?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •