From: Ummon Date: Fri, 8 Dec 2017 07:31:04 +0000 (+0100) Subject: More concise X-Git-Url: https://git.euphorik.ch/?a=commitdiff_plain;h=c28b95d28a88c460298c8eb3ddbb18e283f25c36;p=advent_of_code_2017.git More concise --- diff --git a/AdventOfCode2017/Day8.fs b/AdventOfCode2017/Day8.fs index fcdda30..b9f6789 100644 --- a/AdventOfCode2017/Day8.fs +++ b/AdventOfCode2017/Day8.fs @@ -2,15 +2,15 @@ open System -type Instruction = string * string * int * string * string * int +type Instruction = string * string * int * string * (int -> int -> bool) * int let parseInput (lines : string[]) : Instruction list = lines |> List.ofArray |> List.map ( fun line -> - let line = line.Split ([| '\r'; '\t'; ' ' |], StringSplitOptions.RemoveEmptyEntries) - ( line.[0], line.[1], int line.[2], line.[4], line.[5], int line.[6]) + let line = line.Split ' ' + line.[0], line.[1], int line.[2], line.[4], (match line.[5] with ">" -> (>) | "<" -> (<) | ">=" -> (>=) | "<=" -> (<=) | "!=" -> (<>) | "==" | _ -> (=)), int line.[6] ) let execute (input : Instruction list) : int * int = @@ -18,9 +18,7 @@ let execute (input : Instruction list) : int * int = input |> List.fold ( fun (highest, register) (reg, ins, value, regCond, op, valueCond) -> - let regCondValue = register |> Map.tryFind regCond |> Option.defaultValue 0 - let op' = match op with ">" -> (>) | "<" -> (<) | ">=" -> (>=) | "<=" -> (<=) | "!=" -> (<>) | "==" | _ -> (=) - if op' regCondValue valueCond then + if op (register |> Map.tryFind regCond |> Option.defaultValue 0) valueCond then let regValue' = (register |> Map.tryFind reg |> Option.defaultValue 0) + match ins with "inc" -> value | "dec" -> -value | _ -> 0 max highest regValue', register |> Map.add reg regValue' else