The sub computer running a four-digit display, seven segments per digit, has garbled its output signals by running them through a permutation. The first problem involves counting the number of digit encodings uniquely determined by the number of segments used.
$ cat 08a.rkt #lang racket (provide example-input read-input ) (require (prefix-in aoc: "aoc.rkt") (prefix-in utl: "../scheme/utl.rkt") ) (define (aoc08a . args) ; Return the number of times the digits 1, 4, 7 or 8 appear in ; the given display input-output. If no display i-o is given, ; use the contest problem input; otherwise assume the argument ; is the string representation of a problem input. (length (filter (lambda (s) (member (length s) '(2 3 4 7))) (utl:flatten-to-n (map cadr (apply read-input args)) 1)))) (define (read-input . arg) ; Return the given display input-output. If no argument is ; given, use the contest problem input; otherwise assume the ; argument is the string representation of a problem input. (define (explode-string-list l) (map (lambda (s) (string->list s)) l)) (define (split-line l) (map explode-string-list (list (take l 10) (drop l 11)))) (map split-line (car (aoc:aoc-read-input (if (null? arg) 8 (car arg)))))) (define example-input (aoc:strings->string "be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | fdgacbe cefdb cefbgd gcbe" "edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec | fcgedb cgb dgebacf gc" "fgaebd cg bdaec gdafb agbcfd gdcbef bgcad gfac gcb cdgabef | cg cg fdcagb cbg" "fbegcd cbd adcefb dageb afcb bc aefdc ecdab fgdeca fcdbega | efabcd cedba gadfec cb" "aecbfdg fbg gf bafeg dbefa fcge gcbea fcaegb dgceab fcbdga | gecf egdcabf bgf bfgea" "fgeab ca afcebg bdacfeg cfaedg gcfdb baec bfadeg bafgc acf | gebdcfa ecba ca fadegcb" "dbcfg fgd bdegcaf fgec aegbdf ecdfab fbedc dacgb gdcebf gf | cefg dcbef fcge gbcadfe" "bdfegc cbegaf gecbf dfcage bdacg ed bedf ced adcbefg gebcd | ed bcgafe cdgba cbgef" "egadfb cdbfeg cegd fecab cgb gbdefca cg fgcdab egfdb bfceg | gbdfcae bgc cg cgb" "gcafb gcf dcaebfg ecagb gf abcdeg gaef cafbge fdbac fegbdc | fgae cfgab fg bagce" )) (define example-output 26) (module+ main (aoc08a) ) (module+ test (require rackunit) (for-each (lambda (p) (check-equal? (aoc08a (car p)) (cdr p))) '(("be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | fdgacbe cefdb cefbgd gcbe" . 2) ("edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec | fcgedb cgb dgebacf gc" . 3) ("fgaebd cg bdaec gdafb agbcfd gdcbef bgcad gfac gcb cdgabef | cg cg fdcagb cbg" . 3) ("fbegcd cbd adcefb dageb afcb bc aefdc ecdab fgdeca fcdbega | efabcd cedba gadfec cb" . 1) ("aecbfdg fbg gf bafeg dbefa fcge gcbea fcaegb dgceab fcbdga | gecf egdcabf bgf bfgea" . 3) ("fgeab ca afcebg bdacfeg cfaedg gcfdb baec bfadeg bafgc acf | gebdcfa ecba ca fadegcb" . 4) ("dbcfg fgd bdegcaf fgec aegbdf ecdfab fbedc dacgb gdcebf gf | cefg dcbef fcge gbcadfe" . 3) ("bdfegc cbegaf gecbf dfcage bdacg ed bedf ced adcbefg gebcd | ed bcgafe cdgba cbgef" . 1) ("egadfb cdbfeg cegd fecab cgb gbdefca cg fgcdab egfdb bfceg | gbdfcae bgc cg cgb" . 4) ("gcafb gcf dcaebfg ecagb gf abcdeg gaef cafbge fdbac fegbdc | fgae cfgab fg bagce" . 2))) (check-equal? (aoc08a example-input) example-output) (check-equal? (aoc08a) 416) ) $ raco test 08a.rkt raco test: (submod "08a.rkt" test) 12 tests passed $