This challenge consists of two parts. The winner will be the solution with the lowest total byte count. The same language must be used for both challenges.
Part 1:
Write a function or program that takes a sentence with only valid words as input, and outputs a list of the used characters, the number of times each letter is used, and the number of letters in each of the words in the original sentence. The output from this program must be valid input to the next program (exactly as it is outputted)
I'll add examples and detailed rules further down.
Part 2:
Write a function or program that takes the output from the first program as input and uses this list of English words and recreates a sentence with the information from the output. The sentence doesn't have to be the same as the original sentence.
More information. rules and restrictions:
Part 1:
- The first input can be on any suitable format, with or without quotation marks, as function argument or from STDIN, with or without brackets etc.
- The input sentence will not contain any punctuation or special characters, except for a period/dot in the end. Except for the period symbol, all characters that are in the input will be in the word list.
- The first letter of the sentence will be upper case, the rest will be lower case.
- The output of part 2 must start with the same upper case letter as the original sentence (so converting the input to lower case is not recommended (but OK).
- The output can be on any suitable format:
- It must be possible to copy-paste the output directly into the next program / function
- No alterations can be made when copy-pasting, the entire output must be copied and pasted as a whole, not in parts.
- You may for instance output a histogram of all letters in the alphabet, or only the ones used (in general, whatever is necessary to complete part 2)
- You can not output a list of characters where multiple occurrences are repeated. For instance,
The queue
can't yield an output:Teeehquu (3,5)
, it should be something like:Tehqu, (1 3 1 1 2),(3 5)
.
Part 2:
- The program / function must accept the input exactly as is from part 1 (one exception, see comment below about taking file name as input.).
- If surrounding brackets, quotation marks or similar are necessary to parse the input then these must be part of the output from part 1.
- The word list can be found here.
- The word list can either be saved locally as
w.txt
, or it can be fetched from the url. The url will only count as 5 bytes, so you don't need a url-shortener. - If the program can't open a file without reading the name as an input from STDIN (I believe this
iswas the case for Pyth at least), then the file name can be taken as a separate input argument.
- The word list can either be saved locally as
- The output must be only a sentence (list of valid words), ending with a period and an optional newline.
- The output must have words with the same number of letters as the original sentence in part 1 (in correct order)
- All the letters that were used in the original sentence must be used in the new output.
- The sentence must start with the same upper case letter as the original input sentence and end with a period.
Both parts:
- Neither of the parts should take more than 2 minutes to execute (randomly picking out words until a solution is reached is not accepted).
With the rules listed above, there should be a fair chance that the exact same sentence is reproduced, however that is not a requirement.
Examples:
In the below examples, a few different input and output formats are shown. Many more are accepted.
Part 1:
Input:
Zulus win.
Output type 1:
Z i l n s u w
1 1 1 1 1 2 1
5 3
Output type 2:
(('Z',1),('i',1),('l',1),('n',1),('s',1),('u',2),('w',1)), (5,2)
Output type 3:
'Zilnsuuw',[1,1,1,1,1,2,1],[5,2]
Part 2:
Input: An exact copy of the output from part 1. Output:
Zulus win.
Note that other word combinations are accepted as long as they start with a Z
, and the first word has 5 letters and the second has 3.
The shortest code in bytes win.
f1
that's pasted intof2
must contain all the data specified in the challenge. No additional data can be part of the output fromf1
. No data can be "stored" inf1
making information available when calling it fromf2
.f1
can only take one string as input per call. \$\endgroup\$