-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday02_part02.fs
33 lines (27 loc) · 1.08 KB
/
day02_part02.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module day02_part02
open System.IO
let filepath = __SOURCE_DIRECTORY__ + @"../../day02_input.txt"
let lines = File.ReadLines(filepath)
let DiffStrings (s1 : string) (s2 : string) =
let s1', s2' = s1.PadRight(s2.Length), s2.PadRight(s1.Length)
let matchedString =
(s1', s2')
||> Seq.zip
|> Seq.map (fun (c1, c2) -> if c1 = c2 then c1 else ' ')
|> Seq.filter (fun _c -> _c <> ' ')
matchedString |> List.ofSeq
let findSimilarString element inputList =
let output =
inputList
|> Seq.filter (fun e -> e <> element)
|> Seq.tryFind (fun e -> (DiffStrings element e).Length = (e.Length - 1))
|> Option.map (fun e -> DiffStrings e element) |> Option.defaultValue List.Empty
output
let getSolution inputList =
let mystring =
inputList |> Seq.ofList |> Seq.map (fun (e) ->
let foundResult = findSimilarString e inputList
foundResult
)
mystring |> Seq.find (fun x -> x.Length > 0) |> List.map (fun x -> string x) |> List.fold(+) ""
let resolve = getSolution (lines |> List.ofSeq)