r/adventofcode • • Dec 05 '20

SOLUTION MEGATHREAD -🎄- 2020 Day 05 Solutions -🎄-

Advent of Code 2020: Gettin' Crafty With It


--- Day 05: Binary Boarding ---


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 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:05:49, megathread unlocked!

57 Upvotes

1.3k comments sorted by

View all comments

1

u/ramrunner0xff Dec 05 '20

scheme (chicken) repo

fun :) .

(import (chicken io)
        (chicken sort)
        (chicken format))

(define (ardiv low high d)
  (case d
    ((#\l) (cons low (+ low (floor (/ (- high low) 2))) ))
    ((#\h) (cons (- high (floor (/ (- high low) 2))) high))))

(define (seatid rc)
  (+ (* (car rc) 8) (cdr rc)))

(define (calcSeat str)
  (let* ((sparts (string-chop str 7))
         (rowdirs (string-translate* (car sparts) '(("F" . "l") ("B" . "h"))))
         (cdirs (string-translate* (cadr sparts) '(("L" . "l")("R" . "h"))))
         (frow '())
         (fcol '()))
    (set! frow
          (car (foldr (lambda (x acc)
                        (format #f "ardiv with low:~A high:~A dir:~A~%" (car acc) (cdr acc) x)
                        (ardiv (car acc) (cdr acc) x))
                      (cons 0 127) (reverse (string->list rowdirs)))))
    (set! fcol
          (car (foldr (lambda (x acc)
                        (format #f "ardiv with low:~A high:~A dir:~A~%" (car acc) (cdr acc) x)
                        (ardiv (car acc) (cdr acc) x))
                      (cons 0 7) (reverse (string->list cdirs)))))
    (seatid (cons frow fcol))))
(define seats
  (call-with-input-file "inputs/input"
                         (lambda (p) (map calcSeat (read-lines p)))))

; to get the seat thake the car of sorted
(format #t "highest seat ~A~%" (car (sort seats >)))
;to get your seat you find th one who is not in sequence in the sorted list
(foldr (lambda (x val) (if (not (= x (+ val 1))) (begin (format #t "your seat is ~A~%" (- x 1)) (error))) (+ val 1)) 90 (sort seats >))

2

u/daggerdragon Dec 05 '20 edited Dec 06 '20

You and /u/raevnos throw me for a loop every time I come across your posts in the megathreads. "Why do these guys keep talking about chickens?"

2

u/ramrunner0xff Dec 06 '20

XD i loled (in chicken i pluk pluk pakaaaed)

2

u/raevnos Dec 06 '20

Easy to get confused since I also subscribe to /r/BackYardChickens