Created
December 13, 2022 12:06
-
-
Save yodiz/85202989408e6f2b17acfa5aaaf029d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
let inline middle a b = min a b + (abs (a - b) / (LanguagePrimitives.GenericOne + LanguagePrimitives.GenericOne)) | |
type Point = { x:int; y:int } | |
module Point = | |
let create x y ={ x = x; y = y } | |
let middle p1 p2 = create (middle p1.x p2.x) (middle p1.y p2.y) | |
let a = 2.0**2.0 | |
let pow n p = System.Math.Pow(n, p) | |
let distance (p1:Point) (p2:Point) = | |
let a = (min p1.x p2.x) - (max p1.x p2.x) | |
let b = (min p1.y p2.y) - (max p1.y p2.y) | |
pow (pow a 2 + pow b 2) 0.5 //c | |
///Is point c between a and b | |
let between (a:Point) (b:Point) (c:Point) = distance a c + distance b c = distance a b | |
//https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line | |
let distPointToLine (a:Point) (b:Point) (c:Point) = | |
let x1 = float a.x | |
let y1 = float a.y | |
let x2 = float b.x | |
let y2 = float b.y | |
let x0 = float c.x | |
let y0 = float c.y | |
abs((x2 - x1)*(y1-y0)-(x1-x0)*(y2-y1)) | |
/ (pow (((pow (x2-x1) 2)) + ((pow (y2-y1)) 2)) 0.5) | |
(* game loop *) | |
while true do | |
let token = (Console.In.ReadLine()).Split [|' '|] | |
let loc = Point.create (int token.[0]) (int token.[1]) | |
let humanCount = int(Console.In.ReadLine()) | |
let humans = [| | |
for i in 0 .. humanCount - 1 do | |
let t = (Console.In.ReadLine()).Split [|' '|] | |
yield {|id = int(t.[0]); Loc = { x = int t.[1]; y = int t.[2] }|} | |
|] | |
let zombieCount = int(Console.In.ReadLine()) | |
let zoombies = [| | |
for i in 0 .. zombieCount - 1 do | |
let t = (Console.In.ReadLine()).Split [|' '|] | |
let nt n = int t.[n] | |
yield {| Id = int t.[0]; Loc = Point.create (nt 1) (nt 2); Target = Point.create (nt 3) (nt 4) |} | |
|] | |
//Find human that will die last - human furthest from a zoombie | |
let save = | |
humans | |
|> Array.map | |
(fun h -> | |
let (z,zd) = zoombies |> Array.map (fun z -> z, distance z.Loc h.Loc) |> Array.minBy snd | |
{| | |
Human = h | |
ClosestZoombie = {| Zoombie = z; Distance = zd|} | |
SaveTime = int (distance h.Loc loc) / 1000 | |
KillTime = int zd / 400 | |
|} | |
) | |
|> Array.sortByDescending (fun x ->x.KillTime) | |
|> Array.pick Some | |
let goto = | |
save.ClosestZoombie.Zoombie.Loc | |
printfn "%i %i" goto.x goto.y | |
() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment