created by Aha00aAha00a at 2016-12-05
last modified by Aha00aAha00a at 2026-11-15
revision: 4

Project Euler Problem22

http://projecteuler.net/index.php?section=problems&id=22

Names scores

Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score.

For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN would obtain a score of 938 × 53 = 49714.

What is the total of all the name scores in the file?

names.txt(우클릭, 저장), 5000이 넘는 이름이 들어있는 46K 텍스트파일을 이용하여, 알파펫순으로 정렬하라. 그리고 각 이름의 alphabetical value를 밝히고, 리스트의 순서를 곱하여 이름값을 구하라.

예를 들면, 정릴된 리스트에서 COLIN은 3 + 15 + 12 + 9 + 14 = 53이며, 938번째 이름이다. 그래서 COLIN은 938 × 53 = 49714를 이름값으로 갖는다.

이름값들의 총합은?

1. Solution

871198282
val input = Source.fromFile("p022_names.txt").getLines().mkString
val names = input.replaceAllLiterally("\"", "").split(",")
names.sorted.map(_.map(_ - 'A' + 1).sum).zipWithIndex.map(n => n._1 * (n._2 + 1)).sum

이 문제는 뭔가 수학적인걸 요구하는게 아닌듯.. --2016-12-05

2. See Also

2.2. Adjacent Pages

≤ 32
all
1.0x
1.0x
80
-120
ON
0/0
0/0
0.00
0
0 / 0
1.00x