Programming Challenges - Page 4

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]

2. Nice job, techno.

3. Registered User
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 >> )

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.

5. 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

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.

7. Registered User
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. Do you want replacments for both pre and post increments? (ie ++x and x++)

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

10. Registered User
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. Registered User
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?

12. The python rot13 can be made way shorter:

Code:
def rot13(s):
return s.encode('rot13')

13. Registered User
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...

14. 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);

return ans.intValue();

}
Sorry for no indent, I did this in galeon

15. Registered User
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
•