This commit is contained in:
Jonathan Chan 2021-12-02 22:15:28 -08:00
parent 5a544b2649
commit 56ae75908b
2 changed files with 1036 additions and 0 deletions

1000
input/03.txt Normal file

File diff suppressed because it is too large Load Diff

36
src/03.rkt Normal file
View File

@ -0,0 +1,36 @@
#lang curly-fn racket
(require "../lib.rkt")
(define input
(for/list ([b (problem-input 3)])
(string->list b)))
(define chars->binary
( string->binary list->string))
(define (nth-bit nums p n)
(let ([bs (map #{list-ref % n} nums)])
(if (p (count ( char=? #\1) bs) (/ (length nums) 2))
#\1 #\0)))
(define (squimsh p)
(~> (range (length (first input)))
(map #{nth-bit input p %} _)
chars->binary))
(define (search p)
(let loop ([nums input]
[n 0])
(if (= (length nums) 1)
(chars->binary (first nums))
(let ([bit (nth-bit nums p n)])
(loop (filter #{char=? bit (list-ref % n)} nums) (add1 n))))))
(define part1
(* (squimsh >=) (squimsh <)))
(define part2
(* (search >=) (search <)))
(show-solution part1 part2)