open System
let followThePath (lines : string[]) : string * int =
+ let isNotWhiteSpace = Char.IsWhiteSpace >> not
let rec next (i, j) (di, dj) str n =
let i', j' = i + di, j + dj
let c = lines.[i'].[j']
|> List.pick (
fun (ndi, ndj) ->
let ni, nj = i' + ndi, j' + ndj
- if (ni, nj) <> (i, j) && (Char.IsWhiteSpace lines.[ni].[nj] |> not) then Some (ndi, ndj) else None
+ if (ni, nj) <> (i, j) && isNotWhiteSpace lines.[ni].[nj] then Some (ndi, ndj) else None
)
next (i', j') nextDir str (n + 1)
- elif Char.IsWhiteSpace c |> not then
+ elif isNotWhiteSpace c then
next (i', j') (di, dj) (if Char.IsLetter c then str + string c else str) (n + 1)
else
str, n