Skip to content

Instantly share code, notes, and snippets.

@winny-

winny-/day2.rkt Secret

Created December 2, 2017 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save winny-/f2cbc4437f8f98856590bcc8d3f7cfed to your computer and use it in GitHub Desktop.
Save winny-/f2cbc4437f8f98856590bcc8d3f7cfed 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]
[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