Paste: aoc4

Author: Krenium
Mode: factor
Date: Wed, 4 Dec 2019 18:09:10
Plain Text |
USING: backtrack grouping kernel math math.functions math.order
math.parser math.ranges prettyprint sequences sequences.extras
sequences.generalizations splitting.monotonic ;
IN: aoc.2019.04a

: d ( m -- n n ) 9 [a,b] amb-lazy dup ;

[ 1 d d d d d d drop 6 narray ] bag-of                           ! generate all 6-digit monotonically increasing sequences
[ reverse [ 10^ * ] map-index sum ]                              ! constrain to
[ 273025 767253 between? ] map-filter                            ! input range
[ number>string ] map [ [ 2 clump [ first2 = ] any? ] count . ]  ! part 1
[ [ [ = ] monotonic-split [ length 2 = ] any? ] count . ] bi     ! part 2

New Annotation

Summary:
Author:
Mode:
Body: