2025-12-10 19:20:22 +00:00

36 lines
949 B
Forth

module advent_of_code.tasks.day_9.Star1
open System
open System.IO
let stream = new StreamReader("tasks/day-9/input.txt")
type Point2D =
struct
val X: int64
val Y: int64
new(s: string) =
let splitS = s.Split(',') |> Array.map int64
let x, y = splitS[0], splitS[1]
{
X = x
Y = y
}
override this.ToString() =
$"Point2D with x = {this.X} y = {this.Y}"
end
let getRect(p: Point2D * Point2D) =
let p1, p2 = p.Deconstruct()
abs (p1.X - p2.X + (1 |> int64)) * abs (p1.Y - p2.Y + (1 |> int64))
let notSame (p: Point2D * Point2D) =
let p1, p2 = p.Deconstruct()
p1.X <> p2.X && p1.Y <> p2.Y
let main =
let points = stream.ReadToEnd().Split('\n') |> Array.map Point2D
let allRects = (Array.allPairs points points) |> Array.filter notSame |> Array.map getRect
allRects |> Array.max