Add 2021 advent - day 1.

Time to learn Racket/Scheme?
This commit is contained in:
Érico Nogueira 2021-12-01 15:57:40 -03:00
parent 462062498f
commit d8888bad83
4 changed files with 2049 additions and 0 deletions

16
2021/day1/day1.rkt Normal file
View File

@ -0,0 +1,16 @@
#lang racket
(define (go)
'yep-it-works)
(go)
(define count 0)
(define old 5000)
(for ([t (in-lines)])
(define new (string->number t))
(if (> new old)
(set! count (+ count 1))
#f)
(set! old new))
(display count)

23
2021/day1/day1p2.rkt Normal file
View File

@ -0,0 +1,23 @@
#lang racket
(define l null)
(for ([t (in-lines)])
(define new (string->number t))
(set! l (cons new l)))
(define v (list->vector (reverse l)))
(define (vsum vec pos)
(define p1 (vector-ref vec pos))
(define p2 (vector-ref vec (+ pos 1)))
(define p3 (vector-ref vec (+ pos 2)))
(+ p1 (+ p2 p3)))
(define count 0)
(define len (vector-length v))
(for/list ([i (in-range len)])
(if (and (<= (+ i 4) len) (< (vsum v i) (vsum v (+ i 1))))
(set! count (+ count 1))
#f))
(display count)

10
2021/day1/txt1 Normal file
View File

@ -0,0 +1,10 @@
199
200
208
210
200
207
240
269
260
263

2000
2021/day1/txt2 Normal file

File diff suppressed because it is too large Load Diff