Hello dear readers! 😁
This year I’m doing Advent of Code which, behold, I had never done before. I’m not sure why that’s the case as I had always heard about it every year since it began - but the fact is for some reason it never really interested me.
A lot of people seem to treat the problems as coding exercises, going through great lengths to create “clean code” (I very much dislike this term for some reason), but I really can’t force myself to do the same: the problems are simply too straightforward to even turn on the little “systems design” guy in my head. I very much prefer doing it as a speed coding exercise.
☝️famous last words, ask me about that on day 25
I even went back to LeetCode to check if I was not crazy and the problems had the same level of complexity and for sure they don’t. LeetCode medium problems are at least twice as hard as the hardest problem so far (on day 14).
On one side this is not super enticing, but on the other it’s nice because you can solve all problems in around one hour, which is great for not sucking the life out of you.
I’m using Racket - and to be really honest the only reason is I like having descriptive function names for everything and a nice standard library. It really feels like a faster nicer Ruby.
Take this solution for problem 6 with you:
#lang racket (require racket/file racket/set rackunit) (define (find-start stream (window (list)) (offset 0)) (if (or (= 4 (length (remove-duplicates window))) (empty? stream)) offset (find-start (rest stream) (cons (first stream) (take window (min 3 (length window)))) (+ 1 offset)))) (define (solution f) (find-start (string->list (file->string f)))) (check-equal? (find-start (string->list "mjqjpqmgbljsphdztnvjfqwrcgsmlb")) 7) (check-equal? (find-start (string->list "bvwbjplbgvbhsrlpgdmjqwftvncz")) 5) (check-equal? (find-start (string->list "nppdvjthqldpwncqszvftbrmjlhg")) 6) (check-equal? (find-start (string->list "nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg")) 10) (check-equal? (find-start (string->list "zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw")) 11) (solution "input")
I’m uploading my solutions on GitHub.