Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. module day02_part02
  2.  
  3. open System.IO
  4.  
  5. let filepath = __SOURCE_DIRECTORY__ + @"../../day02_input.txt"
  6. let lines = File.ReadLines(filepath)
  7.  
  8. let DiffStrings (s1 : string) (s2 : string) =
  9. let s1', s2' = s1.PadRight(s2.Length), s2.PadRight(s1.Length)
  10. let matchedString =
  11. (s1', s2')
  12. ||> Seq.zip
  13. |> Seq.map (fun (c1, c2) -> if c1 = c2 then c1 else ' ')
  14. |> Seq.filter (fun _c -> _c <> ' ')
  15. matchedString |> List.ofSeq
  16.  
  17. let findSimilarString element inputList =
  18. let output =
  19. inputList
  20. |> Seq.filter (fun e -> e <> element)
  21. |> Seq.tryFind (fun e -> (DiffStrings element e).Length = (e.Length - 1))
  22. |> Option.map (fun e -> DiffStrings e element) |> Option.defaultValue List.Empty
  23. output
  24.  
  25. let getSolution inputList =
  26. let mystring =
  27. inputList |> Seq.ofList |> Seq.map (fun (e) ->
  28. let foundResult = findSimilarString e inputList
  29. foundResult
  30. )
  31. mystring |> Seq.find (fun x -> x.Length > 0) |> List.map (fun x -> string x) |> List.fold(+) ""
  32.  
  33. let resolve = getSolution (lines |> List.ofSeq)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement