View Feed
group-icon
Coffee Room
Discuss anything here - everything that you wish to discuss with fellow engineers.
12774 Members
Join this group to post and comment.
Kaustubh Katdare
Kaustubh Katdare • Dec 7, 2008

Code a self-documenting pangram in any programming language of your choice

Source: Gaia Intranet :: Careers :: Puzzle


A pangram is a sentence which contains every letter of the alphabet. A self-documenting pangram is one which follows the general format of:
This sentence contains a's, b's, c's, ...



For example:


Only a fool would check that this sentence contains exactly six 'a's, one 'b', six 'c's, three 'd's, thirty-four 'e's, five 'f's, two 'g's, ten 'h's, thirteen 'i's, one 'j', two 'k's, five 'l's, one 'm', twenty-two 'n's, seventeen 'o's, one 'p', one 'q', seven 'r's, thirty-two 's's, twenty-six 't's, three 'u's, seven 'v's, eight 'w's, six 'x's, seven 'y's, and one 'z'.


Challenge: Code a self-documenting pangram in any programming language of your choice.

PS: A well commented code is expected. [​IMG]

sumitjami
sumitjami • Dec 9, 2008
does this mean we have to write a program which counts the no of a`s ,b`s ,c`s........in it`s source code and in the end prints a line
"This sentence contains a's, b's, c's, ... "

???????????????????
Ashutosh_shukla
Ashutosh_shukla • Dec 9, 2008
Am i supposed to code a program that starts with "Only a fool would check that"
and finish up with your sentence ? Please can you make it clear? 😕
shalini_goel14
shalini_goel14 • Dec 11, 2008
Hello Mr. Ashutosh,

We are supposed to write a program that starts with any given sentence (Lets say "Only a fool would check that this sentence contains exactly " )followed by 'a's , 'bs'........so on.The tricky part lies in that should be in words and count of alphabets in those words should also be included.

If you see the example given

Only a fool would check that this sentence contains exactly six 'a's, one 'b', six 'c's, three 'd's, thirty-four 'e's, five 'f's, two 'g's, ten 'h's, thirteen 'i's, one 'j', two 'k's, five 'l's, one 'm', twenty-two 'n's, seventeen 'o's, one 'p', one 'q', seven 'r's, thirty-two 's's, twenty-six 't's, three 'u's, seven 'v's, eight 'w's, six 'x's, seven 'y's, and one 'z'.
There are total 5 'f's we will be given only sentence 'Only a fool would check that this sentence contains exactly' rest part of the sentence we have to generate with our code.

I think now you would have got what we are supposed to code for?😀

So i guess my program starts with a given statement that "Hi my name is ashutosh and this sentence contains exactly" & rest generated by program.I will try to write the code now as soon as i get time to do it.
sean_26
sean_26 • Dec 19, 2008
shalini_goel14
Hello Mr. Ashutosh,

We are supposed to write a program that starts with any given sentence (Lets say "Only a fool would check that this sentence contains exactly " )followed by 'a's , 'bs'........so on.The tricky part lies in that should be in words and count of alphabets in those words should also be included.

If you see the example given



There are total 5 'f's we will be given only sentence 'Only a fool would check that this sentence contains exactly' rest part of the sentence we have to generate with our code.

I think now you would have got what we are supposed to code for?😀

Thanks for your informative posting.
shalini_goel14
shalini_goel14 • Dec 24, 2008
Hi All,

I was trying to code for it.It is just like solving one of the other puzzles posted by our Big Boss 😉. I am stucked in a situation

When I am counting the letters for e.g. I count the letters 'e' and suppose I get its count as 13(thirteen) total in pangram excluding its own(2 'e's).

Now I increment the count of letters accordingly t+h+i+r+t+e+e+n

t by 1+1
h by 1
i by 1
r by 1
e by 1+1
n by 1

Now suppose i get count of 't' as 20(twenty). Again the count of e will change which will ultimately change the count of 't',then how should i deal with such a cyclic counting .Can anyone give any ideas?? 😔
Hi all I seem to be visiting quite often these days anyways coming back to this thread I would like to suggest a logic that i thought of
You can have a string passed as an argument to a function.Now you will require an array to store the count of alphabets. Also you pass the string first time as original one say "Only a foll would check that this sentence contains only" and the function would find the counts and store in array.
Now the next time the string passed would be Only a fool would check that this sentence contains a's and so on.
You keep calling the function until the array contents before and after the function call are same.This is a logic that i thought of using the basic control structures and the recursive function calls if someone has any other idea he/she is welcome to share it.
I wanted to code this one but due to lack of time i could not.
I hope this helps you people and someone tries to code this one.
shalini_goel14
shalini_goel14 • Dec 25, 2008
You are right, even I have also tried in the same way ,but in any case you will face the situation I described earlier(cyclic count dependency). Do you have any idea how to overcome it?😔
Hmm, pretty interesting! Good luck people 😀

(tries to boot up Python..)
I think if you keep calling the function then at a certain stage you will get the answer I guess once we should work it out ourselves on paper and then code to give it to computer.First check whether our logic is really working then code.and ya please send me code if possible I would like to see what you have done.
😔
sumitjami
sumitjami • Jan 8, 2009
i am rearly eager to see the code coz i am just not able to figure out the actual logic.....

Share this content on your social channels -