Files
project-euler/npr_sundaypuzzle_20120422.fs
2025-08-03 20:16:55 -07:00

32 lines
811 B
FSharp

module npr_sundaypuzzle_20120422
open common
open System.IO
open System.Text.RegularExpressions
let puzzle =
let loadNames fn =
File.ReadAllLines(fn)
|> Seq.map (fun l -> Regex.Replace(l, "(\w+).*", "$1").ToLower() )
|> Seq.filter (fun n -> n.Length = 4)
let maleNames =
loadNames @"dist.male.first.txt"
let femaleNames =
loadNames @"dist.female.first.txt"
let rotateChar (c:char) =
c |> int |> (fun n -> (n + 13 - 97) % 26 + 97) |> char
let rotateName name =
name
|> mapChars rotateChar
|> Array.map string
|> Array.fold (fun acc i -> acc + i) ""
maleNames
|> Seq.map (fun n -> (n, rotateName n))
|> Seq.filter (fun (_,mn) -> Seq.exists ((=) mn) femaleNames)
|> Seq.toArray