Programming Challenges - Page 4


Page 4 of 19 FirstFirst 1234567814 ... LastLast
Results 46 to 60 of 279

Thread: Programming Challenges

  1. #46
    Join Date
    May 2001
    Location
    Uh, I'm somewhere where I don't know where I am.
    Posts
    1,228
    sorry, stuck with the shifting counter, non-shifting is quicker, believe it or not

    Code:
    unsigned int reverseBits(unsigned int x) { 
         unsigned int res(0), cntr(32); 
         while (cntr--) { 
              res <<= 1; 
              res |= x & 1; 
              x >>= 1; 
         } 
         return res; 
    }
    [/B][/QUOTE]
    if (i_forgot && this_is_about_code)
    language = c++;

  2. #47
    Join Date
    Mar 2003
    Location
    Tampa, FL USA
    Posts
    2,193
    Nice job, techno.

  3. #48
    Join Date
    Mar 2001
    Posts
    729
    sorry, stuck with the shifting counter, non-shifting is quicker, believe it or not
    Heh, that makes me think of one.. Come up with bitwise-shift and increment (or decrement) functions, using only the bitwise operations. (that doesn't include >> )

  4. #49
    Join Date
    May 2001
    Location
    Uh, I'm somewhere where I don't know where I am.
    Posts
    1,228
    Originally posted by Sepero
    Nice job, techno.
    Why's everyone always got to spell my name wrong? Oh, right maybe cause I spelled it wrong in the first place.
    if (i_forgot && this_is_about_code)
    language = c++;

  5. #50
    Join Date
    Aug 2002
    Location
    Essex, UK
    Posts
    937
    I get that all the time as well, teckno I've had oozi, OOzi, Oozi, oozy...
    Let's get it right people, it's an o, then a zero, then a z, then an i. But Rob will do fine

  6. #51
    Join Date
    May 2001
    Location
    Uh, I'm somewhere where I don't know where I am.
    Posts
    1,228
    Originally posted by Strogian
    Heh, that makes me think of one.. Come up with bitwise-shift and increment (or decrement) functions, using only the bitwise operations. (that doesn't include >> )
    can it include << ? So you're looking for a counter?

    so we can use ~ ^ & | and what not, but no >>.

    Just making sure I have this correct. I'll be spending the next 4 hours running long tests which need barely to no interaction. This'll give me something to do.
    if (i_forgot && this_is_about_code)
    language = c++;

  7. #52
    Join Date
    Mar 2001
    Posts
    729
    Well, I want functions that replace the ++ and >> operations, so naturally you shouldn't use ++ or >> in the function. (<< and -- are also no-good, but I don't think they'd help you anyway )

  8. #53
    Join Date
    Jan 2001
    Location
    Somewhere in middle America
    Posts
    164
    Do you want replacments for both pre and post increments? (ie ++x and x++)

  9. #54
    Join Date
    Mar 2001
    Posts
    729
    Oh, wow. I'd never thought of that. Hey, if you can do it, go ahead!

  10. #55
    Join Date
    Aug 2003
    Posts
    5
    Looks like you have had some interesting theoretical/mathematical challenges, so far. Heres something practical:

    Define a simple hangman program
    It takes one word as its only parameter
    The user has 2x as many guesses as there are letters in the word to guess the word. the user enters a letter on stdin, the program prints out the word, with that guess and any previous ones revealed as letters in the word, other letter are replaced by *. Also printed out is the number of guesses left before the user runs out of time. So a sample run may go as follows:

    hangman sameple
    e
    ***e**e
    you have 13 guesses remaining
    s
    s**e**e

    etc.

    have fun, this is easy compared to some earlier challenges and will hopefully less able programmers a chance to test their skills.

    mullet

  11. #56
    Join Date
    Jun 2003
    Posts
    173
    I deciphered Sepero's first code. I mostly figured it out without a program but used it just to help. Anyway, I have attached the code to decipher the code in Perl. Did anyone else get it?
    Attached Files Attached Files

  12. #57
    Join Date
    Jan 2000
    Location
    Houston, TX, USA
    Posts
    9,994
    The python rot13 can be made way shorter:

    Code:
    def rot13(s):
        return s.encode('rot13')
    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

  13. #58
    Join Date
    Apr 2002
    Posts
    259
    Originally posted by Strike
    The python rot13 can be made way shorter:

    Code:
    def rot13(s):
        return s.encode('rot13')
    I actually mention that in the original post...
    OggVorbis gets mobile...
    http://www.gentoo.org
    Is that a penquin in your pocket or are you just happy to see me?

  14. #59
    Join Date
    Jan 2003
    Location
    Central Florida
    Posts
    364
    Heres a java solution for the add 2 numbers without +

    Code:
    public int add(int a, int b){
    
    BigInteger bigA = new BigInteger(a);
    BigInteger bigB = new BigInteger(b);
    BigInteger ans = bigA.add(bigB);
    
    return ans.intValue();
    
    }
    Sorry for no indent, I did this in galeon
    friend: first, it takes 2 minutes to load google; second, it take another 2 minutes to search for something; and third, once it finally stops searching, the Search Results pages come out screwed up (where it shows the google logo up top, the search form, and then some random characters like "[47]GGH9")
    zdude255: nope
    friend: damn...
    zdude255: all your viruses are belong to you
    friend: ...
    friend: not funny

  15. #60
    Join Date
    Jul 2003
    Posts
    28
    Design a binary code and write an encoder and decoder such that if as many as 3 bits of a codeword are encoded with errors, the decoder can correct the codeword. Obviously the only purpose of the encoder here is to take a codeword and mess it up in no more than three places. Your word length can be whatever you want, but the number of codewords needs to be at least 4. The shorter the word length and greater the number of codewords, the smarter your code is of course .

Posting Permissions

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