Skip to content

Snippets

Alex Harsányi edited this page Feb 1, 2021 · 2 revisions

Walked distance

#lang racket
(require "al-interactive.rkt")

(define (walked-distance df)
  (and (df-contains? df "dst" "grade")
       (df-fold
        df
        '("dst" "grade")
        0
        (lambda (a p n)
          (if (and p n)
              (match-let ([(list pd pg) p]
                          [(list nd ng) n])
                (if (and pd pg nd ng)
                    (+ a (* (- nd pd) (+ 1 (/ (abs ng) 100.0))))
                    a))
              a)))))
Clone this wiki locally