AoC'21, day 1, first problem rvc


Count consecutive increasing values in a sequence.

 $ cat 01a.rkt  
 #lang racket 
  
  
 (provide 
   example-data 
   read-input) 
  
  
 (require 
   (prefix-in aoc: "aoc.rkt") 
   (prefix-in srfi1: srfi/1)) 
  
  
 (define (aoc01a . input) 
  
   ; Return the number of depth increases in the given sequence of 
   ; depth soundings.  If no soundings are given, use the contest 
   ; problem input; otherwise assume the argument is the string 
   ; representation of a problem input. 
  
   (increasing-count (apply read-input input))) 
  
  
 (define (increasing-count soundings) 
  
   ; Return the number of depth increases in the given sequence of depth 
   ; soundings. 
  
   (length 
     (filter 
       (lambda (p) (apply < p)) 
       (srfi1:zip soundings (cdr soundings))))) 
  
  
 (define  (read-input . input) 
  
   ; Return the given depth soundings.  If no soundings are given, 
   ; use the contest problem input; otherwise assume the argument 
   ; is the string representation of a problem input. 
  
   (map 
     (lambda (d) (string->number d)) 
     (flatten (aoc:aoc-read-input (if (null? input) 1 (car input)))))) 
  
  
 (module+ main 
  
   (aoc01a)) 
  
  
 (aoc:define-string example-data 
   "199" 
   "200" 
   "208" 
   "210" 
   "200" 
   "207" 
   "240" 
   "269" 
   "260" 
   "263") 
  
 (define example-result 7) 
  
  
 (module+ test 
  
   (require rackunit) 
  
   (check-equal? (aoc01a example-data) example-result) 
   (check-equal? (aoc01a) 1527)) 
  
  
 $ raco test 01a.rkt  
 raco test: (submod "01a.rkt" test) 
 2 tests passed 
  
 $