Create a bidirectional Gematria calculator, for any given sequence of Unicode characters as the alphabet.
Gematria is a system of assigning numerical values to symbols, developed by ancient Greeks and adopted by ancient Jews. It is in a way like ASCII or Unicode, it's just non-linear... See the following table (full table is available in the link above):
Index Letter Letter name Value -------------------------- 0 א "Alef" 1 1 ב "Bet" 2 ... 8 ט "Tet" 9 9 י "Yud" 10 10 כ "Kaf" 20 ... 17 צ "Tsady" 90 18 ' "Kuf" 100 19 ר "Resh" 200 ...
The names of letters are not important, only their index in the "Array" of the alphabet and the respective numerical value. The Hebrew alphabet only has 22 letters (not including "final" letters), so the maximum available value is 400.
If we borrow this system to the English alphabet (A-Z) we will end up with A=1, B=2... L=30... U=300... Z=800.
Two things we need to know.
One of the most important features in this system is calculating the "Gematria Value" of a word, by summing up its letters' values. (Some say there is a mystical connection between words, or phrases (when the value of space is zero) - that share the same Gematria Value).
Any non-negative Integer can be represented in symbols. For example (and let's stay with the English alphabet for now) the value of 32 is LB (L=30 + B=2). The value of 1024 is ZTKD (800+200+20+4. Note that ZSSKD is also 1024, but that's not a legal representation, since it can be compacted).
Write a program / a function / a code snippet in your language-of-choice, which is first set up with an alphabet (see API below) and then accept an argument. That argument may be an Integer, or a word/phrase. If it's an Integer - your program should output/return its representation in the alphabet symbols - the most compacted one (see (2) above). If it is a word or a phrase, your program should output/return the Gematria Value (by summing up symbols' values, not counting whitespaces, see (1) above).
Your program/function should accept 3 arguments. You can get them from STDIN, or as function arguments, you can even assume they are variables which initialized programmatically prior to your function invocation.
- First argument - the first character (in Unicode) of the alphabet.
- Second argument - the last character (in Unicode) of the alphabet.
- Third argument - An Integer, to be represented in symbols, OR a phrase which is created by the given alphabet.
Output / Return Value: Depending on the third argument, as explained above.
- First two arguments will always be one character long each, and the second will always be grater than the first.
- The sequence (first until last, inclusive) will never include any of the values 30-39 (which represent the digits 0-9), otherwise it will make the third argument ambiguous. EDIT: It won't contain space as well, since in phrases spaces are counted as zeros.
- The third argument, in case it's a phrase, may only contain spaces and letters of the given alphabet. Empty string is not a valid input (you can assume it's not empty). In case it's an Integer, you can assume it's a positive Integer.
Input Output A Z CODE GOLF 175 a s 512 sssssjb A B 7 BBBA ≐ ⊐ ≤≫ ≥ 1700
Score = upvotes - length/100.0
Your code should be short, but more-importantly popular. Negative scores can also play along. The winner will be the answer with highest score in a week from now, 2014-11-29 19:20:00 UTC.