Created
December 12, 2020 06:42
-
-
Save saahityaedams/e767dd4bd2076b612809060d7b8da134 to your computer and use it in GitHub Desktop.
aoc 6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #lang racket | |
| (define input | |
| (port->lines (open-input-file "input6.in"))) | |
| ; for Section 1 | |
| ; (define (split-groups gs) | |
| ; (let aux [(in gs) (curr-g "") (out `())] | |
| ; (cond | |
| ; [(null? (cdr in)) (cons curr-g out)] | |
| ; [(equal? (car in) "") (aux (cdr in) "" (cons curr-g out))] | |
| ; [else (aux (cdr in) (string-append curr-g (car in)) out)]))) | |
| ; (define (split-group-into-char-set-len g) (length (remove-duplicates (map string (string->list g))))) | |
| ; (define (split-group-into-char-set-len g) (length (remove-duplicates (map string (string->list g))))) | |
| ; (apply + (map split-group-into-char-set-len (split-groups input))) | |
| (define (split-groups gs) | |
| (let aux [(in gs) (curr-g `()) (out `())] | |
| (cond | |
| [(null? (cdr in)) (cons curr-g out)] | |
| [(equal? (car in) "") (aux (cdr in) `() (cons curr-g out))] | |
| [else (aux (cdr in) (cons (string->list (car in)) curr-g) out)]))) | |
| (define (count-intersect g) (length (group-intersect g))) | |
| (define (group-intersect g) | |
| (let aux [(in g) (out (car g))] | |
| (cond | |
| [(null? (cdr in)) (set-intersect (car in) out)] | |
| [else (aux (cdr in) (set-intersect (car in) out))]))) | |
| (apply + (map count-intersect (split-groups input))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment