Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,25 @@
#lang racket
(define (wake-and-split nuts sailors depth wakes)
(define-values (portion remainder) (quotient/remainder nuts sailors))
(define monkey (if (zero? depth) 0 1))
(define new-wakes (cons (list nuts portion remainder) wakes))
(and (positive? portion)
(= remainder monkey)
(if (zero? depth)
new-wakes
(wake-and-split (- nuts portion remainder) sailors (sub1 depth) new-wakes))))
(define (sleep-and-split nuts sailors)
(wake-and-split nuts sailors sailors '()))
(define (monkey_coconuts (sailors 5))
(let loop ([nuts sailors])
(or (sleep-and-split nuts sailors)
(loop (add1 nuts)))))
(for ([sailors (in-range 5 7)])
(define wakes (monkey_coconuts sailors))
(printf "For ~a sailors the initial nut count is ~a\n" sailors (first (last wakes)))
(map displayln (reverse wakes))
(newline))