From d872061ff393da411f77d3fa933b71b581bd2687 Mon Sep 17 00:00:00 2001 From: haskal Date: Sun, 1 Dec 2019 02:15:53 -0500 Subject: [PATCH] Day 1 --- .gitignore | 4 ++++ 1.rkt | 17 +++++++++++++++++ get-input | 4 ++++ 3 files changed, 25 insertions(+) create mode 100644 .gitignore create mode 100644 1.rkt create mode 100755 get-input diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7145f99 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.session +*.rkt~ +input.*.txt +.envrc diff --git a/1.rkt b/1.rkt new file mode 100644 index 0000000..ca2e0d5 --- /dev/null +++ b/1.rkt @@ -0,0 +1,17 @@ +#lang racket + +(define input (file->list "input.1.txt")) + +(define (mass->fuel mass) + (- (floor (/ mass 3)) 2)) + +; part 1 +(displayln (foldr + 0 (map mass->fuel input))) + +(define (mass->fuel* mass) + (let ([fuel (mass->fuel mass)]) + (cond [(<= fuel 0) 0] + [else (+ fuel (mass->fuel* fuel))]))) + +; part 2 +(displayln (foldr + 0 (map mass->fuel* input))) diff --git a/get-input b/get-input new file mode 100755 index 0000000..f8794bd --- /dev/null +++ b/get-input @@ -0,0 +1,4 @@ +#!/bin/bash + +session=$(cat .session) +curl -SsH "Cookie: session=$session" https://adventofcode.com/2019/day/$1/input > input.$1.txt