speed-control.rkt
#748
- Author
- winny
- Created
- May 5, 2023, 10:44 p.m.
- Expires
- Never
- Size
- 615 bytes
- Hits
- 59
- Syntax
- Racket
- Private
- ✗ No
#|
https://www.codewars.com/kata/56484848ba95170a8000004d/train/racket
I know I said I'm done with racket, but I have created mental debt by training myself on an industry-undesirable language :(.
|#
#lang racket
(provide gps)
(define (gps s x)
(match x
[(or (list) (list _)) 0]
[_
(for/fold ([acc empty]
#:result (argmax identity acc))
([a (in-list x)]
[b (in-list (cdr x))])
(define value (inexact->exact (floor (abs (/ (* 3600 (- a b)) s)))))
;; (printf "~a - ~a = ~a\n" a b value)
(cons value acc))]))