@ -160,13 +160,13 @@ Again, run =count= with this validator on the parsed input data.
I wanted to see if I could do the Part 2 validator with almost nothing but regex, so I did that.
* Day 5: Binary Boarding
** Part 1
I did some stuff with doing manual BSP here, but I'm a fucking idiot and couldn't get it to work.
I am a failure at the one thing that I should be good at and I should be ashamed of myself.
Anyway, each boarding pass can actually be treated as a binary number. F and L are zero digits,
Each boarding pass can actually be treated as a binary number. F and L are zero digits,
B and R are one digits. The ID is =row * 8 + column=, and the column part is 3 digits, so... uh...
Convert them all to IDs, maximize 'em.
** Part 2
Find the first ID that's missing but doesn't have neighbors. This is just =(first (memf ...))=.
I re-did this with manual BSP, since I tried and failed at that for a while before realizing the
binary string method.
@ -1,6 +1,35 @@
;; naive solution: manual BSP
(define (lower-half lst)
(take lst (quotient (length lst) 2)))
(define (upper-half lst)
(drop lst (quotient (length lst) 2)))
(define (pass->seat str)
(define (row-bsp row)
(for/fold ([rng (range 0 127)])
([ch (in-string row)])
[#\F (lower-half rng)]
[#\B (upper-half rng)]))))
(define (col-bsp col)
(for/fold ([rng (range 0 8)])
([ch (in-string col)])
[#\L (lower-half rng)]
[#\R (upper-half rng)]))))
(define row-pass (substring str 0 7))
(define col-pass (substring str 7 10))
(cons (add1 (row-bsp row-pass)) (col-bsp col-pass)))
(define (seat->id seat)
(+ (* (car seat) 8) (cdr seat)))
;; big brain solution: it's just a binary string
(define (pass->id str)
(for/fold ([id 0])
([ch (in-string str)])
@ -10,10 +39,10 @@
[(#\B #\R) 1]))))
(define (day5a in)
(apply max (map pass->id in)))
(apply max (map (compose1 seat->id pass->seat) in)))
(define (day5b in)
(define ids (map pass->id in))
(define ids (map (compose1 seat->id pass->seat) in))
(first (memf (lambda (id)
(and (not (member id ids))
(member (add1 id) ids)