C/C++

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • More Solutions

    11 answers - 660 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    I was asked to submit atleast 5 solutions for the following problem:
    By Replacing/Adding or deleting only one character from the following
    code snippet, make it print tttttttttttttttttttt (20 times)
    #include<stdio.h>
    int main()
    {
    int k, j=20;
    for(k=0;k<j;k--)
    printf("t);
    printf("\n");
    return 0;
    }
    I came up with 3 solutions which were
    1. instead of for(k=0;k<j;k--) write for(k=0;k<j;j--)
    2. instead of for(k=0;k<j;k--) write for(k=0;-k<j;k--)
    3.instead of for(k=0;k<j;k--) write for(k=0;k+j;k--)
    Can anyone suggest me 2 more solutions?
  • No.1 | | 1020 bytes | |

    Romram <sajjanharudit@gmail.comwrote:
    I was asked to submit atleast 5 solutions for the following problem:

    By Replacing/Adding or deleting only one character from the following
    code snippet, make it print tttttttttttttttttttt (20 times)

    #include<stdio.h>

    int main()
    {
    int k, j=20;
    for(k=0;k<j;k--)
    printf("t);
    printf("\n");
    return 0;
    }

    I assume you forget the closing quote in the first printf(). Please make
    sure that the code you post actually is correct and compiles.

    1. instead of for(k=0;k<j;k--) write for(k=0;k<j;j--)

    2. instead of for(k=0;k<j;k--) write for(k=0;-k<j;k--)

    3.instead of for(k=0;k<j;k--) write for(k=0;k+j;k--)

    Can anyone suggest me 2 more solutions?

    instead of for(k=0;k<j;k--) write for(k=0;k<j;j-- )
    instead of for(k=0;k<j;k--) write for(k=0;k<j;j-- )

    et cetera. If this is not considered a correct answer, the question
    should have been more precise.
  • No.2 | | 278 bytes | |


    Can anyone suggest me 2 more solutions?
    instead of for(k=0;k<j;k--) write for(k=0;k<j;j-- )
    instead of for(k=0;k<j;k--) write for(k=0;k<j;j-- )
    et cetera. If this is not considered a correct answer, the question
    should have been more precise.
  • No.3 | | 1419 bytes | |

    Ico <usenet@zevv.nlwrote:
    Romram <sajjanharudit@gmail.comwrote:
    >I was asked to submit atleast 5 solutions for the following problem:
    >>

    >By Replacing/Adding or deleting only one character from the following
    >code snippet, make it print tttttttttttttttttttt (20 times)
    >>

    >#include<stdio.h>
    >>

    >int main()
    >{
    >int k, j=20;
    >for(k=0;k<j;k--)
    >printf("t);
    >printf("\n");
    >return 0;
    >}
    >

    I assume you forget the closing quote in the first printf(). Please make
    sure that the code you post actually is correct and compiles.
    >
    >1. instead of for(k=0;k<j;k--) write for(k=0;k<j;j--)
    >>

    >2. instead of for(k=0;k<j;k--) write for(k=0;-k<j;k--)
    >>

    >3.instead of for(k=0;k<j;k--) write for(k=0;k+j;k--)
    >>

    >Can anyone suggest me 2 more solutions?
    >

    instead of for(k=0;k<j;k--) write for(k=0;k<j;j-- )
    instead of for(k=0;k<j;k--) write for(k=0;k<j;j-- )

    Ehm, no those are wrong ofcourse, I changed *and* inserted, which is
    against the rules. I should sit on my hands before I type.
  • No.4 | | 1075 bytes | |

    Romram <sajjanharudit@gmail.comwrote:
    I was asked to submit atleast 5 solutions for the following problem:

    By Replacing/Adding or deleting only one character from the following
    code snippet, make it print tttttttttttttttttttt (20 times)

    #include<stdio.h>

    int main()
    {
    int k, j=20;
    for(k=0;k<j;k--)
    printf("t);
    printf("\n");
    return 0;
    }

    I came up with 3 solutions which were

    1. instead of for(k=0;k<j;k--) write for(k=0;k<j;j--)
    2. instead of for(k=0;k<j;k--) write for(k=0;-k<j;k--)
    3.instead of for(k=0;k<j;k--) write for(k=0;k+j;k--)

    Can anyone suggest me 2 more solutions?

    I have reason to believe you have already found the only three possible
    solutions. I couldn't think of any more than the ones you already
    stated, so I have just tried a brute-force search of all possible
    replaces/additions/deletions of all possible characters at all possible
    locations.

    I'm interested in any other solutions that I might have missed.

    Ico
  • No.5 | | 981 bytes | |

    Romram wrote:
    I was asked to submit atleast 5 solutions for the following problem:

    By Replacing/Adding or deleting only one character from the following
    code snippet, make it print tttttttttttttttttttt (20 times)

    #include<stdio.h>

    int main()
    {
    int k, j=20;
    for(k=0;k<j;k--)
    printf("t);
    printf("\n");
    return 0;
    }

    I came up with 3 solutions which were

    1. instead of for(k=0;k<j;k--) write for(k=0;k<j;j--)

    2. instead of for(k=0;k<j;k--) write for(k=0;-k<j;k--)

    3.instead of for(k=0;k<j;k--) write for(k=0;k+j;k--)

    Can anyone suggest me 2 more solutions?

    Clearly some sort of homework. The canonical for loop

    for (k = 0; k < j; ++k)

    otherwise the loop almost infinite. The snippet is broken in at least
    two places and cannot be fixed with one change (as far as I can tell).

    Please compile these things into small programs before posting here.
  • No.6 | | 1465 bytes | |

    Ico wrote:
    Romram <sajjanharudit@gmail.comwrote:
    >I was asked to submit atleast 5 solutions for the following problem:
    >>

    >By Replacing/Adding or deleting only one character from the following
    >code snippet, make it print tttttttttttttttttttt (20 times)
    >>

    >#include<stdio.h>
    >>

    >int main()
    >{
    >int k, j=20;
    >for(k=0;k<j;k--)
    >printf("t);
    >printf("\n");
    >return 0;
    >}
    >>

    >I came up with 3 solutions which were
    >>

    >1. instead of for(k=0;k<j;k--) write for(k=0;k<j;j--)
    >2. instead of for(k=0;k<j;k--) write for(k=0;-k<j;k--)
    >3.instead of for(k=0;k<j;k--) write for(k=0;k+j;k--)
    >>

    >Can anyone suggest me 2 more solutions?
    >

    I have reason to believe you have already found the only three possible
    solutions. I couldn't think of any more than the ones you already
    stated, so I have just tried a brute-force search of all possible
    replaces/additions/deletions of all possible characters at all possible
    locations.

    I'm interested in any other solutions that I might have missed.

    add a single `-' to for(k=0;k<j;k--): for(k=0;-k<j;k--)
    ^
  • No.7 | | 1426 bytes | |

    Pedro Graca <hexkid@dodgeit.comwrote:
    Ico wrote:
    >Romram <sajjanharudit@gmail.comwrote:

    I was asked to submit atleast 5 solutions for the following problem:

    By Replacing/Adding or deleting only one character from the following
    code snippet, make it print tttttttttttttttttttt (20 times)

    #include<stdio.h>

    int main()
    {
    int k, j=20;
    for(k=0;k<j;k--)
    printf("t);
    printf("\n");
    return 0;
    }

    I came up with 3 solutions which were

    1. instead of for(k=0;k<j;k--) write for(k=0;k<j;j--)
    2. instead of for(k=0;k<j;k--) write for(k=0;-k<j;k--)
    3.instead of for(k=0;k<j;k--) write for(k=0;k+j;k--)

    Can anyone suggest me 2 more solutions?
    >>

    >I have reason to believe you have already found the only three possible
    >solutions. I couldn't think of any more than the ones you already
    >stated, so I have just tried a brute-force search of all possible
    >replaces/additions/deletions of all possible characters at all possible
    >locations.
    >>

    >I'm interested in any other solutions that I might have missed.
    >

    add a single `-' to for(k=0;k<j;k--): for(k=0;-k<j;k--)
    ^

    Is that not the same as P's solution #2 ?
  • No.8 | | 1830 bytes | |

    Ico wrote:
    Romram <sajjanharudit@gmail.comwrote:
    >I was asked to submit atleast 5 solutions for the following problem:
    >>

    >By Replacing/Adding or deleting only one character from the following
    >code snippet, make it print tttttttttttttttttttt (20 times)
    >>

    >#include<stdio.h>
    >>

    >int main()
    >{
    >int k, j=20;
    >for(k=0;k<j;k--)
    >printf("t);
    >printf("\n");
    >return 0;
    >}
    >>

    >I came up with 3 solutions which were
    >>

    >1. instead of for(k=0;k<j;k--) write for(k=0;k<j;j--)
    >2. instead of for(k=0;k<j;k--) write for(k=0;-k<j;k--)
    >3.instead of for(k=0;k<j;k--) write for(k=0;k+j;k--)
    >>

    >Can anyone suggest me 2 more solutions?
    >

    I have reason to believe you have already found the only three possible
    solutions. I couldn't think of any more than the ones you already
    stated, so I have just tried a brute-force search of all possible
    replaces/additions/deletions of all possible characters at all possible
    locations.

    I'm interested in any other solutions that I might have missed.

    My last post was a repeated solution. Sorry.

    If you don't mind UB (decrementing k past INT_MIN) or using an
    unprototyped function or waiting for the program to go through all the
    negative values of the int type

    instead of printf("t"); write pruntf("t"); and link with a library that
    defines

    int pruntf(char const * t) {
    static int n = 20;
    if (n) {
    ;
    printf("%s", t);
    }
    return 0;
    }
  • No.9 | | 323 bytes | |


    instead of printf("t"); write pruntf("t"); and link with a library that
    defines

    int pruntf(char const * t) {
    static int n = 20;
    if (n) {
    ;
    printf("%s", t);
    }
    return 0;
    }

    You can change only one character in the code adding a library is
    way out of the question

  • No.10 | | 763 bytes | |

    Romram <sajjanharudit@gmail.comwrote:
    I was asked to submit atleast 5 solutions for the following problem:

    By Replacing/Adding or deleting only one character from the following
    code snippet, make it print tttttttttttttttttttt (20 times)

    #include<stdio.h>

    int main()
    {
    int k, j=20;
    for(k=0;k<j;k--)
    printf("t);
    printf("\n");
    return 0;
    }

    I came up with 3 solutions which were

    1. instead of for(k=0;k<j;k--) write for(k=0;k<j;j--)
    2. instead of for(k=0;k<j;k--) write for(k=0;-k<j;k--)
    3.instead of for(k=0;k<j;k--) write for(k=0;k+j;k--)

    Can anyone suggest me 2 more solutions?

    It's been a few days now, did you found any alternatives yet ?

    Ico
  • No.11 | | 99 bytes | |


    It's been a few days now, did you found any alternatives yet ?
    N

Re: More Solutions


max 4000 letters.
Your nickname that display:
In order to stop the spam: 8 + 7 =
QUESTION ON "C/C++"

EMSDN.COM