Count letters: Difference between revisions
Content added Content deleted
Langurmonkey (talk | contribs) mNo edit summary |
Langurmonkey (talk | contribs) |
||
Line 30: | Line 30: | ||
split(replace(.s, RE/\P{L}/)), |
split(replace(.s, RE/\P{L}/)), |
||
) |
) |
||
} |
|||
}</lang> |
|||
writeln .countLetters("fuzzy furry kittens") |
|||
writeln .countLetters("ασδ ξκλ ασδ ξα") # random Greek letters</lang> |
|||
{{out}} |
{{out}} |
Revision as of 17:57, 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}/)), )
}
writeln .countLetters("fuzzy furry kittens") writeln .countLetters("ασδ ξκλ ασδ ξα") # random Greek letters</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}