mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-01-13 23:48:02 -05:00
34 lines
632 B
TypeScript
34 lines
632 B
TypeScript
//! test_output(2970)
|
|
|
|
import Range from "../helpers/Range.ts";
|
|
|
|
export default function main() {
|
|
return nameListScore([
|
|
"MARY",
|
|
"PATRICIA",
|
|
"LINDA",
|
|
"BARBARA",
|
|
"ELIZABETH",
|
|
"JENNIFER",
|
|
"MARIA",
|
|
"SUSAN",
|
|
"MARGARET",
|
|
// Truncated. Expected output is 871198282 for the full list.
|
|
]);
|
|
}
|
|
|
|
function nameListScore(names: string[]) {
|
|
names.sort();
|
|
|
|
return Range.from(names)
|
|
.indexed()
|
|
.map(([i, name]) => (i + 1) * nameScore(name))
|
|
.sum();
|
|
}
|
|
|
|
function nameScore(name: string) {
|
|
return Range.from(name)
|
|
.map((c) => c.codePointAt(0)! - "A".codePointAt(0)! + 1)
|
|
.sum();
|
|
}
|