diff --git a/2019/day01/input1.txt b/2019/day-01/input1.txt similarity index 100% rename from 2019/day01/input1.txt rename to 2019/day-01/input1.txt diff --git a/2019/day01/script1.sh b/2019/day-01/script1.sh similarity index 100% rename from 2019/day01/script1.sh rename to 2019/day-01/script1.sh diff --git a/2019/day01/script2.py b/2019/day-01/script2.py similarity index 100% rename from 2019/day01/script2.py rename to 2019/day-01/script2.py diff --git a/2019/day02/script.py b/2019/day-02/script.py similarity index 100% rename from 2019/day02/script.py rename to 2019/day-02/script.py diff --git a/2019/day03/script1.py b/2019/day-03/script1.py similarity index 100% rename from 2019/day03/script1.py rename to 2019/day-03/script1.py diff --git a/2019/day03/script2.py b/2019/day-03/script2.py similarity index 100% rename from 2019/day03/script2.py rename to 2019/day-03/script2.py diff --git a/2019/day04/script1.py b/2019/day-04/script1.py similarity index 100% rename from 2019/day04/script1.py rename to 2019/day-04/script1.py diff --git a/2020/day-01/README.md b/2020/day-01/README.md new file mode 100644 index 0000000..0e0c0e6 --- /dev/null +++ b/2020/day-01/README.md @@ -0,0 +1,38 @@ +# --- Day 1: Report Repair --- + +After saving Christmas [five years in a row](/events), you've decided to take a vacation at a nice resort on a tropical island. *Surely*, Christmas will go on without you. + +The tropical island has its own currency and is entirely cash-only. The gold coins used there have a little picture of a starfish; the locals just call them *stars*. None of the currency exchanges seem to have heard of them, but somehow, you'll need to find fifty of these coins by the time you arrive so you can pay the deposit on your room. + +To save your vacation, you need to get all *fifty stars* by December 25th. + +Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants *one star*. Good luck! + +Before you leave, the Elves in accounting just need you to fix your *expense report* (your puzzle input); apparently, something isn't quite adding up. + +Specifically, they need you to *find the two entries that sum to `2020`* and then multiply those two numbers together. + +For example, suppose your expense report contained the following: + +``` +1721 +979 +366 +299 +675 +1456 + +``` + +In this list, the two entries that sum to `2020` are `1721` and `299`. Multiplying them together produces `1721 * 299 = 514579`, so the correct answer is `514579`. + +Of course, your expense report is much larger. *Find the two entries that sum to `2020`; what do you get if you multiply them together?* + +## --- Part Two --- + +The Elves in accounting are thankful for your help; one of them even offers you a starfish coin they had left over from a past vacation. They offer you a second one if you can find *three* numbers in your expense report that meet the same criteria. + +Using the above example again, the three entries that sum to `2020` are `979`, `366`, and `675`. Multiplying them together produces the answer, `241861950`. + +In your expense report, *what is the product of the three entries that sum to `2020`?* + diff --git a/2020/day01/input.txt b/2020/day-01/input.txt similarity index 100% rename from 2020/day01/input.txt rename to 2020/day-01/input.txt diff --git a/2020/day01/solver_1.py b/2020/day-01/solver_1.py similarity index 100% rename from 2020/day01/solver_1.py rename to 2020/day-01/solver_1.py diff --git a/2020/day01/solver_2.py b/2020/day-01/solver_2.py similarity index 100% rename from 2020/day01/solver_2.py rename to 2020/day-01/solver_2.py diff --git a/2020/day-02/README.md b/2020/day-02/README.md new file mode 100644 index 0000000..dbcb1f3 --- /dev/null +++ b/2020/day-02/README.md @@ -0,0 +1,44 @@ +# --- Day 2: Password Philosophy --- + +Your flight departs in a few days from the coastal airport; the easiest way down to the coast from here is via [toboggan](https://en.wikipedia.org/wiki/Toboggan). + +The shopkeeper at the North Pole Toboggan Rental Shop is having a bad day. "Something's wrong with our computers; we can't log in!" You ask if you can take a look. + +Their password database seems to be a little corrupted: some of the passwords wouldn't have been allowed by the *Official Toboggan Corporate Policy* that was in effect when they were chosen. + +To try to debug the problem, they have created a list (your puzzle input) of *passwords* (according to the corrupted database) and *the corporate policy when that password was set*. + +For example, suppose you have the following list: + +``` +1-3 a: abcde +1-3 b: cdefg +2-9 c: ccccccccc + +``` + +Each line gives the password policy and then the password. The password policy indicates the lowest and highest number of times a given letter must appear for the password to be valid. For example, `1-3 a` means that the password must contain `a` at least `1` time and at most `3` times. + +In the above example, `2` passwords are valid. The middle password, `cdefg`, is not; it contains no instances of `b`, but needs at least `1`. The first and third passwords are valid: they contain one `a` or nine `c`, both within the limits of their respective policies. + +*How many passwords are valid* according to their policies? + +## --- Part Two --- + +While it appears you validated the passwords correctly, they don't seem to be what the Official Toboggan Corporate Authentication System is expecting. + +The shopkeeper suddenly realizes that he just accidentally explained the password policy rules from his old job at the sled rental place down the street! The Official Toboggan Corporate Policy actually works a little differently. + +Each policy actually describes two *positions in the password*, where `1` means the first character, `2` means the second character, and so on. (Be careful; Toboggan Corporate Policies have no concept of "index zero"!) *Exactly one of these positions* must contain the given letter. Other occurrences of the letter are irrelevant for the purposes of policy enforcement. + +Given the same example list from above: + + + - `1-3 a: abcde` is *valid*: position `1` contains `a` and position `3` does not. + + - `1-3 b: cdefg` is *invalid*: neither position `1` nor position `3` contains `b`. + + - `2-9 c: ccccccccc` is *invalid*: both position `2` and position `9` contain `c`. + + +*How many passwords are valid* according to the new interpretation of the policies? diff --git a/2020/day02/input.txt b/2020/day-02/input.txt similarity index 100% rename from 2020/day02/input.txt rename to 2020/day-02/input.txt diff --git a/2020/day02/solver_1.py b/2020/day-02/solver_1.py similarity index 100% rename from 2020/day02/solver_1.py rename to 2020/day-02/solver_1.py diff --git a/2020/day02/solver_2.py b/2020/day-02/solver_2.py similarity index 100% rename from 2020/day02/solver_2.py rename to 2020/day-02/solver_2.py diff --git a/2020/day01/README.md b/2020/day01/README.md deleted file mode 100644 index e5309c4..0000000 --- a/2020/day01/README.md +++ /dev/null @@ -1,41 +0,0 @@ -# Day 1: Report Repair - -After saving Christmas [five years in a row](https://adventofcode.com/events), you've decided to take a vacation at a nice resort on a tropical island. Surely, Christmas will go on without you. - -The tropical island has its own currency and is entirely cash-only. The gold coins used there have a little picture of a starfish; the locals just call them stars. None of the currency exchanges seem to have heard of them, but somehow, you'll need to find fifty of these coins by the time you arrive so you can pay the deposit on your room. - -To save your vacation, you need to get all fifty stars by December 25th. - -Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck! - -Before you leave, the Elves in accounting just need you to fix your expense report (your puzzle input); apparently, something isn't quite adding up. - -Specifically, they need you to find the two entries that sum to `2020` and then multiply those two numbers together. - -For example, suppose your expense report contained the following: - -``` -1721 -979 -366 -299 -675 -1456 - -``` - -In this list, the two entries that sum to `2020` are `1721` and `299`. Multiplying them together produces `1721 * 299 = 514579`, so the correct answer is `514579`. - -Of course, your expense report is much larger. Find the two entries that sum to `2020`; what do you get if you multiply them together? - -To begin, [get your puzzle input](input.txt). - ---- - -## Part Two - -The Elves in accounting are thankful for your help; one of them even offers you a starfish coin they had left over from a past vacation. They offer you a second one if you can find three numbers in your expense report that meet the same criteria. - -Using the above example again, the three entries that sum to `2020` are `979`, `366`, and `675`. Multiplying them together produces the answer, `241861950`. - -In your expense report, what is the product of the three entries that sum to `2020`? diff --git a/2020/day02/README.md b/2020/day02/README.md deleted file mode 100644 index eacbb26..0000000 --- a/2020/day02/README.md +++ /dev/null @@ -1,45 +0,0 @@ -# Day 2: Password Philosophy - -Your flight departs in a few days from the coastal airport; the easiest way down to the coast from here is via [toboggan](https://en.wikipedia.org/wiki/Toboggan). - -The shopkeeper at the North Pole Toboggan Rental Shop is having a bad day. "Something's wrong with our computers; we can't log in!" You ask if you can take a look. - -Their password database seems to be a little corrupted: some of the passwords wouldn't have been allowed by the Official Toboggan Corporate Policy that was in effect when they were chosen. - -To try to debug the problem, they have created a list (your puzzle input) of passwords (according to the corrupted database) and the corporate policy when that password was set. - -For example, suppose you have the following list: - -``` -1-3 a: abcde -1-3 b: cdefg -2-9 c: ccccccccc - -``` - -Each line gives the password policy and then the password. The password policy indicates the lowest and highest number of times a given letter must appear for the password to be valid. For example, `1-3 a` means that the password must contain `a` at least `1` time and at most `3` times. - -In the above example, `2` passwords are valid. The middle password, `cdefg`, is not; it contains no instances of `b`, but needs at least `1`. The first and third passwords are valid: they contain one `a` or nine `c`, both within the limits of their respective policies. - -How many passwords are valid according to their policies? - -To begin, [get your puzzle input](input.txt). - - ---- - -## Part Two - -While it appears you validated the passwords correctly, they don't seem to be what the Official Toboggan Corporate Authentication System is expecting. - -The shopkeeper suddenly realizes that he just accidentally explained the password policy rules from his old job at the sled rental place down the street! The Official Toboggan Corporate Policy actually works a little differently. - -Each policy actually describes two positions in the password, where `1` means the first character, `2` means the second character, and so on. (Be careful; Toboggan Corporate Policies have no concept of "index zero"!) Exactly one of these positions must contain the given letter. Other occurrences of the letter are irrelevant for the purposes of policy enforcement. - -Given the same example list from above: - -- `1-3 a: abcde` is valid: position `1` contains `a` and position `3` does not. -- `1-3 b: cdefg` is invalid: neither position `1` nor position `3` contains `b`. -- `2-9 c: ccccccccc` is invalid: both position `2` and position `9` contain `c`. - -How many passwords are valid according to the new interpretation of the policies? \ No newline at end of file diff --git a/README.md b/README.md index 8bc1e31..7300872 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,18 @@ # My solutions to https://adventofcode.com/ - [2020](./2020/) -- [2019](./2019/) \ No newline at end of file +- [2019](./2019/) + +## Start a new problem + +You may automatically fetch the data with: +``` +SESSION_ID= ./start_aoc_day.py +``` +and refresh the `README.md`, after completing part 1, with: +``` +SESSION_ID= ./start_aoc_day.py last +``` + +You may use other arguments. For more information type `./start_aoc_day.py -h` +or visit [aoc-to-markdown repository](https://github.com/antonio-ramadas/aoc-to-markdown). \ No newline at end of file diff --git a/start_aoc_day.py b/start_aoc_day.py new file mode 100755 index 0000000..c92d818 --- /dev/null +++ b/start_aoc_day.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 +import os +import re +import sys +from datetime import datetime + +curdir = os.path.dirname(os.path.realpath(__file__)) +sys.path.insert(1, curdir + "/aoc-to-markdown") +import aoc_to_markdown + + +def setup_session_id() -> bool: + if os.getenv("SESSION_ID"): + return True + else: + print("SESSION_ID is needed in order to download the input") + answer = input("Want to input the session cookie value? [N/] ") + + if answer and answer not in "Nn": + os.environ["SESSION_ID"] = answer + return True + + +def setup_program_arguments(last=False): + year = datetime.now().year + output_dir = f"{year}/" + if not os.path.exists(output_dir): + os.makedirs(output_dir) + + sys.argv = [sys.argv[0], "-o", output_dir] + + + if last: + folder_syntax = re.compile("^day-(\\d+)$") + last_day = max( + [ + int(folder_syntax.search(f).group(1)) + for f in os.listdir(output_dir) + if folder_syntax.match(f) + ], + default=1, + ) + sys.argv.append("-d") + sys.argv.append(f"{last_day}") + + elif setup_session_id(): # don't download input again + sys.argv.append("-i") + + +def main(): + + # manually set arguments for aoc_to_markdown + # (until main accepts arguments) + if len(sys.argv) <= 1: + setup_program_arguments() + elif len(sys.argv) == 2 and sys.argv[1] == "last": + setup_program_arguments(last=True) + aoc_to_markdown.main() + + +if __name__ == "__main__": + main()