Programming Challenges - Page 16


Page 16 of 19 FirstFirst ... 61213141516171819 LastLast
Results 226 to 240 of 279

Thread: Programming Challenges

  1. #226
    Join Date
    Apr 2001
    Location
    SF Bay Area, CA
    Posts
    14,947
    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.

  2. #227
    Join Date
    Mar 2003
    Location
    Tampa, FL USA
    Posts
    2,193
    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.
    Last edited by Sepero; 11-08-2005 at 02:11 PM.

  3. #228
    Join Date
    Mar 2005
    Location
    asdhsadgas
    Posts
    197
    is there any ideea in inverse(rac)=car and vroooom appearing in both ends ?
    i'm stupid

  4. #229
    Join Date
    May 2001
    Location
    Uh, I'm somewhere where I don't know where I am.
    Posts
    1,228
    Whew! I followed all the rules, right? A single recursive loop and print a single char at a time?

    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);
    }
    if (i_forgot && this_is_about_code)
    language = c++;

  5. #230
    Join Date
    Mar 2003
    Location
    Tampa, FL USA
    Posts
    2,193
    Quote Originally Posted by tecknophreak
    Whew! I followed all the rules, right? A single recursive loop and print a single char at a time?
    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"
    Last edited by Sepero; 11-07-2005 at 01:28 PM.

  6. #231
    Join Date
    Mar 2005
    Location
    asdhsadgas
    Posts
    197
    this took about 10minutes

    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);
    }
    i'm stupid

  7. #232
    Join Date
    Mar 2003
    Location
    Tampa, FL USA
    Posts
    2,193
    Nice spx2. I hadn't expected a loop like that. There is definitely more than one way to do it.

  8. #233
    Join Date
    Mar 2005
    Location
    asdhsadgas
    Posts
    197
    well,im really good with algorithms...atleast i was
    i'm retired now from contests and such.
    if you like it thank you.
    i'm stupid

  9. #234
    Join Date
    Mar 2005
    Location
    asdhsadgas
    Posts
    197
    is there any better way to do it ?
    i'm stupid

  10. #235
    Join Date
    Mar 2003
    Location
    Tampa, FL USA
    Posts
    2,193
    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. #236
    Join Date
    Mar 2005
    Location
    asdhsadgas
    Posts
    197
    we shall leave that to other people(the optimization you talk about)
    i'm stupid

  12. #237
    Join Date
    Mar 2003
    Location
    Tampa, FL USA
    Posts
    2,193
    Yeah, I kinda wanna do it myself, but at the same time, I don't wanna spoil the fun for anyone else.

  13. #238
    Join Date
    Jun 2003
    Posts
    173
    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;
    }
    Last edited by lagdawg; 03-13-2006 at 10:53 AM. Reason: Typographical errors.

  14. #239
    Join Date
    Sep 2003
    Location
    Rochester, MN
    Posts
    3,607
    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...

  15. #240
    Join Date
    May 2001
    Location
    Uh, I'm somewhere where I don't know where I am.
    Posts
    1,228
    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++.
    if (i_forgot && this_is_about_code)
    language = c++;

Posting Permissions

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