Took me a while to dig through some docs to find what I wanted, but I wrote a parser in F# using FParsec.
openSystem.IOopenFParsec// parsersletparseDecimal:Parser<decimal,unit>=puint64|>>decimalletstrWss=pstrings>>.spacesletparseTermexpression=(parseDecimal.>>spaces)<|>between(strWs"(")(strWs")")expressionletrunParserexprstr=matchrunexprstrwith|Success(result,_,_)->result|Failure(errorMsg,_,_)->failwithf"Error from parser: %s"errorMsgletrunPartaddOperatorinput=letopp=OperatorPrecedenceParser<decimal,unit,unit>()letexpression=opp.ExpressionParserletmultOperator=InfixOperator("*",spaces,1,Associativity.Left,(*))opp.TermParser<-parseTermexpressionopp.AddOperator(addOperator)opp.AddOperator(multOperator)input|>Array.sumBy(runParserexpression)|>printfn"%A"letinput=File.ReadAllLines"input.txt"runPart(InfixOperator("+",spaces,1,Associativity.Left,(+)))inputrunPart(InfixOperator("+",spaces,2,Associativity.Left,(+)))input
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Took me a while to dig through some docs to find what I wanted, but I wrote a parser in F# using
FParsec
.