blob: 5d124e0110ea8c82154699c07c68f625eb979a46 (
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)
|