From 0bcab1f340ff36e25d9711523c243e5aa294656d Mon Sep 17 00:00:00 2001 From: Jonathan Chan Date: Sat, 30 Nov 2019 21:37:37 -0800 Subject: [PATCH] Day 1. --- .gitignore | 2 + input/01.txt | 100 +++++++ lib.rkt | 28 ++ src/01.rkt | 716 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 846 insertions(+) create mode 100644 .gitignore create mode 100644 input/01.txt create mode 100644 lib.rkt create mode 100644 src/01.rkt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..35a4f73 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +**/*.bak +compiled/ diff --git a/input/01.txt b/input/01.txt new file mode 100644 index 0000000..e15a9aa --- /dev/null +++ b/input/01.txt @@ -0,0 +1,100 @@ +142195 +119326 +57976 +138834 +132685 +113092 +88731 +52063 +122899 +78681 +117881 +121912 +112633 +85163 +145655 +76668 +92939 +81941 +62645 +126482 +114642 +55588 +95934 +68172 +62160 +111109 +141496 +97453 +83723 +50309 +82930 +66124 +142265 +100066 +147434 +149708 +77906 +71147 +76590 +59528 +67973 +68187 +135534 +129331 +147054 +89062 +63159 +80990 +103402 +139627 +87251 +66561 +102708 +91307 +121287 +149077 +142275 +144917 +98677 +114912 +102236 +56147 +130660 +63523 +112577 +75086 +136006 +142090 +80446 +53900 +144975 +143195 +138974 +60145 +132474 +62640 +62270 +76275 +62315 +85065 +99617 +73579 +97553 +79715 +81297 +77342 +142907 +114001 +137846 +122398 +71457 +133929 +110617 +68928 +56741 +87754 +53907 +68322 +85782 +140916 \ No newline at end of file diff --git a/lib.rkt b/lib.rkt new file mode 100644 index 0000000..8671871 --- /dev/null +++ b/lib.rkt @@ -0,0 +1,28 @@ +#lang racket + +(require racket/format + 2htdp/batch-io) + +(provide problem-input + show-solution + sum) + +;; IO helpers + +;; problem-input : number? -> (listof string?) +;; Return contents of input file input/xx.txt as lines of strings. +(define (problem-input n) + (let* ([filename (~a n #:min-width 2 #:align 'right #:left-pad-string "0")] + [path (string-append "../input/" filename ".txt")]) + (read-lines path))) + +;; show-solution : any/c -> any/c -> void +;; Print part1 and part2 on separate lines. +(define (show-solution part1 part2) + (printf "Part 1: ~a\nPart 2: ~a\n" part1 part2)) + + +;; Common helpers + +;; sum : (listof number) -> number +(define (sum ns) (apply + ns)) \ No newline at end of file diff --git a/src/01.rkt b/src/01.rkt new file mode 100644 index 0000000..b650162 --- /dev/null +++ b/src/01.rkt @@ -0,0 +1,716 @@ +#reader(lib"read.ss""wxme")WXME0108 ## +#| + This file uses the GRacket editor format. + Open this file in DrRacket version 7.0 or later to read it. + + Most likely, it was created by saving a program in DrRacket, + and it probably contains a program with non-text elements + (such as images or comment boxes). + + http://racket-lang.org/ +|# + 33 7 #"wxtext\0" +3 1 6 #"wxtab\0" +1 1 8 #"wximage\0" +2 0 8 #"wxmedia\0" +4 1 34 #"(lib \"syntax-browser.ss\" \"mrlib\")\0" +1 0 36 #"(lib \"cache-image-snip.ss\" \"mrlib\")\0" +1 0 68 +( + #"((lib \"image-core.ss\" \"mrlib\") (lib \"image-core-wxme.rkt\" \"mr" + #"lib\"))\0" +) 1 0 16 #"drscheme:number\0" +3 0 44 #"(lib \"number-snip.ss\" \"drscheme\" \"private\")\0" +1 0 36 #"(lib \"comment-snip.ss\" \"framework\")\0" +1 0 93 +( + #"((lib \"collapsed-snipclass.ss\" \"framework\") (lib \"collapsed-sni" + #"pclass-wxme.ss\" \"framework\"))\0" +) 0 0 43 #"(lib \"collapsed-snipclass.ss\" \"framework\")\0" +0 0 19 #"drscheme:sexp-snip\0" +0 0 29 #"drscheme:bindings-snipclass%\0" +1 0 101 +( + #"((lib \"ellipsis-snip.rkt\" \"drracket\" \"private\") (lib \"ellipsi" + #"s-snip-wxme.rkt\" \"drracket\" \"private\"))\0" +) 2 0 88 +( + #"((lib \"pict-snip.rkt\" \"drracket\" \"private\") (lib \"pict-snip.r" + #"kt\" \"drracket\" \"private\"))\0" +) 0 0 55 +#"((lib \"snip.rkt\" \"pict\") (lib \"snip-wxme.rkt\" \"pict\"))\0" +1 0 34 #"(lib \"bullet-snip.rkt\" \"browser\")\0" +0 0 25 #"(lib \"matrix.ss\" \"htdp\")\0" +1 0 22 #"drscheme:lambda-snip%\0" +1 0 29 #"drclickable-string-snipclass\0" +0 0 26 #"drracket:spacer-snipclass\0" +0 0 57 +#"(lib \"hrule-snip.rkt\" \"macro-debugger\" \"syntax-browser\")\0" +1 0 26 #"drscheme:pict-value-snip%\0" +0 0 45 #"(lib \"image-snipr.ss\" \"slideshow\" \"private\")\0" +1 0 38 #"(lib \"pict-snipclass.ss\" \"slideshow\")\0" +2 0 55 #"(lib \"vertical-separator-snip.ss\" \"stepper\" \"private\")\0" +1 0 18 #"drscheme:xml-snip\0" +1 0 31 #"(lib \"xml-snipclass.ss\" \"xml\")\0" +1 0 21 #"drscheme:scheme-snip\0" +2 0 34 #"(lib \"scheme-snipclass.ss\" \"xml\")\0" +1 0 10 #"text-box%\0" +1 0 32 #"(lib \"text-snipclass.ss\" \"xml\")\0" +1 0 1 6 #"wxloc\0" + 0 0 81 0 1 #"\0" +0 75 1 #"\0" +0 10 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 0 9 +#"Standard\0" +0 75 12 #"Courier New\0" +0 10 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 2 1 +#"\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 2 24 +#"framework:default-color\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1 +#"\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 15 +#"text:ports out\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 150 0 150 0 0 0 -1 -1 2 1 +#"\0" +0 -1 1 #"\0" +1.0 0 -1 -1 93 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 255 0 0 0 0 0 -1 +-1 2 15 #"text:ports err\0" +0 -1 1 #"\0" +1 0 -1 -1 93 -1 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 1 +#"\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 17 +#"text:ports value\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 0 0 175 0 0 0 -1 -1 2 1 +#"\0" +0 -1 1 #"\0" +1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1 +-1 2 27 #"Matching Parenthesis Style\0" +0 -1 1 #"\0" +1.0 0 92 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 34 139 34 0 0 0 -1 +-1 2 1 #"\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 37 +#"framework:syntax-color:scheme:symbol\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 38 +#"framework:syntax-color:scheme:keyword\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 38 38 128 0 0 0 -1 -1 2 1 +#"\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2 +38 #"framework:syntax-color:scheme:comment\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 194 116 31 0 0 0 -1 -1 2 1 +#"\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 37 +#"framework:syntax-color:scheme:string\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 35 +#"framework:syntax-color:scheme:text\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 39 +#"framework:syntax-color:scheme:constant\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 41 128 38 0 0 0 -1 -1 2 1 +#"\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 49 +#"framework:syntax-color:scheme:hash-colon-keyword\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 42 +#"framework:syntax-color:scheme:parenthesis\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 132 60 36 0 0 0 -1 -1 2 1 +#"\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 36 +#"framework:syntax-color:scheme:error\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 1 +#"\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 36 +#"framework:syntax-color:scheme:other\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 16 +#"Misspelled Text\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1 +#"\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 81 112 203 0 0 0 -1 -1 2 +38 #"drracket:check-syntax:lexically-bound\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 81 112 203 0 0 0 -1 -1 2 1 +#"\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 178 34 34 0 0 0 -1 -1 2 28 +#"drracket:check-syntax:set!d\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 178 34 34 0 0 0 -1 -1 2 37 +#"drracket:check-syntax:unused-require\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 36 +#"drracket:check-syntax:free-variable\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 1 +#"\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 68 0 203 0 0 0 -1 -1 2 31 +#"drracket:check-syntax:imported\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 68 0 203 0 0 0 -1 -1 2 47 +#"drracket:check-syntax:my-obligation-style-pref\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 178 34 34 0 0 0 -1 -1 2 1 +#"\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 0 116 0 0 0 0 -1 -1 2 50 +#"drracket:check-syntax:their-obligation-style-pref\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 0 116 0 0 0 0 -1 -1 2 48 +#"drracket:check-syntax:unk-obligation-style-pref\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1 +#"\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 139 142 28 0 0 0 -1 -1 2 +49 #"drracket:check-syntax:both-obligation-style-pref\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 139 142 28 0 0 0 -1 -1 2 +26 #"plt:htdp:test-coverage-on\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 1 +#"\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 2 27 +#"plt:htdp:test-coverage-off\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 4 1 +#"\0" +0 70 1 #"\0" +1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0 +-1 -1 4 4 #"XML\0" +0 70 1 #"\0" +1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0 +-1 -1 2 37 #"plt:module-language:test-coverage-on\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 -1 2 38 +#"plt:module-language:test-coverage-off\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 93 -1 -1 0 1 0 0 0 1 0 0 0 0 0 0 255 165 0 0 0 0 -1 -1 4 1 +#"\0" +0 71 1 #"\0" +1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0 +-1 -1 4 1 #"\0" +0 -1 1 #"\0" +1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1 +-1 4 1 #"\0" +0 71 1 #"\0" +1.0 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 0 255 0 0 0 -1 +-1 4 1 #"\0" +0 71 1 #"\0" +1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1.0 1.0 1.0 0 100 0 0 0 0 -1 +-1 2 1 #"\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 200 0 0 0 0 0 -1 -1 4 32 +#"widget.rkt::browser-text% basic\0" +0 70 1 #"\0" +1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0 +-1 -1 4 59 +#"macro-debugger/syntax-browser/properties color-text% basic\0" +0 70 1 #"\0" +1.0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0 +-1 -1 57 1 #"\0" +0 -1 1 #"\0" +1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1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#"require" +0 0 24 3 1 #" " +0 0 19 3 12 #"\"../lib.rkt\"" +0 0 24 3 1 #")" +0 0 24 29 1 #"\n" +0 0 24 29 1 #"\n" +0 9 1651 21 0 0 0 274 0 14 3 3 #"DAY" +0 0 24 3 1 #" " +0 0 14 3 2 #"1:" +0 0 24 3 1 #" " +0 0 14 3 3 #"The" +0 0 24 3 1 #" " +0 0 14 3 7 #"Tyranny" +0 0 24 3 1 #" " +0 0 14 3 2 #"of" +0 0 24 3 1 #" " +0 0 14 3 3 #"the" +0 0 24 3 1 #" " +0 0 14 3 6 #"Rocket" +0 0 24 3 1 #" " +0 0 14 3 8 #"Equation" +0 0 24 3 2 #" (" +0 0 14 3 7 #"excerpt" +0 0 24 3 1 #")" +0 0 24 29 1 #"\n" +0 0 24 29 1 #"\n" +0 0 14 3 4 #"PART" +0 0 24 3 1 #" " +0 0 14 3 2 #"1:" +0 0 24 29 1 #"\n" +0 0 14 3 3 #"..." +0 0 24 29 1 #"\n" +0 0 14 3 4 #"Fuel" +0 0 24 3 1 #" " +0 0 14 3 8 #"required" +0 0 24 3 1 #" " +0 0 14 3 2 #"to" +0 0 24 3 1 #" " +0 0 14 3 6 #"launch" +0 0 24 3 1 #" " +0 0 14 3 1 #"a" +0 0 24 3 1 #" " +0 0 14 3 5 #"given" +0 0 24 3 1 #" " +0 0 15 3 6 #"module" +0 0 24 3 1 #" " +0 0 14 3 2 #"is" +0 0 24 3 1 #" " +0 0 14 3 5 #"based" +0 0 24 3 1 #" " +0 0 14 3 2 #"on" +0 0 24 3 1 #" " +0 0 14 3 3 #"its" +0 0 24 3 1 #" " +0 0 14 3 5 #"mass." +0 0 24 29 1 #"\n" +0 0 14 3 12 #"Specifically" +0 0 28 3 1 #"," +0 0 24 3 1 #" " +0 0 14 3 2 #"to" +0 0 24 3 1 #" " +0 0 14 3 4 #"find" +0 0 24 3 1 #" " +0 0 14 3 3 #"the" +0 0 24 3 1 #" " +0 0 14 3 4 #"fuel" +0 0 24 3 1 #" " +0 0 14 3 8 #"required" +0 0 24 3 1 #" " +0 0 15 3 3 #"for" +0 0 24 3 1 #" " +0 0 14 3 1 #"a" +0 0 24 3 1 #" " +0 0 15 3 6 #"module" +0 0 28 3 1 #"," +0 0 24 3 1 #" " +0 0 14 3 4 #"take" +0 0 24 3 1 #" " +0 0 14 3 3 #"its" +0 0 24 3 1 #" " +0 0 14 3 4 #"mass" +0 0 28 3 1 #"," +0 0 24 29 1 #"\n" +0 0 14 3 6 #"divide" +0 0 24 3 1 #" " +0 0 14 3 2 #"by" +0 0 24 3 1 #" " +0 0 14 3 5 #"three" +0 0 28 3 1 #"," +0 0 24 3 1 #" " +0 0 14 3 5 #"round" +0 0 24 3 1 #" " +0 0 14 3 4 #"down" +0 0 28 3 1 #"," +0 0 24 3 1 #" " +0 0 14 3 3 #"and" +0 0 24 3 1 #" " +0 0 14 3 8 #"subtract" +0 0 24 3 1 #" " +0 0 21 3 2 #"2." +0 0 24 29 1 #"\n" +0 0 14 3 3 #"..." +0 0 24 29 1 #"\n" +0 0 14 3 4 #"What" +0 0 24 3 1 #" " +0 0 14 3 2 #"is" +0 0 24 3 1 #" " +0 0 14 3 3 #"the" +0 0 24 3 1 #" " +0 0 14 3 3 #"sum" +0 0 24 3 1 #" " +0 0 14 3 2 #"of" +0 0 24 3 1 #" " +0 0 14 3 3 #"the" +0 0 24 3 1 #" " +0 0 14 3 4 #"fuel" +0 0 24 3 1 #" " +0 0 14 3 12 #"requirements" +0 0 24 3 1 #" " +0 0 15 3 3 #"for" +0 0 24 3 1 #" " +0 0 14 3 3 #"all" +0 0 24 3 1 #" " +0 0 14 3 2 #"of" +0 0 24 3 1 #" " +0 0 14 3 3 #"the" +0 0 24 3 1 #" " +0 0 14 3 7 #"modules" +0 0 24 29 1 #"\n" +0 0 14 3 2 #"on" +0 0 24 3 1 #" " +0 0 14 3 4 #"your" +0 0 24 3 1 #" " +0 0 14 3 11 #"spacecraft?" +0 0 24 29 1 #"\n" +0 0 24 29 1 #"\n" +0 0 14 3 4 #"PART" +0 0 24 3 1 #" " +0 0 14 3 2 #"2:" +0 0 24 29 1 #"\n" +0 0 14 3 3 #"..." +0 0 24 29 1 #"\n" +0 0 14 3 2 #"So" +0 0 28 3 1 #"," +0 0 24 3 1 #" " +0 0 15 3 3 #"for" +0 0 24 3 1 #" " +0 0 14 3 4 #"each" +0 0 24 3 1 #" " +0 0 15 3 6 #"module" +0 0 24 3 1 #" " +0 0 14 3 4 #"mass" +0 0 28 3 1 #"," +0 0 24 3 1 #" " +0 0 14 3 9 #"calculate" +0 0 24 3 1 #" " +0 0 14 3 3 #"its" +0 0 24 3 1 #" " +0 0 14 3 4 #"fuel" +0 0 24 3 1 #" " +0 0 14 3 3 #"and" +0 0 24 3 1 #" " +0 0 14 3 3 #"add" +0 0 24 3 1 #" " +0 0 14 3 2 #"it" +0 0 24 3 1 #" " +0 0 14 3 2 #"to" +0 0 24 3 1 #" " +0 0 14 3 3 #"the" +0 0 24 3 1 #" " +0 0 14 3 6 #"total." +0 0 24 29 1 #"\n" +0 0 14 3 4 #"Then" +0 0 28 3 1 #"," +0 0 24 3 1 #" " +0 0 14 3 5 #"treat" +0 0 24 3 1 #" " +0 0 14 3 3 #"the" +0 0 24 3 1 #" " +0 0 14 3 4 #"fuel" +0 0 24 3 1 #" " +0 0 14 3 6 #"amount" +0 0 24 3 1 #" " +0 0 14 3 3 #"you" +0 0 24 3 1 #" " +0 0 14 3 4 #"just" +0 0 24 3 1 #" " +0 0 14 3 10 #"calculated" +0 0 24 3 1 #" " +0 0 14 3 2 #"as" +0 0 24 3 1 #" " +0 0 14 3 3 #"the" +0 0 24 3 1 #" " +0 0 14 3 5 #"input" +0 0 24 3 1 #" " +0 0 14 3 4 #"mass" +0 0 24 29 1 #"\n" +0 0 14 3 3 #"and" +0 0 24 3 1 #" " +0 0 14 3 6 #"repeat" +0 0 24 3 1 #" " +0 0 14 3 3 #"the" +0 0 24 3 1 #" " +0 0 14 3 7 #"process" +0 0 28 3 1 #"," +0 0 24 3 1 #" " +0 0 14 3 10 #"continuing" +0 0 24 3 1 #" " +0 0 14 3 5 #"until" +0 0 24 3 1 #" " +0 0 14 3 1 #"a" +0 0 24 3 1 #" " +0 0 14 3 4 #"fuel" +0 0 24 3 1 #" " +0 0 14 3 11 #"requirement" +0 0 24 3 1 #" " +0 0 14 3 2 #"is" +0 0 24 3 1 #" " +0 0 14 3 4 #"zero" +0 0 24 29 1 #"\n" +0 0 14 3 2 #"or" +0 0 24 3 1 #" " +0 0 14 3 9 #"negative." +0 0 24 29 1 #"\n" +0 0 14 3 3 #"..." +0 0 24 29 1 #"\n" +0 0 14 3 4 #"What" +0 0 24 3 1 #" " +0 0 14 3 2 #"is" +0 0 24 3 1 #" " +0 0 14 3 3 #"the" +0 0 24 3 1 #" " +0 0 14 3 3 #"sum" +0 0 24 3 1 #" " +0 0 14 3 2 #"of" +0 0 24 3 1 #" " +0 0 14 3 3 #"the" +0 0 24 3 1 #" " +0 0 14 3 4 #"fuel" +0 0 24 3 1 #" " +0 0 14 3 12 #"requirements" +0 0 24 3 1 #" " +0 0 15 3 3 #"for" +0 0 24 3 1 #" " +0 0 14 3 3 #"all" +0 0 24 3 1 #" " +0 0 14 3 2 #"of" +0 0 24 3 1 #" " +0 0 14 3 3 #"the" +0 0 24 3 1 #" " +0 0 14 3 7 #"modules" +0 0 24 29 1 #"\n" +0 0 14 3 2 #"on" +0 0 24 3 1 #" " +0 0 14 3 4 #"your" +0 0 24 3 1 #" " +0 0 14 3 10 #"spacecraft" +0 0 24 3 1 #" " +0 0 15 3 4 #"when" +0 0 24 3 1 #" " +0 0 14 3 4 #"also" +0 0 24 3 1 #" " +0 0 14 3 6 #"taking" +0 0 24 3 1 #" " +0 0 14 3 4 #"into" +0 0 24 3 1 #" " +0 0 14 3 7 #"account" +0 0 24 3 1 #" " +0 0 14 3 3 #"the" +0 0 24 3 1 #" " +0 0 14 3 4 #"mass" +0 0 24 3 1 #" " +0 0 14 3 2 #"of" +0 0 24 3 1 #" " +0 0 14 3 3 #"the" +0 0 24 29 1 #"\n" +0 0 14 3 5 #"added" +0 0 24 3 1 #" " +0 0 14 3 5 #"fuel?" +0 0 24 3 1 #" " +0 0 0 0 24 29 1 #"\n" +0 0 24 29 1 #"\n" +0 0 24 3 1 #"(" +0 0 15 3 6 #"define" +0 0 24 3 1 #" " +0 0 14 3 5 #"input" +0 0 24 3 2 #" (" +0 0 14 3 3 #"map" +0 0 24 3 1 #" " +0 0 14 3 14 #"string->number" +0 0 24 3 2 #" (" +0 0 14 3 13 #"problem-input" +0 0 24 3 1 #" " +0 0 21 3 1 #"1" +0 0 24 3 3 #")))" +0 0 24 29 1 #"\n" +0 0 24 29 1 #"\n" +0 0 17 3 31 #";; calc-fuel : number -> number" +0 0 24 29 1 #"\n" +0 0 24 3 1 #"(" +0 0 15 3 6 #"define" +0 0 24 3 2 #" (" +0 0 14 3 9 #"calc-fuel" +0 0 24 3 1 #" " +0 0 14 3 4 #"mass" +0 0 24 3 1 #")" +0 0 24 29 1 #"\n" +0 0 24 3 3 #" (" +0 0 14 3 1 #"-" +0 0 24 3 2 #" (" +0 0 14 3 5 #"floor" +0 0 24 3 2 #" (" +0 0 14 3 1 #"/" +0 0 24 3 1 #" " +0 0 14 3 4 #"mass" +0 0 24 3 1 #" " +0 0 21 3 1 #"3" +0 0 24 3 3 #")) " +0 0 21 3 1 #"2" +0 0 24 3 2 #"))" +0 0 24 29 1 #"\n" +0 0 24 29 1 #"\n" +0 0 24 3 1 #"(" +0 0 15 3 6 #"define" +0 0 24 3 1 #" " +0 0 14 3 5 #"part1" +0 0 24 29 1 #"\n" +0 0 24 3 3 #" (" +0 0 14 3 3 #"sum" +0 0 24 3 2 #" (" +0 0 14 3 3 #"map" +0 0 24 3 1 #" " +0 0 14 3 9 #"calc-fuel" +0 0 24 3 1 #" " +0 0 14 3 5 #"input" +0 0 24 3 3 #")))" +0 0 24 29 1 #"\n" +0 0 24 29 1 #"\n" +0 0 17 3 35 #";; calc-fuel-rec : number -> number" +0 0 24 29 1 #"\n" +0 0 17 3 35 #";; Calculate the fuel given a mass," +0 0 24 29 1 #"\n" +0 0 17 3 44 #";; then add the fuel required for THAT fuel," +0 0 24 29 1 #"\n" +0 0 17 3 54 #";; and so on until the fuel required is 0 or negative," +0 0 24 29 1 #"\n" +0 0 17 3 39 #";; for which the fuel should just be 0." +0 0 24 29 1 #"\n" +0 0 24 3 1 #"(" +0 0 15 3 6 #"define" +0 0 24 3 2 #" (" +0 0 14 3 13 #"calc-fuel-rec" +0 0 24 3 1 #" " +0 0 14 3 4 #"mass" +0 0 24 3 1 #")" +0 0 24 29 1 #"\n" +0 0 24 3 3 #" (" +0 0 15 3 3 #"let" +0 0 24 3 3 #" ([" +0 0 14 3 4 #"fuel" +0 0 24 3 2 #" (" +0 0 14 3 9 #"calc-fuel" +0 0 24 3 1 #" " +0 0 14 3 4 #"mass" +0 0 24 3 3 #")])" +0 0 24 29 1 #"\n" +0 0 24 3 5 #" (" +0 0 14 3 2 #"if" +0 0 24 3 2 #" (" +0 0 14 3 2 #"<=" +0 0 24 3 1 #" " +0 0 14 3 4 #"fuel" +0 0 24 3 1 #" " +0 0 21 3 1 #"0" +0 0 24 3 2 #") " +0 0 21 3 1 #"0" +0 0 24 29 1 #"\n" +0 0 24 3 9 #" (" +0 0 14 3 1 #"+" +0 0 24 3 1 #" " +0 0 14 3 4 #"fuel" +0 0 24 3 2 #" (" +0 0 14 3 13 #"calc-fuel-rec" +0 0 24 3 1 #" " +0 0 14 3 4 #"fuel" +0 0 24 3 5 #")))))" +0 0 24 29 1 #"\n" +0 0 24 29 1 #"\n" +0 0 24 3 1 #"(" +0 0 15 3 6 #"define" +0 0 24 3 1 #" " +0 0 14 3 5 #"part2" +0 0 24 29 1 #"\n" +0 0 24 3 3 #" (" +0 0 14 3 3 #"sum" +0 0 24 3 2 #" (" +0 0 14 3 3 #"map" +0 0 24 3 1 #" " +0 0 14 3 13 #"calc-fuel-rec" +0 0 24 3 1 #" " +0 0 14 3 5 #"input" +0 0 24 3 3 #")))" +0 0 24 29 1 #"\n" +0 0 24 29 1 #"\n" +0 0 24 3 1 #"(" +0 0 14 3 13 #"show-solution" +0 0 24 3 1 #" " +0 0 14 3 5 #"part1" +0 0 24 3 1 #" " +0 0 14 3 5 #"part2" +0 0 24 3 1 #")" +0 0