Available Marks: 10Numerologists ascribe certain magical properties to numbers, and in turn derive numbers from words or phrases. Nonsense like this can still provide an interesting computational exercise. The two algorithms of interest to us are: - Given a positive integer N, add up the digits in its decimal representation. If that sum has more than one digit, add up its digits and so on until only a single digit remains. That's the digital root of N.
- Given a phrase containing one or more words, assign a number to each letter equal to its position in the alphabet, so that a is 1, b is 2 and so on to z (26). Capital letters are counted the same as small letters, and non-letters are ignored. Now add up the values and reduce the sum to its digital root, which becomes the digital root of the phrase. This process is called gematria.
Write a program that reads in up to 20 lines, preceded by the number of lines. For each line, if it contains only a number, calculate and display the digital root, spaces and the number. If it's a phrase, calculate the letter sum, then display the digital root, the sum and the phrase, agsin separated by spaces. Input and calculated numbers are less than a billion and phases are shorter than 100 characters. ExampleInput: 5
123
the quick brown fox
7823438
"640 K ought to be enough for anybody". Bill Gates, 1981.
Progcomp
| Output:6 123
4 211 the quick brown fox
8 7823438
1 406 "640 K ought to be enough for anybody". Bill Gates, 1981.
4 103 Progcomp |
Test DataYou should test your program on the following data:14
99999
10000
7
12345678
98765432
June
UNSW Progcomp Twenty-thirteen
the second figure thrice
"Tragedy is when I cut my finger,...
Comedy is when you walk into an open sewer and die" (attributed to Mel Brooks).
the thirty-sixth triangular number, declared the number of the beast
A Clockwork Orange, Stanley Kubrick: 3*114+1=343
(114 was Kubrick's signature code, it appears in four films as CRM114 or serum 114 or C-rm114.)
Nineteen associates attacked the World Trade Center in New York and the Pentagon in Washington. |
Marking Scheme5 marks for correctly implementing the digit reduction algorithm and 5 for combining it correctly with the phrase analysis.
|
|