From bc77b0e75f4b4f5f1e4411c9a8e2108875810a60 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sun, 15 Dec 2019 21:48:17 -0800 Subject: [PATCH] d15 p1 --- 2019/15.rkt | 24 ++++++++++++++++++++++++ 2019/15.rktd | 1 + 2 files changed, 25 insertions(+) create mode 100644 2019/15.rkt create mode 100644 2019/15.rktd diff --git a/2019/15.rkt b/2019/15.rkt new file mode 100644 index 0000000..234b73e --- /dev/null +++ b/2019/15.rkt @@ -0,0 +1,24 @@ +#lang br +(require racket/file rackunit) + +(define (make-patintss ints) + (for/list ([i (in-range (length ints))]) + (apply append (map (curry make-list (add1 i)) '(0 1 0 -1))))) + +(define (fft str [phase-count 1]) + (for/fold ([ints (for/list ([c (in-string str)]) + (string->number (string c)))] + #:result (take ints 8)) + ([pidx (in-range phase-count)]) + (for/list ([patints (in-list (make-patintss ints))]) + (modulo (abs (for/sum ([int (in-list (cons 0 ints))] ; cons 0 to burn off first patint + [patint (in-cycle patints)]) + (* int patint))) 10)))) + + +(check-equal? (fft "80871224585914546619083218645595" 100) '(2 4 1 7 6 1 7 6)) +(check-equal? (fft "19617804207202209144916044189917" 100) '(7 3 7 4 5 4 1 8)) +(check-equal? (fft "69317163492948606335995924319873" 100) '(5 2 4 3 2 1 3 3)) + +;; 1 +(check-equal? (fft (file->string "15.rktd") 100) '(8 5 7 2 6 5 0 2)) \ No newline at end of file diff --git a/2019/15.rktd b/2019/15.rktd new file mode 100644 index 0000000..19fae88 --- /dev/null +++ b/2019/15.rktd @@ -0,0 +1 @@ +59773775883217736423759431065821647306353420453506194937477909478357279250527959717515453593953697526882172199401149893789300695782513381578519607082690498042922082853622468730359031443128253024761190886248093463388723595869794965934425375464188783095560858698959059899665146868388800302242666479679987279787144346712262803568907779621609528347260035619258134850854741360515089631116920328622677237196915348865412336221562817250057035898092525020837239100456855355496177944747496249192354750965666437121797601987523473707071258599440525572142300549600825381432815592726865051526418740875442413571535945830954724825314675166862626566783107780527347044 \ No newline at end of file