Count letters: Difference between revisions
Content added Content deleted
Langurmonkey (talk | contribs) (new task, with langur language example) |
Langurmonkey (talk | contribs) mNo edit summary |
||
Line 5: | Line 5: | ||
Use the following. The Greek letters are random and don't spell anything that I know of. |
Use the following. The Greek letters are random and don't spell anything that I know of. |
||
fuzzy furry kittens |
fuzzy furry kittens |
||
ασδ ξκλ ασδ ξα |
ασδ ξκλ ασδ ξα |
||
Revision as of 17:56, 11 March 2020
Count letters
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
- Task
Count the letters used in a sentence, by code point, generating a hash or associative array, or appropriate construct for the language.
Use the following. The Greek letters are random and don't spell anything that I know of.
fuzzy furry kittens
ασδ ξκλ ασδ ξα
langur
<lang langur>var .countLetters = f(.s) {
for[=h{}] .s2 in split(replace(.s, RE/\P{L}/)) { _for[.s2; 0] += 1 }
}
writeln .countLetters("fuzzy furry kittens") writeln .countLetters("ασδ ξκλ ασδ ξα") # random Greek letters</lang>
<lang langur>var .countLetters = f(.s) {
foldfrom( f(var .h2, .s2) { .h2[.s2; 0] += 1; .h2 }, h{}, split(replace(.s, RE/\P{L}/)), )
}</lang>
- Output:
h{"f": 2, "u": 2, "z": 2, "y": 2, "r": 2, "k": 1, "i": 1, "t": 2, "e": 1, "n": 1, "s": 1} h{"α": 3, "σ": 2, "δ": 2, "ξ": 2, "κ": 1, "λ": 1}