Skip to content

Instantly share code, notes, and snippets.

@winny-
Created December 2, 2017 05:16
Show Gist options
  • Save winny-/7652453e364249eec56c31a1b5e8175b to your computer and use it in GitHub Desktop.
Save winny-/7652453e364249eec56c31a1b5e8175b to your computer and use it in GitHub Desktop.
#lang racket
(define (part1 ls)
(for/sum ([n (map (curry argmax identity) ls)]
[m (map (curry argmin identity) ls)])
(- n m)))
(define (part2 ls)
(for/sum ([line ls])
(for/first ([n line]
[i (length line)]
#:when #t
[m (remove n line)]
#:when (zero? (modulo n m)))
(quotient n m))))
(module+ main
(define ls
(for/list ([line (port->list read-line)])
(map string->number (string-split line #rx"\t"))))
(displayln (format "Part 1: ~a" (part1 ls)))
(displayln (format "Part 2: ~a" (part2 ls))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment