# Project Euler Problem 22

Project Euler Problem 22 solution is straightforward. The only auxiliary function needed is **alphavalue** that for any string calculates its alphabetic value. Names are stripped from whitespace, sorted, products of alphabetic value by position are calculated and finally added together:

open System.IO let alphavalue (s: string) = s.ToCharArray() |> Array.map (fun x -> int x - int 'A' + 1) |> Array.sum let readData (path: string) = use sr = new StreamReader(path) sr.ReadLine().Split(',') let problem022 () = readData @"..\..\..\Datafiles\Problem022.data" |> Array.map (fun x -> x.Replace("\"","")) |> Array.sort |> Array.mapi (fun i x -> int64((alphavalue x) * (i + 1))) |> Array.sum

Advertisements

Leave a Comment