Skip to content

Instantly share code, notes, and snippets.

@mishadoff
Last active December 12, 2015 04:49
Show Gist options
  • Save mishadoff/4717390 to your computer and use it in GitHub Desktop.
Save mishadoff/4717390 to your computer and use it in GitHub Desktop.
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