pls help...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Imnew2c
    New Member
    • Jun 2007
    • 5

    pls help...

    need help with logic of a pgm...

    pgm is to print the following output...

    This computer generated string contains ___letters:,___ _ A,_____B,
    ....._____Z.

    This is the output.
    The blanks are the count of the characters(/alphabets) that appear in the output string itself.
    I mean to say the "____" needs to be filled for eg: by the count of A in the output.It should include even the A that follows the "________" and any other occurence of A.
    same with the case with all characters.
    Now the problem: i will cite an eg: now since Z appears in only word zero,the count of Z will be zero( because all character appear in the output atleast once).
    so when the string is printed with count of Z it will print zero Z.
    now Z have appeared twice in the string and hence one more iteration will occur which will cause two Z to be output..but as you can see now there is only one Z and hence another iteration will print it as one Z..by this time the count of letter N and R has changed.so further iterations.
    problem is tht the program is not converging because i have to print the count in words.If it were to be printed in numbers it happens in just 2 iterations.
    Please help.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    I'm all set to help. I just don't know where you are stuck. What have you tried already?

    Comment

    • Imnew2c
      New Member
      • Jun 2007
      • 5

      #3
      Originally posted by weaknessforcats
      I'm all set to help. I just don't know where you are stuck. What have you tried already?

      oh..at last some one has shown some concern..
      yes i have tried this pgm...
      as i said my pgm does not converge to a end..its going on and on...i don't see something wrong with my logic..
      i used a file to write the seed string..read the file..write afresh into it the latest character count and individual counts..
      my exit condition:
      i keep track of all values of last iteration
      i compare the same with the latest iteration...if both are equal it means there is no character count variation and output is stable...but this is not happening..ever ytime the iteration occurs it finds a new character...so count varies and all values varies..
      there are ten characters count tht u can keep constant by some manipulations..
      a,b,c,d,j,k,m,p ,q,z

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        What does the code look like?

        Comment

        • phiefer3
          New Member
          • Jun 2007
          • 67

          #5
          It may simply not be possible. Without knowing the exact string you want to output, there may be no way for it to meet your end criteria.

          For example. suppose that 5 of the letters (other than x) appear 6 times (or 16, or 60, or any other number containing an x).

          This means that the word "six" will appear 5 times, and counting the "X" where you show its count, that makes 6 x's. This means that you put the word "six" infront of the "X". But this makes it so there are 7 x's, so you change the word infront of the "X" to "seven", and now there are only 6 x's again.

          There can be numerous other ways for this to form an infinite loop.

          Comment

          • Imnew2c
            New Member
            • Jun 2007
            • 5

            #6
            Originally posted by weaknessforcats
            What does the code look like?
            i have tried the code...for debugging purpose i tried two ways...
            1) instead of words i print numbers,,pgm finished under less than a min
            2) i tried only till D..since all a,b,c and D have value stable without any variation this time also pgm finished in 6 iterations..

            now when i go for test till E..the pgm ends up in a infinite loop....

            how do i send my code to you..can i post it here..or we have a way to upload it somewhere....

            Comment

            • Imnew2c
              New Member
              • Jun 2007
              • 5

              #7
              Originally posted by phiefer3
              It may simply not be possible. Without knowing the exact string you want to output, there may be no way for it to meet your end criteria.

              For example. suppose that 5 of the letters (other than x) appear 6 times (or 16, or 60, or any other number containing an x).

              This means that the word "six" will appear 5 times, and counting the "X" where you show its count, that makes 6 x's. This means that you put the word "six" infront of the "X". But this makes it so there are 7 x's, so you change the word infront of the "X" to "seven", and now there are only 6 x's again.

              There can be numerous other ways for this to form an infinite loop.

              yes you are correct...its hitting a infinite loop..i have tried till 2crore iterations n no stable output...but except for oscillations should this program hit end somewhere? if we try some sort of predictive logic may be this will end..but i am not able to fix some logic now...

              Comment

              • sicarie
                Recognized Expert Specialist
                • Nov 2006
                • 4677

                #8
                Please also have a look at this.

                Comment

                Working...