aboutsummaryrefslogtreecommitdiff
path: root/06/2.rkt
blob: 2d666edca67c0f92b93ca7b20fe7e16e514227c8 (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

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