|(require aoc-racket/day08)||package: aoc-racket|
The puzzle relies the fact that within strings, certain single characters — like the backslash \ and double-quote mark " — are described with more than one character. Thus, the question asks us to compare the two lengths.
(define (memory-length str) (string-length (read (open-input-string str)))) (define (q1 strs) (- (apply + (map string-length strs)) (apply + (map memory-length strs))))
8.2 What’s the difference between the re-encoded length of the literal string, and the original length?
This question simply comes down to — do you know how to use the string-formatting functions in your programming language?
In Racket, a string can be re-encoded with ~v. Not a very puzzling puzzle overall.