25 lines
789 B
Forth
25 lines
789 B
Forth
module advent_of_code.tasks.day_2.Star1
|
|
|
|
open System.IO
|
|
|
|
let stream = new StreamReader("tasks/day-2/input.txt")
|
|
|
|
let convertToString (i: int64) = i |> string
|
|
|
|
let isInvalid (id: string) =
|
|
let individualCount = id.Length / 2
|
|
let firstHalf, secondHalf = id[0..individualCount - 1], id[individualCount..]
|
|
if firstHalf = secondHalf then id |> int64 else 0
|
|
|
|
let rec getInvalid (lines: string list) =
|
|
let line, tail = lines.Head, lines.Tail
|
|
let els = line.Split("-")
|
|
let low, high = els[0] |> int64, els[1] |> int64
|
|
let invalids = [low .. high] |> List.map convertToString |> List.map isInvalid
|
|
|
|
List.sum invalids + if tail.IsEmpty then 0 |> int64 else getInvalid tail
|
|
|
|
let main =
|
|
let lines = stream.ReadLine().Split(",") |> Array.toList
|
|
getInvalid lines
|