day 14: now part 1 is no longer commented

This commit is contained in:
xenia 2020-12-14 00:28:48 -05:00
parent d2baefb506
commit 9528e81713
1 changed files with 20 additions and 19 deletions

39
14.rkt
View File

@ -5,24 +5,25 @@
;; solution for day 14 ;; solution for day 14
(define (part1 input) (define (part1 input)
(void)) (define (parse-mask msk)
; (define (parse-mask msk) (define orval (for/fold ([val 0]) ([chr (in-string msk)])
; (define orval (for/fold ([val 0]) ([chr (in-string msk)]) (+ (* val 2) (if (equal? chr #\1) 1 0))))
; (+ (* val 2) (if (equal? chr #\1) 1 0)))) (define andval (for/fold ([val 0]) ([chr (in-string msk)])
; (define andval (for/fold ([val 0]) ([chr (in-string msk)]) (+ (* val 2) (if (equal? chr #\0) 0 1))))
; (+ (* val 2) (if (equal? chr #\0) 0 1)))) (values orval andval))
; (cons orval andval)) (define orval 0)
; (define orval 0) (define andval (sub1 (expt 2 37)))
; (define andval (sub1 (expt 2 37))) (define mem (make-hash))
; (define mem (make-hash)) (for ([ins (in-list input)])
; (for ([ins (in-list input)]) (match ins
; (match ins [(cons 'mask mask)
; [(cons 'mask (cons ov av)) (set! orval ov) (set! andval av)] (define-values [ov av] (parse-mask mask))
; [(cons 'set (cons addr val)) (set! orval ov) (set! andval av)]
; (define new-val (bitwise-ior (bitwise-and val andval) orval)) [(cons 'set (cons addr val))
; (hash-set! mem addr new-val)])) (define new-val (bitwise-ior (bitwise-and val andval) orval))
; (for/sum ([(k v) (in-hash mem)]) (hash-set! mem addr new-val)]))
; v)) (for/sum ([(k v) (in-hash mem)])
v))
(define (addr->bits addr) (define (addr->bits addr)
(vector-copy (vector-copy
@ -37,7 +38,7 @@
(define mask #f) (define mask #f)
(for ([ins (in-list input)]) (for ([ins (in-list input)])
(match ins (match ins
[(cons 'mask m) (set! mask m) (displayln mask)] [(cons 'mask m) (set! mask m)]
[(cons 'set (cons addr val)) [(cons 'set (cons addr val))
(define addr-bits (addr->bits addr)) (define addr-bits (addr->bits addr))
(for ([chr (in-string mask)] [i (in-naturals)]) (for ([chr (in-string mask)] [i (in-naturals)])