# Programming Challenges

Show 40 post(s) from this thread on one page
• 11-02-2005, 06:04 PM
bwkaz
As long as *_a + *_b <= INT_MAX, anyway... ;)

Er, well, wait, maybe it would still work.

...

...

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.
• 11-04-2005, 07:46 AM
Sepero
Using a single recursive loop, Print this:
vroooom racecar vroooom

You can use a string or array, but it should be printed one character at a time.
:)
• 11-07-2005, 04:12 AM
spx2
is there any ideea in inverse(rac)=car and vroooom appearing in both ends ?
• 11-07-2005, 08:44 AM
tecknophreak
Whew! I followed all the rules, right? A single recursive loop and print a single char at a time? :D

Code:

```#include <stdio.h> #include <string.h> char str[] = "vroooom racecar vroooom"; void printStr(int pos) {         if (pos == strlen(str)) {                 return;         }         printf("%c", str[pos]);         printStr(pos + 1); } int main() {         printStr(0); }```
• 11-07-2005, 11:51 AM
Sepero
Quote:

Originally Posted by tecknophreak
Whew! I followed all the rules, right? A single recursive loop and print a single char at a time? :D

LOL, yeah. Now this time, only use the string "vroooom race".

EDIT:
Good job technophreak. I guess I didn't make myself understood as well as I thought.
I'll try again. :)

Using:
One recursive function(/method), and the string(/array) "vroooom race"

Print:
"vroooom racecar vroooom"
• 11-07-2005, 01:47 PM
spx2

i hope you like it

Code:

```#include <stdio.h> #include <string.h> char s[] = "vroooom race"; int t=0; int h=0; void f(char t) {printf("%c", t);} void H(int p) { if(s[p]!=0)           {           t++;           f(s[p]);           H(p+1);           h++;           if(t==1){                     if(h<=5)                     f(s[p]);                     else                     f(s[strlen(s)-p-6]);                     }                              else t=1;           } } int main() {         H(0);         scanf("%d",1); }```
• 11-08-2005, 08:20 AM
Sepero
Nice spx2. I hadn't expected a loop like that. There is definitely more than one way to do it. :)
• 11-08-2005, 08:26 AM
spx2
well,im really good with algorithms...atleast i was
i'm retired now from contests and such.
if you like it thank you.
• 11-08-2005, 10:05 AM
spx2
is there any better way to do it ?
• 11-08-2005, 12:56 PM
Sepero
Quote:

Originally Posted by spx2
is there any better way to do it ?

If I may take that as a personal challenge... ;)

Code:

```#include <stdio.h> #include <string.h> char s[] = "vroooom race"; void f(char t) { printf("%c", t); } void H(int p) {   if(s[p]!=0)     {         f(s[p]); // print "vroooom race"         H(p+1);         if(p<11 && p>6)           f(s[p]); // print "car "         else if(p<=6)           f(s[6-p]); // print "vroooom"     } } int main() {     H(0);   printf("\n"); }```
Though, it can still be done differently. The original way that I was thinking, was to somehow switch the "vr" and "m" during the second half of recursion.
• 11-09-2005, 09:49 AM
spx2
we shall leave that to other people(the optimization you talk about)
• 11-09-2005, 01:56 PM
Sepero
Yeah, I kinda wanna do it myself, but at the same time, I don't wanna spoil the fun for anyone else. ;)
• 03-13-2006, 09:51 AM
lagdawg
Here is my solution with reversing vrooom.

Code:

```#include<stdio.h> #include<string.h> char str[] = "vrooom race"; void invVrooom () {         char str2 [] = "mooorv";         for(int x = 0; x < 6; x++) { str[x] = str2[x]; }         return; } void printString(int pos) {         printf("%c",str[pos]);                 if(str[pos] == 'e') {                 invVrooom();                 return;         } else {                 printString(pos+1);         }         printf("%c",str[pos]);         return; } int main (void) {         printString(0);         printf("\n");         return 0; }```
• 03-13-2006, 11:13 AM
cybertron
Is anybody else reminded of the Ralph S. Mouse books by this challenge? Teachers used to read them to us in like 2nd grade and there was a mouse who had a toy motorcycle that he could drive by saying "vrooom", and then one day he got stuck in a corner and couldn't turn around, so to back up he said "mooorv".

Funny that I remember that this many years later...:)
• 04-07-2006, 05:04 PM
tecknophreak
Ok, here's one. You know a quote has a ceaser(sp?) cipher on it, you just don't know what is is. You have to run a program/script and have the program figure out what the correct cipher is for the quote. The program will have two outputs the cipher, i.e. Shift +24, and the answer.

Here's a fun quote: zypr: "ufyr'q qylry'q jgrrjc fcjncp bmgle rm rfyr bme? jmmiq jgic fc'q rpwgle rm hskn mtcp, zsr fc ayl'r osgrc kyic gr."

I'd really like to see the script for this one since I'm sure it's quicker/easier than c/c++.
Show 40 post(s) from this thread on one page