Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.77 KB | None | 0 0
  1. open System.IO
  2.  
  3. module PathWalker =
  4.     let stringListLogger (stringList: string[]) = Seq.iter(fun x -> printfn "%s" (x.ToString())) stringList
  5.  
  6.     let walk (x, y) (steps, direction) =
  7.         match direction with
  8.         | 'F' -> (x, y + steps)
  9.         | 'B' -> (x, y - steps)
  10.         | 'H' -> (x + steps, y)
  11.         | 'V' -> (x - steps, y)
  12.         | _ -> (x, y)
  13.  
  14.     let walkAll (line: string) =
  15.         line
  16.         |> Seq.chunkBySize 2
  17.         |> Seq.map (fun arr -> (int (arr.[0].ToString()), arr.[1]))
  18.         |> Seq.fold walk (0, 0)
  19.    
  20.     let walkLine input =
  21.         input
  22.         |> walkAll
  23.  
  24. [<EntryPoint>]
  25. let main argv =
  26.  
  27.     let (x, y) = File.ReadAllLines "input.txt" |> String.concat "" |> PathWalker.walkLine
  28.     printfn "%i %i" x y
  29.     0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement