Results 1 to 3 of 3

Thread: programming puzzle

  1. #1
    Join Date
    Apr 2009
    Location
    Germany
    Beans
    2,134
    Distro
    Ubuntu Development Release

    programming puzzle

    hi, a little puzzle for you, I hope not all know it already:

    Code:
    int i, n = 20; 
    for (i=0; i<n; i--) 
    { 
    	cout << "x" << endl; 
    }
    find three different solutions to get this code to print out 20 times x by only replacing a single character with another single character.
    No adding of characters.

    Usually people find two possibilities quite quickly but the third can be tricky

  2. #2
    Join Date
    Dec 2008
    Location
    Stanford
    Beans
    25
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: programming puzzle

    Code:
    int i, n = 20; 
    for (i=0; i<n; n--) 
    { 
    	cout << "x" << endl; 
    }
    Code:
    int i, n = 20; 
    for (i=0; i+n; i--) 
    { 
    	cout << "x" << endl; 
    }
    Code:
    int i, n = 20; 
    for (i=0;-i<n; i--) 
    { 
    	cout << "x" << endl; 
    }

  3. #3
    Join Date
    May 2009
    Beans
    60

    Re: programming puzzle

    Victor got it. Very good programmer. I didn't know about Slerp until now.

Bookmarks

Posting Permissions

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