-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.fs
More file actions
39 lines (29 loc) · 973 Bytes
/
Utils.fs
File metadata and controls
39 lines (29 loc) · 973 Bytes
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
34
35
36
37
38
39
module AoC2020.Utils
open System.IO
open System.Text.RegularExpressions
open FParsec
let readLines filePath = File.ReadLines(filePath)
let readInput (s: string) =
readLines (__SOURCE_DIRECTORY__ + (sprintf "/input/%s.txt" s))
let getProblem (a: seq<string>): string = a |> Seq.head
module Seq =
let repeatForever s =
let c = Seq.cache s
seq {
while true do
yield! c
}
let filteri f =
Seq.mapi (fun i v -> (i, v))
>> Seq.filter (fun v -> f (fst v) (snd v))
>> Seq.map snd
let splitByLinefeed (s: string) = s.Split '\n'
let splitByTwoLinefeeds s = Regex.Split(s, "\n\n")
let readInputDelimByEmptyLine inputfile =
readInput inputfile
|> String.concat "\n"
|> splitByTwoLinefeeds
let testParser p str =
match run p str with
| ParserResult.Success (result, _, _) -> printfn "Success: %A" result
| Failure (errorMsg, _, _) -> printfn "Failure: %s" errorMsg