hi. i have started this thread for people to post programming challenges for others to solve. the programming challenges are exercises for people to practice programming. once you have completed a challenge post your code. when you are posting your code, please quote the challenge that you are responding to.
happy coding!
i was once trapped by windows, but linux set me free...
Yeah, it would, as long as *_a and *_b are both positive. If they're negative, you can underflow and lose a bit off the top, but otherwise I think you're safe.
Originally posted by grady swap two integers without using a temporary variable.
This thread is a cool idea. Here is my solution.
- Suramya
--------------------------------------------------
My Website: http://www.suramya.com
My Blog: http://www.suramya.com/blog
Registered Linux User #: 309391
--------------------------------------------------
*************************************************
Disclaimer:
Any errors in spelling, tact, or fact are transmission errors.
*************************************************
Write a rot13 implementation, those'd be cool to see. Take stdin, transform it according to rot13 (changing nothing if the symbol isn't a letter, but rotating both uppercase and lowercase letters, separately), and print it to stdout. This program makes a nifty tool when people start talking in threads like this:
Ubj vf rirelbar gbqnl?
Bu, abg onq, ohg V jbaqre vs nalobql ryfr trgf guvf guernq?
V'z fher gurl qba'g, ohg bu jryy.
Of course, I doubt anybody would do that anymore (that was something that happened more in the old G:OT forum), but still...
Here's my Perl solution to swapping two variables:
($a, $b) = ($b, $a);
:D
Web server did you say? Hmm...
#!/usr/bin/perl -w
use HTTP::Daemon;
$HTTPserver=HTTP::Daemon->new(Timeout =>600);
print "My url is: ",$HTTPserver->url,".\n";
while ($HTTPclient = $HTTPserver->accept) {
$HTTPclient->autoflush(1);
print $HTTPclient
'<HTML><HEAD><TITLE>
Welcome to my web server!
</TITLE></HEAD><BODY>
This web server was written in Perl.
</BODY></HTML>';
$HTTPclient->close;
}
#!/usr/bin/python
def rot13(text):
new_text = []
for x in text[0:]:
up = False
if x.isupper():
x = x.lower()
up = True
byte = ord(x)
if byte >= ord('a') and byte <= ord('z'):
x = chr((byte - ord('a') + 13) % 26 + ord('a'))
if up:
x = x.upper()
new_text.append(x)
return ''.join(new_text)
text = raw_input('Enter some text: ')
print rot13(text)
Hmm, my school had an upper level CS course called Applied Algorithms. The course basically consisted of a list of 30 specific programs handed out at the beginning of the semester, of which you had to write any 20 of them before the end. Class time would be spent clarifying rules, discussing implementation problems, advice, etc. I never took the course, but I am good friends with the professor. I might be able to get and post these programs when I visit the school again in a couple of weeks, if anyone is interested.
[edit] Several, but not all, of these programs had very simple implementations (less than a page in c++), but had speed requirments (terms of Bigo) that make them more complicated.
I'm really f'lar. Just at work and forgot my password for the moment.