! Copyright (C) 2022 Keldan Chapman. ! See http://factorcode.org/license.txt for BSD license. USING: kernel AOC prettyprint splitting sequences eval arrays math math.order sorting ; IN: AOC.2022.13 : parse ( input -- pair ) "\n\n" split-subseq [ "[" "{ " replace "]" " }" replace "," " " replace eval( -- x x ) 2array ] map ; : seq ) 2dup = [ 2drop +eq+ ] [ swap [ drop +lt+ ] [ swap [ drop +gt+ ] [ [ unclip ] bi@ swapd 2dup [ number? ] bi@ and [ 2dup = [ 2drop seq 2nip ] if ] [ [ dup number? [ 1array ] when ] bi@ seq