Skip to content

Commit 3a79b44

Browse files
committed
Day 2, second solution
1 parent 9c08112 commit 3a79b44

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

day2_1.rkt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@
2626
(define test-inputs
2727
(list "abcdef" "bababc" "abbcde" "abcccd" "aabcdd" "abcdee" "ababab"))
2828

29-
(= 12 (solve-puzzle test-inputs))
29+
(= 12 (solve-puzzle test-inputs))
30+
31+
;(solve-puzzle (file->lines "day2_1-input.txt"))

day2_2.rkt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#lang racket
2+
3+
(require threading)
4+
5+
(define (find-equals full-list word)
6+
(~>> full-list
7+
(map (λ (ele)
8+
(foldr (λ (ele acc)
9+
(if (equal? (car ele) (cdr ele))
10+
(cons (car ele) acc)
11+
acc))
12+
(list)
13+
(map cons word ele))))
14+
(filter (λ (e) (= (sub1 (length word))
15+
(length e))))))
16+
17+
(define (solve-puzzle input)
18+
(let ([mapped (map string->list input)])
19+
(~>> mapped
20+
(map (curry find-equals mapped))
21+
(filter (compose not empty?))
22+
(first)
23+
(flatten)
24+
(list->string))))
25+
26+
(define test-input
27+
(list "abcde" "fghij" "klmno" "pqrst" "fguij" "axcye" "wvxyz"))
28+
29+
(equal? "fgij" (solve-puzzle test-input))
30+
31+
;(solve-puzzle (file->lines "day2_1-input.txt"))

0 commit comments

Comments
 (0)