aboutsummaryrefslogtreecommitdiff
path: root/advent-of-code/2023/06/2.rkt
blob: cc381cf2ca4261467a0268161bb8e3b6a604cdd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#lang racket/base

(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)