From 2072614ce4f6c35ef4a1433ea749db3514e2c383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bor=20Gro=C5=A1elj=20Simi=C4=87?= Date: Thu, 3 Dec 2020 03:39:54 +0100 Subject: [PATCH] automate building and running --- .gitignore | 6 +++++- run | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100755 run diff --git a/.gitignore b/.gitignore index 1167d00..bdf8808 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,8 @@ *.cmo *.cmi -a.out +*.out +*.in + +# contains the session cookie needed for input file download +.cookie diff --git a/run b/run new file mode 100755 index 0000000..a807050 --- /dev/null +++ b/run @@ -0,0 +1,62 @@ +#!/bin/sh -eu + +source .cookie + +usage () { + printf "USAGE: ./run [day_number]\n" + printf "If day number is provided, build and run the task for that day.\n" + printf "Run all implemented tasks otherwise\n" +} + + +die () { + printf "error: %s\n" "$1" + usage + exit 1 +} + +day () { + test -f "day_$1.in" || curl "https://adventofcode.com/2020/day/$1/input" \ + -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0' \ + -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' \ + -H 'Accept-Language: en-US,en;q=0.5' \ + --compressed \ + -H 'DNT: 1' \ + -H 'Connection: keep-alive' \ + -H "Cookie: session=${SESSION_COOKIE}" \ + -H 'Upgrade-Insecure-Requests: 1' \ + -H 'Cache-Control: max-age=0' \ + -H 'TE: Trailers' > "day_$1.in" + + ocamlc "day_$1.ml" -o "day_$1" + ./"day_$1" + + printf "Day $1 task 1:\n" + cat "day_$1_1.out" + + printf "Day $1 task 2:\n" + cat "day_$1_2.out" +} + +if [ $# = 0 ] +then + for f in day_*.ml + do + day $(basename "$f" .ml | cut -d _ -f 2) + printf "\n" + done + exit 0 +fi + +case "$1" in + *[[:digit:]]) + test -f "day_$1.ml" || die "No program source for day $1" + day $1 + ;; + -u|-h|--usage|--help) + usage + ;; + *) + die "$1 is not a day number" + ;; +esac -- 2.45.2