I was missing parser combinators so came back and did day 8 again.
data classNode(valchildren:List<Node>,valmetadata:List<Int>)funparse(input:String):Node{valinteger=Terminals.IntegerLiteral.PARSER.map(String::toInt)valtreeRef=Parser.Reference<Node>()funnodeParser(numChildren:Int,numMetadata:Int):Parser<Node>=sequence(treeRef.lazy().times(numChildren),integer.times(numMetadata),::Node)valnodeInfo:Parser<Pair<Int,Int>>=sequence(integer,integer){nc,nm->Pair(nc,nm)}valtree:Parser<Node>=nodeInfo.next{(nc,nm)->nodeParser(nc,nm)}treeRef.set(tree)valparser=tree.from(Terminals.IntegerLiteral.TOKENIZER,Scanners.WHITESPACES)returnparser.parse(input.trim())}
It was initially much more dense but I tried to break it up to make it easier to follow. It's not the One True Way of parsing for nothing you know!
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.
I was missing parser combinators so came back and did day 8 again.
It was initially much more dense but I tried to break it up to make it easier to follow. It's not the One True Way of parsing for nothing you know!