! Copyright (C) 2022 Keldan Chapman. ! See http://factorcode.org/license.txt for BSD license. USING: kernel AOC prettyprint sequences math math.matrices arrays splitting combinators ; IN: AOC.2022.8 : up ( mat y x -- seq ) [ head ] dip '[ _ swap nth ] map reverse ; : dn ( mat y x -- seq ) [ 1 + tail ] dip '[ _ swap nth ] map ; : lf ( mat y x -- seq ) [ swap nth ] dip head reverse ; : rt ( mat y x -- seq ) [ swap nth ] dip 1 + tail ; : evaluate-scenery ( input quot -- mat ) [ split-lines [ >array ] map dup ] dip '[ rot [ _ -rot { [ up ] [ dn ] [ lf ] [ rt ] } 3cleave 4array ] dip @ ] matrix-map-index ; inline : part-1 ( input -- result ) [ '[ [ _ < ] all? ] any? 1 0 ? ] evaluate-scenery [ sum ] map-sum ; : part-2 ( input -- result ) [ '[ [ [ _ >= ] find drop ] keep length 1 - or 1 + ] map product ] evaluate-scenery mmax ; MAIN: [ 8 read-day-input [ part-1 . ] [ part-2 . ] bi ]