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

Kaustubh Katdare

Kaustubh Katdare

@thebigk Oct 26, 2024
Source: #-Link-Snipped-#


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 <number> a's, <number> b's, <number> 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]

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • sumitjami

    sumitjami

    @sumitjami-UHV2GH Dec 8, 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 <number> a's, <number> b's, <number> c's, ... "

    ???????????????????
  • Ashutosh_shukla

    Ashutosh_shukla

    @ashutosh-shukla-ed4Ei4 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

    @shalini-goel14-ASmC2J Dec 10, 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 <number> 'a's , <number> 'bs'........so on.The tricky part lies in that <number> 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?😀

  • Ashutosh_shukla

    Ashutosh_shukla

    @ashutosh-shukla-ed4Ei4 Dec 13, 2008

    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

    @sean-26-9vHFh3 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 <number> 'a's , <number> 'bs'........so on.The tricky part lies in that <number> 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.
  • Ashutosh_shukla

    Ashutosh_shukla

    @ashutosh-shukla-ed4Ei4 Dec 24, 2008

    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 <no> 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

    @shalini-goel14-ASmC2J 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?😔
  • Ashraf HZ

    Ashraf HZ

    @Ash Dec 25, 2008

    Hmm, pretty interesting! Good luck people 😀

    (tries to boot up Python..)
  • Ashutosh_shukla

    Ashutosh_shukla

    @ashutosh-shukla-ed4Ei4 Dec 26, 2008

    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

    @sumitjami-UHV2GH Jan 8, 2009

    i am rearly eager to see the code coz i am just not able to figure out the actual logic.....
  • shalini_goel14

    shalini_goel14

    @shalini-goel14-ASmC2J Apr 20, 2023

    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?? 😔