AoC '21, Day 11, second problem, rvc


A simple modification to the first problem.

 $ cat 11b.rkt 
 #lang racket 
  
 (require "11a.rkt") 
  
  
 (define (aoc-11b input) 
  
   (let* 
  
     ((octopuses (new-octopus-garden input)) 
      (population (octopuses 'population))) 
  
     (if (zero? population) 
       0 
       (let loop ((i 1)) 
         (if (= (step octopuses) population) 
           i 
           (loop (+ i 1))))))) 
  
  
 (module+ main 
   (aoc-11b problem-input)) 
  
  
 (module+ test 
  
   (require rackunit) 
    
   (check-eq? (aoc-11b "") 0) 
   (check-eq? (aoc-11b "0") 10) 
   (check-eq? (aoc-11b "000\n000\n000") 10) 
  
   (check-eq? (aoc-11b example-input) 195) 
   (check-eq? (aoc-11b problem-input) 505) 
   ) 
  
 $ raco test 11b.rkt 
 raco test: (submod "11b.rkt" test) 
 5 tests passed 
  
 $