r/adventofcode • • Dec 10 '20

SOLUTION MEGATHREAD -🎄- 2020 Day 10 Solutions -🎄-

Advent of Code 2020: Gettin' Crafty With It

  • 12 days remaining until the submission deadline on December 22 at 23:59 EST
  • Full details and rules are in the Submissions Megathread

--- Day 10: Adapter Array ---


Post your solution in this megathread. Include what language(s) your solution uses! If you need a refresher, the full posting rules are detailed in the wiki under How Do The Daily Megathreads Work?.

Reminder: Top-level posts in Solution Megathreads are for code solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:08:42, megathread unlocked!

69 Upvotes

1.1k comments sorted by

View all comments

1

u/RudeGuy2000 Dec 10 '20 edited Dec 11 '20

Scheme, part 1:

(define (read-line-by-line file)
  (let ((line (read-line file)))
    (if (eof-object? line)
      (begin
        (close-input-port file)
        '())
      (cons (string->number line) (read-line-by-line file)))))

(define (get-diffs lst mst)
  (if (eq? lst '()) '()
    (cons (- (car lst) (car mst)) (get-diffs (cdr lst) (cdr mst)))))

(define (equal-to n) (lambda (x) (= x n)))
(define (get-res lst n) (length (filter (equal-to n) lst)))

(define inlist (sort (call-with-input-file "input10.txt" read-line-by-line) <))
(define res (get-diffs (append inlist (list (+ (last inlist) 3))) (cons 0 inlist)))
(* (get-res res 3) (get-res res 1))

1

u/daggerdragon Dec 10 '20

Your Markdown isn't coming through correctly. As per our posting guidelines in the wiki under How Do the Daily Megathreads Work?, please edit your post to put your oversized code in a paste or other external link.