Skip to content

Instantly share code, notes, and snippets.

@qookei
Created December 7, 2024 20:59
Show Gist options
  • Save qookei/4a87228d4cfd217aa68999a2f05ddc32 to your computer and use it in GitHub Desktop.
Save qookei/4a87228d4cfd217aa68999a2f05ddc32 to your computer and use it in GitHub Desktop.
(use-modules (ice-9 textual-ports) (ice-9 pretty-print) (srfi srfi-1) (ice-9 receive) (srfi srfi-26))
(define (read-input)
(let ([line (get-line (current-input-port))])
(if (eof-object? line)
'()
(cons (filter identity (map string->number (string-split line #\space)))
(read-input)))))
(define (abs- a b) (abs (- a b)))
(receive (left right)
(unzip2 (read-input))
(pretty-print (fold + 0 (map abs- (sort left <) (sort right <))))
(pretty-print (fold + 0 (map (λ (v) (* v (count (cut = v <>) right))) left))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment