diff options
author | H.J <thechairman@thechairman.info> | 2024-10-09 11:36:55 -0400 |
---|---|---|
committer | H.J <thechairman@thechairman.info> | 2024-10-09 11:36:55 -0400 |
commit | 8777ff071f7bb37631baa7b6717ad29961e50911 (patch) | |
tree | 6d59c4ed58e454b960339c3d1151f0a879e8d7cb /aoc2018/day-02 | |
parent | 6156a9ef7be4012063a042aafb4e9b0d7eadde8e (diff) | |
download | gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.tar.gz gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.zip |
sorting by language
Diffstat (limited to 'aoc2018/day-02')
-rw-r--r-- | aoc2018/day-02/day-02.rkt | 27 |
1 files changed, 0 insertions, 27 deletions
diff --git a/aoc2018/day-02/day-02.rkt b/aoc2018/day-02/day-02.rkt deleted file mode 100644 index 38155fb..0000000 --- a/aoc2018/day-02/day-02.rkt +++ /dev/null @@ -1,27 +0,0 @@ -#lang racket - -(require advent-of-code - threading) - -(define ids (port->lines (open-aoc-input (find-session) 2018 2 #:cache #true))) - -;; part 1 -(define (make-baskets str) - (for/fold ([baskets (hash)]) ([ch (in-string str)]) - (hash-update baskets ch add1 0))) - -(define (has-count n ht) - (member n (hash-values ht))) - -(for/fold ([two 0] [three 0] #:result (* two three)) ([id (in-list ids)]) - (define baskets (make-baskets id)) - (values (if (has-count 2 baskets) (add1 two) two) (if (has-count 3 baskets) (add1 three) three))) - -;; part 2 -(define (string-difference str1 str2) - (for/sum ([ch1 (in-string str1)] [ch2 (in-string str2)]) (if (equal? ch1 ch2) 0 1))) - -(for*/first ([id1 (in-list ids)] [id2 (in-list ids)] #:when (= 1 (string-difference id1 id2))) - (~>> (for/list ([ch1 (in-string id1)] [ch2 (in-string id2)] #:when (equal? ch1 ch2)) - ch1) - (apply string))) |