Skip to content

Instantly share code, notes, and snippets.

@winny- winny-/day1.rkt Secret
Created Dec 1, 2017

Embed
What would you like to do?
#lang racket
(define (part1 ls)
(match-define (list-rest a tail) ls)
(define-values (n p)
(for/fold ([n 0]
[prev a])
([m (append tail (list a))])
(values (if (= prev m)
(+ n m)
n)
m)))
n)
(define (part2 ls)
(define-values (head tail) (split-at ls (quotient (length ls) 2)))
(for/fold ([n 0])
([a ls]
[b (append tail head)])
(if (= a b)
(+ n a)
n)))
(module+ main
(define ls (map (compose string->number string)
(string->list (read-line))))
(displayln (format "Part 1: ~a" (part1 ls)))
(displayln (format "Part 2: ~a" (part2 ls))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.