diff options
| author | Mistivia <i@mistivia.com> | 2024-01-27 20:01:29 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2024-01-27 20:01:29 +0800 |
| commit | 97b89c31131b63a7bc3c5b47a6988c16716252d2 (patch) | |
| tree | 090eff3cf0dcb85ce67656fa7960f540082fe963 | |
| parent | e482c6c5dac4bc3af2cba85a3e71524c58b9afe4 (diff) | |
solve advent of code 2023 06 part2
| -rw-r--r-- | advent-of-code/2023/06/2.rkt | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/advent-of-code/2023/06/2.rkt b/advent-of-code/2023/06/2.rkt new file mode 100644 index 0000000..5d124e0 --- /dev/null +++ b/advent-of-code/2023/06/2.rkt @@ -0,0 +1,29 @@ +#lang racket + +(define in (open-input-file "input")) + +(define (read-num) + (define line (read-line in)) + (string->number + (apply + string-append + (string-split + (cadr (string-split (string-trim line) ":")))))) + +(define time (read-num)) +(define distance (read-num)) + +(define (calc time hold-time) + (* hold-time (- time hold-time))) + +(define (solve time distance) + (define (loop counter hold-time) + (if (> hold-time time) + counter + (if (> (calc time hold-time) distance) + (loop (+ 1 counter) (+ 1 hold-time)) + (loop counter (+ 1 hold-time))))) + (loop 0 0)) + +(display (solve time distance)) +(newline) |
