Read the following story carefully.
Mr. Alphabet Wordwala thinks that he is an extremely intelligent person on earth. He once thought that English is a bad language because it accepts only few of all possible words that can be made with its alphabets in its dictionary.
For example,
On one hand it has words like "an", "empty", "headed", "queen", "and", "a", "king";
but on the other hand it does not have words like "zn", "fmpty", "geaded", "quoom", "amd", "b", "kung".
Because he thinks he is an extremely intelligent person, he thought of generating brand new dictionaries of English language which will include all possible words. For generating the dictionaries in that way, he has to solve the following two problems.
Wordwala Problem 1:
For some unknown reason, Mr. Wordwala wants to enumerate all words of length less than a given positive number, say n, in a list of words such that initially all words of length 1 will appear, then all words of length 2 and so on till all words of length n are generated. Note that within the words of same length they are ordered alphabetically. Note also that Mr. Wordwala will consider only small-case letters. He calls this list, lexolist(n).
Sample lexolists for n=1, n=2, n=3 and n=4 are given in the file "samples.tar.bz2".
Use the following command to uncompress the files:
bunzip2 samples.tar.bz2; tar -xvf samples.tar
For example,
For lexolist(4) the word present at index 221422 is "long".
For lexolist(4) the word "word" is present at index 414859.
1a) Write a program that will take n and another integer, say k, and will return the word that is present at index k in the lexolist(n). Note that list index starts at 0.
1b) Write a program that will take n and a word, say w, and will return the index at which w is present at in the lexolist(n).
-----------------------
Wordwala Problem 2:
For another unknown and mysterious reason, Mr. Wordwala wants to enumerate all words of length less than a given positive number n, and then he wants to sort them alphabetically. He calls this list, sortolist(n).
Sample sortolists for n=1, n=2, n=3 and n=4 are given in the file "samples.tar.bz2".
For example,
For sortolist(4) the word present at index 211271 is "long".
For sortolist(4) the word "word" is present at index 412445.
2a) Write a program that will take n and another integer, say k, and will return the word that is present at index k in the sortolist(n). Note that list index starts at 0.
2b) Write a program that will take n and a word, say w, and will return the index at which w is present at in the sortolist(n).
For these problems you can use either Haskell or Python.
----------------------------------------------
Problem 2:
Write a function to generate the truth table entries of assignment of truth values to n boolean variables. You should NOT use explicit recursion.
You are allowed to use only the following higher order functions:
zip, zipWith, take, takeWhile, drop, dropWhile, map, repeat
You are to generate a single string containing the output and write it to a file by using following Haskell function: writeFile "filename.txt" output
For example,
If n = 2 then the output string is "-----\n|T|T|\n|T|F|\n|F|T|\n|F|F|\n-----\n".
Some input-oupput samples are given below:
If n = 2 then the assignments of truth values is as follows:
-----
|T|T|
|T|F|
|F|T|
|F|F|
-----
-----------------------
If n = 3 then the assignments of truth values is as follows:
-------
|T|T|T|
|T|T|F|
|T|F|T|
|T|F|F|
|F|T|T|
|F|T|F|
|F|F|T|
|F|F|F|
-------
-----------------------
If n = 4 then the assignments of truth values is as follows:
---------
|T|T|T|T|
|T|T|T|F|
|T|T|F|T|
|T|T|F|F|
|T|F|T|T|
|T|F|T|F|
|T|F|F|T|
|T|F|F|F|
|F|T|T|T|
|F|T|T|F|
|F|T|F|T|
|F|T|F|F|
|F|F|T|T|
|F|F|T|F|
|F|F|F|T|
|F|F|F|F|
---------
-----------------------