#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    6
    Rep Power
    0

    Frequency of letter pairs in a text file


    Write a program to count the occurrences of all letter pairs in a sample of text (like the first paragraph of the Constitution). Disregard differences between lower and upper case letters. (Blanks are not considered as letters). Output the 100 most frequent letter pairs, in order by percent of total. Also show which percent of total pairs is accounted for by this list of 100. Your program should correctly process situations where the input file is empty or where less than 100 pairs occur.
    Sample output

    th 2.37% in 2.20% fj 2.00% ... (6 per line)
    ...
    (100 letter pairs)

    Output represents 73.44% of 23641 letter pairs.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    12
    Rep Power
    0

    Question


    so what is your problem. where have you been stuck.give us the exact or any other relevent detail for us to answer.do you want any algorithm! .but please avoid expect the full code.
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,893
    Rep Power
    481
    To represent a % character in a printf format string you can use
    printf("%%");
    or
    printf("%c",'%');
    You're welcome.
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    6
    Rep Power
    0
    Originally Posted by s_1_th97
    so what is your problem. where have you been stuck.give us the exact or any other relevent detail for us to answer.do you want any algorithm! .but please avoid expect the full code.
    i am able to print for a single letter but letter pairs are required so i am expecting either algorithm or block of code that can count letter pairs
  8. #5
  9. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,893
    Rep Power
    481
    I'd make a rank 2 array of integers, indexes range from 0..255. increment at the index into the array by the characters. Post process to retain only the information you need to keep.

    is
    ab
    the same as
    ba
    ?

    Does order matter?


    (if the memory were small I'd choose the array to be smaller using only the (number of) indexes you actually need, and I'd make it a byte array, and I'd consider "imprecise counting" in which you generate a random number (say on [0, 1) ) if less than 0.2 or whatever tolerance you need you increment the count)
    Last edited by b49P23TIvg; November 19th, 2013 at 10:26 PM.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo