Programming Challenges - Page 7


Page 7 of 19 FirstFirst ... 3456789101117 ... LastLast
Results 91 to 105 of 279

Thread: Programming Challenges

  1. #91
    Join Date
    Aug 2002
    Location
    Essex, UK
    Posts
    937
    In Perl, you'd say:

    ($a, $b) = ($b, $a);

    which must be even cleverer than Python
    Registered Linux User #325947

    Check out Feather Linux, my distro.
    (Yes, it's shameless self promotion, deal with it )

  2. #92
    Join Date
    Jan 2000
    Location
    Houston, TX, USA
    Posts
    9,994
    Originally posted by o0zi
    In Perl, you'd say:

    ($a, $b) = ($b, $a);

    which must be even cleverer than Python
    Is this a joke?
    We love Sensei!!
    A 1:1 ratio of Arby's sauce to Horsey sauce must be maintained.
    Like Linux? Want to like it more? Try Debian
    Best. (Python.) IRC bot. ever.
    Geekology

  3. #93
    Join Date
    Aug 2002
    Location
    Essex, UK
    Posts
    937
    Sure hope so
    Registered Linux User #325947

    Check out Feather Linux, my distro.
    (Yes, it's shameless self promotion, deal with it )

  4. #94
    Join Date
    Sep 2003
    Location
    Edmonton, Alberta, Canada
    Posts
    311
    Originally posted by dchidelf
    Go ahead and burninate the countryside.
    Burninating the peasants,
    Burninating all the peoples,
    IN THEIR THACHED-ROOFED COTTAGES!
    thached-roof cottages
    And the Trogdor comes in the NIIIGHT!
    MOUNT TAPE U1439 ON B3, NO RING

    Registered Linux user # 31337!

  5. #95
    Join Date
    Nov 2002
    Location
    Flagstaff, AZ
    Posts
    103

    the greatest game ever programmed......

    So, I took mullet's suggestion (a couple pages back now) and decided to try and learn basic python by way of hangman.
    Here is a newbie's attempt at hangman in python.
    It meets all of mullet's specs, with the number of guesses excepted.

    you run the program
    python hangman.txt 'word or phrase for game'

    Then just follow the instructions.

    the one exception I made was that he wanted:
    The user has 2x as many guesses as there are letters in the word to guess the word.
    I won't tell you why I made the change, but if you play the game, you'll see soon enough.

    I welcome any and all comments/suggestions/complaints about my program. Since I'm a newbie at this, I consider it all constructive criticism.
    enjoy!
    -nathan

    p.s. oh yeah, and I think my next project will be a program that will keep track of a darts game of cricket for 2 or 3 players. we were playing darts the other night, and could've used it. so, if anyone else is up for it, that's my idea for a 'newbie challenge' maybe I'll get *****ious and learn some gui stuff too......
    Attached Files Attached Files

  6. #96
    Join Date
    Dec 2000
    Location
    Glasgow, Scotland
    Posts
    4,361
    OK - played the game now. Couple of comments to make:

    1. It only accepts a single word, not a whole phrase - if you put in something like 'star wars' it only takes the first word.

    2. It includes the quotes you put in - ie from the above it will actually take 'star as the word

    My suggested solution would be to start the game by asking them to enter a word or phrase, rather than using it as an argument for the program.

    Other than that, good job!
    mrBen "Carpe Aptenodytes"

    Linux User #216794

    My blog page

    3rd year running - get yourself to LugRadio Live 7th-8th July 2007, Wolverhampton, UK. The premier FLOSS community event.

  7. #97
    Join Date
    Nov 2002
    Location
    Flagstaff, AZ
    Posts
    103

    hmmmmmmmm..........

    Mr. Ben,
    when I play it on my computer, it seems to work as expected

    for example:

    [friedn@localhost programming]$ python hangman.txt 'some stuff'
    **** *****
    Please enter a guess:
    and the final line would be:

    Please enter a guess: f
    some stuff
    I believe you that it's different on your machine, but I don't know why. Any ideas on why?

    perplexing...........
    -nathan

  8. #98
    Join Date
    Dec 2000
    Location
    Glasgow, Scotland
    Posts
    4,361
    Probably because I'm running it at work under Windows........
    mrBen "Carpe Aptenodytes"

    Linux User #216794

    My blog page

    3rd year running - get yourself to LugRadio Live 7th-8th July 2007, Wolverhampton, UK. The premier FLOSS community event.

  9. #99
    Join Date
    Sep 2001
    Location
    Just for kicks
    Posts
    1,831
    Yeah, works fine for me. Probably has to do with how DOS (I'm guessing) takes in command like arguments. I don't think it recognizes single quotes. Try double quotes, mrBen.
    "You cannot invade the mainland United States. There would be a rifle behind each blade of grass." --Admiral Yamamoto, 1941

  10. #100
    Join Date
    Dec 2000
    Location
    Glasgow, Scotland
    Posts
    4,361
    Originally posted by sasKuatch
    Yeah, works fine for me. Probably has to do with how DOS (I'm guessing) takes in command like arguments. I don't think it recognizes single quotes. Try double quotes, mrBen.
    Aha!

    That worked.

    I retract all my previous comments.
    mrBen "Carpe Aptenodytes"

    Linux User #216794

    My blog page

    3rd year running - get yourself to LugRadio Live 7th-8th July 2007, Wolverhampton, UK. The premier FLOSS community event.

  11. #101
    Join Date
    May 2001
    Location
    Uh, I'm somewhere where I don't know where I am.
    Posts
    1,228
    Here's another answer to that square question I asked a while ago:

    Code:
    #include <iostream>
    
    int main() {
    	int square(1), diff(3);
    	while (square < 10000) {
    		std::cout << square << std::endl;
    		square += diff;
    		diff += 2;
    	}
    }
    if (i_forgot && this_is_about_code)
    language = c++;

  12. #102
    Join Date
    May 2001
    Location
    Uh, I'm somewhere where I don't know where I am.
    Posts
    1,228
    Ok, new challange, this one is basically a little parser with little to do with math. Mostly strings.

    Convert an IP address to a unsigned long(32-bit) and back.

    Criteria:

    1. The only functions you can use, you have to create yourself, no using libraries.

    2. The IP address can be given to you in any format, doesn't have to be XXX.XXX.XXX.XXX, it can also be XXX.XX.XX.XXX or anything else.

    I hope that's enough to discourage any "cheaters"
    if (i_forgot && this_is_about_code)
    language = c++;

  13. #103
    Join Date
    Dec 2000
    Location
    Glasgow, Scotland
    Posts
    4,361
    OK - this is a 5 minutes Python beginning (I'm at work - don't have any more time). It converts an IP address to a 32bit (unsigned) hex number.

    It doesn't convert back yet, but it would take an IPv6 address

    Code:
    #!/usr/bin/python
    
    ip="192.168.1.10"
    
    hexip=[hex(int(x))[2:] for x in ip.split('.')]
    
    for loop in range(len(hexip)):
         if len(hexip[loop])==1:
              hexip[loop]="0"+hexip[loop]
    
    print "".join(hexip)
    mrBen "Carpe Aptenodytes"

    Linux User #216794

    My blog page

    3rd year running - get yourself to LugRadio Live 7th-8th July 2007, Wolverhampton, UK. The premier FLOSS community event.

  14. #104
    Join Date
    May 2001
    Location
    Uh, I'm somewhere where I don't know where I am.
    Posts
    1,228
    Nice Mr. Ben, but aren't split, len and range functions? I'll let it slide though. Aren't there any C/C++/JAVA programers who want to represent?

    Ok, next. Now we have our IP address in unsigned long form and string form.

    Let's say a user says that he/she wants to increment the value of part of the ip address by pointing at a position in the string and incrementing it there. (The ip string is now always XXX.XXX.XXX.XXX)

    I.E. "192.168.001.010"
    ^
    changes to

    "202.168.001.010"

    But when the user would select 1 from 192, it doesn't increment since 292 is out of range.

    So here's kinda how it'll work,

    OUTPUT: 192.168.001.010
    INPUT: index of decimal user wishes to increment
    OUTPUT: 202.168.001.010

    In the background, you'll have the IP address stored in a unsigned long/int (32-bit) and only convert to string to output.

    The REAL challange: Write it in a few lines as you can without using ANY functions(other than those you create)

    P.S. Getting these challanges from portions of code I write at work, in case someone might think is hw or something. I did this the actual work, not i/o, in 6 lines of code.

    [edit]speaking of work, maybe i should do some...[/edit]
    if (i_forgot && this_is_about_code)
    language = c++;

  15. #105
    Join Date
    Jan 2000
    Location
    Houston, TX, USA
    Posts
    9,994
    Originally posted by tecknophreak
    Nice Mr. Ben, but aren't split, len and range functions? I'll let it slide though.

    Yeah, but so are hex and int. But they are all builtins, so it's not like he's using a library or something.

    Also, mrBen, yours wouldn't take an ipv6 address and do it because those use ':' as the separator and not '.' I actually think I posted the code to do just this very challenge on this board (or somewhere) not too long ago.
    We love Sensei!!
    A 1:1 ratio of Arby's sauce to Horsey sauce must be maintained.
    Like Linux? Want to like it more? Try Debian
    Best. (Python.) IRC bot. ever.
    Geekology

Posting Permissions

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