Created
December 7, 2024 20:59
-
-
Save qookei/4a87228d4cfd217aa68999a2f05ddc32 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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