Last active
December 12, 2015 04:49
-
-
Save mishadoff/4717390 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module: beautiful-strings | |
define function string-beauty (s :: <string>) => (n :: <integer>) | |
let repetitions = make(<simple-vector>, size: 26, fill: 0); | |
for (c in choose(alphabetic?, s)) | |
let i = as(<integer>, as-uppercase(c)) - as(<integer>, 'A'); | |
repetitions[i] := repetitions[i] + 1; | |
end for; | |
reduce1(\+, map(\*, sort(repetitions), range(from: 1, to: 26))) | |
end function string-beauty; | |
define function main (name :: <string>, arguments :: <vector>) | |
for (i :: <integer> from 1 to string-to-integer(read-line(*standard-input*))) | |
format-out("Case #%d: %d\n", i, string-beauty(read-line(*standard-input*))); | |
end for; | |
exit-application(0); | |
end function main; | |
main(application-name(), application-arguments()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment