├── 2015 ├── README.md ├── cpp │ ├── day_01a.cpp │ ├── day_01b.cpp │ ├── day_02a.cpp │ ├── day_02b.cpp │ ├── day_03a.cpp │ ├── day_03b.cpp │ ├── day_04a.cpp │ ├── day_04b.cpp │ ├── day_05a.cpp │ ├── day_05b.cpp │ ├── day_06a.cpp │ ├── day_06b.cpp │ ├── day_07a.cpp │ ├── day_07b.cpp │ ├── day_08a.cpp │ ├── day_08b.cpp │ ├── day_09a.cpp │ ├── day_09b.cpp │ ├── day_10a.cpp │ ├── day_10b.cpp │ ├── day_11a.cpp │ ├── day_11b.cpp │ ├── day_12a.cpp │ ├── day_12b.cpp │ ├── day_13a.cpp │ ├── day_13b.cpp │ ├── day_14a.cpp │ ├── day_14b.cpp │ ├── day_15a.cpp │ ├── day_15b.cpp │ ├── day_16a.cpp │ ├── day_16b.cpp │ ├── day_17a.cpp │ ├── day_17b.cpp │ ├── day_18a.cpp │ ├── day_18b.cpp │ ├── day_19a.cpp │ ├── day_19b.cpp │ ├── day_20a.cpp │ ├── day_20b.cpp │ ├── day_21a.cpp │ ├── day_21b.cpp │ ├── day_22a.cpp │ ├── day_22b.cpp │ ├── day_23a.cpp │ ├── day_23b.cpp │ ├── day_24a.cpp │ ├── day_24b.cpp │ └── day_25a.cpp └── sample_input │ ├── day_01_sample_input │ ├── day_02_sample_input │ ├── day_03_sample_input │ ├── day_04_sample_input │ ├── day_05_sample_input │ ├── day_06_sample_input │ ├── day_07_sample_input │ ├── day_08_sample_input │ ├── day_09_sample_input │ ├── day_10_sample_input │ ├── day_11_sample_input │ ├── day_12_sample_input │ ├── day_13_sample_input │ ├── day_14_sample_input │ ├── day_15_sample_input │ ├── day_16_sample_input │ ├── day_17_sample_input │ ├── day_18_sample_input │ ├── day_19_sample_input │ ├── day_20_sample_input │ ├── day_21_sample_input │ ├── day_22_sample_input │ ├── day_23_sample_input │ ├── day_24_sample_input │ └── day_25_sample_input ├── 2016 ├── README.md ├── cpp │ ├── day_01a.cpp │ ├── day_01b.cpp │ ├── day_02a.cpp │ ├── day_02b.cpp │ ├── day_03a.cpp │ ├── day_03b.cpp │ ├── day_04a.cpp │ ├── day_04b.cpp │ ├── day_05a.cpp │ ├── day_05b.cpp │ ├── day_06a.cpp │ ├── day_06b.cpp │ ├── day_07a.cpp │ ├── day_07b.cpp │ ├── day_08a.cpp │ ├── day_08b.cpp │ ├── day_09a.cpp │ ├── day_09b.cpp │ ├── day_10a.cpp │ ├── day_10b.cpp │ ├── day_11a.cpp │ ├── day_11b.cpp │ ├── day_12a.cpp │ ├── day_12b.cpp │ ├── day_13a.cpp │ ├── day_13b.cpp │ ├── day_14a.cpp │ ├── day_14b.cpp │ ├── day_15a.cpp │ ├── day_15b.cpp │ ├── day_16a.cpp │ ├── day_16b.cpp │ ├── day_17a.cpp │ ├── day_17b.cpp │ ├── day_18a.cpp │ ├── day_18b.cpp │ ├── day_19a.cpp │ ├── day_19b.cpp │ ├── day_20a.cpp │ ├── day_20b.cpp │ ├── day_21a.cpp │ ├── day_21b.cpp │ ├── day_22a.cpp │ ├── day_22b.cpp │ ├── day_23a.cpp │ ├── day_23b.cpp │ ├── day_24a.cpp │ ├── day_24b.cpp │ └── day_25a.cpp └── sample_input │ ├── day_01_sample_input │ ├── day_02_sample_input │ ├── day_03_sample_input │ ├── day_04_sample_input │ ├── day_05_sample_input │ ├── day_06_sample_input │ ├── day_07_sample_input │ ├── day_08_sample_input │ ├── day_09_sample_input │ ├── day_10_sample_input │ ├── day_11_sample_input │ ├── day_12_sample_input │ ├── day_13_sample_input │ ├── day_14_sample_input │ ├── day_15_sample_input │ ├── day_16_sample_input │ ├── day_17_sample_input │ ├── day_18_sample_input │ ├── day_19_sample_input │ ├── day_20_sample_input │ ├── day_21_sample_input │ ├── day_22_sample_input │ ├── day_23_sample_input │ ├── day_24_sample_input │ └── day_25_sample_input ├── 2017 ├── README.md ├── cpp │ ├── day_01a.cpp │ ├── day_01b.cpp │ ├── day_02a.cpp │ ├── day_02b.cpp │ ├── day_03a.cpp │ ├── day_03b.cpp │ ├── day_04a.cpp │ ├── day_04b.cpp │ ├── day_05a.cpp │ ├── day_05b.cpp │ ├── day_06a.cpp │ ├── day_06b.cpp │ ├── day_07a.cpp │ ├── day_07b.cpp │ ├── day_08a.cpp │ ├── day_08b.cpp │ ├── day_09a.cpp │ ├── day_09b.cpp │ ├── day_10a.cpp │ ├── day_10b.cpp │ ├── day_11a.cpp │ ├── day_11b.cpp │ ├── day_12a.cpp │ ├── day_12b.cpp │ ├── day_13a.cpp │ ├── day_13b.cpp │ ├── day_14a.cpp │ ├── day_14b.cpp │ ├── day_15a.cpp │ ├── day_15b.cpp │ ├── day_16a.cpp │ ├── day_16b.cpp │ ├── day_17a.cpp │ ├── day_17b.cpp │ ├── day_18a.cpp │ ├── day_18b.cpp │ ├── day_19a.cpp │ ├── day_19b.cpp │ ├── day_20a.cpp │ ├── day_20b.cpp │ ├── day_21a.cpp │ ├── day_21b.cpp │ ├── day_22a.cpp │ ├── day_22b.cpp │ ├── day_23a.cpp │ ├── day_23b.cpp │ ├── day_24a.cpp │ ├── day_24b.cpp │ └── day_25a.cpp └── sample_input │ ├── day_01_sample_input │ ├── day_02_sample_input │ ├── day_03_sample_input │ ├── day_04_sample_input │ ├── day_05_sample_input │ ├── day_06_sample_input │ ├── day_07_sample_input │ ├── day_08_sample_input │ ├── day_09_sample_input │ ├── day_10_sample_input │ ├── day_11_sample_input │ ├── day_12_sample_input │ ├── day_13_sample_input │ ├── day_14_sample_input │ ├── day_15_sample_input │ ├── day_16_sample_input │ ├── day_17_sample_input │ ├── day_18_sample_input │ ├── day_19_sample_input │ ├── day_20_sample_input │ ├── day_21_sample_input │ ├── day_22_sample_input │ ├── day_23_sample_input │ ├── day_24_sample_input │ └── day_25_sample_input ├── 2018 ├── README.md ├── cpp │ ├── day_01a.cpp │ ├── day_01b.cpp │ ├── day_02a.cpp │ ├── day_02b.cpp │ ├── day_03a.cpp │ ├── day_03b.cpp │ ├── day_04a.cpp │ ├── day_04b.cpp │ ├── day_05a.cpp │ ├── day_05b.cpp │ ├── day_06a.cpp │ ├── day_06b.cpp │ ├── day_07a.cpp │ ├── day_07b.cpp │ ├── day_08a.cpp │ ├── day_08b.cpp │ ├── day_09a.cpp │ ├── day_09b.cpp │ ├── day_10a.cpp │ ├── day_10b.cpp │ ├── day_11a.cpp │ ├── day_11b.cpp │ ├── day_12a.cpp │ ├── day_12b.cpp │ ├── day_13a.cpp │ ├── day_13b.cpp │ ├── day_14a.cpp │ ├── day_14b.cpp │ ├── day_15a.cpp │ ├── day_15b.cpp │ ├── day_16a.cpp │ ├── day_16b.cpp │ ├── day_17a.cpp │ ├── day_17b.cpp │ ├── day_18a.cpp │ ├── day_18b.cpp │ ├── day_19a.cpp │ ├── day_19b.cpp │ ├── day_20a.cpp │ ├── day_20b.cpp │ ├── day_21a.cpp │ ├── day_21b.cpp │ ├── day_22a.cpp │ ├── day_22b.cpp │ ├── day_23a.cpp │ ├── day_23b.cpp │ ├── day_24a.cpp │ ├── day_24b.cpp │ └── day_25a.cpp └── sample_input │ ├── day_01_sample_input │ ├── day_02_sample_input │ ├── day_03_sample_input │ ├── day_04_sample_input │ ├── day_05_sample_input │ ├── day_06_sample_input │ ├── day_07_sample_input │ ├── day_08_sample_input │ ├── day_09_sample_input │ ├── day_10_sample_input │ ├── day_11_sample_input │ ├── day_12_sample_input │ ├── day_13_sample_input │ ├── day_14_sample_input │ ├── day_15_sample_input │ ├── day_16_sample_input │ ├── day_17_sample_input │ ├── day_18_sample_input │ ├── day_19_sample_input │ ├── day_20_sample_input │ ├── day_21_sample_input │ ├── day_22_sample_input │ ├── day_23_sample_input │ ├── day_24_sample_input │ └── day_25_sample_input ├── 2019 ├── README.md ├── cpp │ ├── day_01a.cpp │ ├── day_01b.cpp │ ├── day_02a.cpp │ ├── day_02b.cpp │ ├── day_03a.cpp │ ├── day_03b.cpp │ ├── day_04a.cpp │ ├── day_04b.cpp │ ├── day_05a.cpp │ ├── day_05b.cpp │ ├── day_06a.cpp │ ├── day_06b.cpp │ ├── day_07a.cpp │ ├── day_07b.cpp │ ├── day_08a.cpp │ ├── day_08b.cpp │ ├── day_09a.cpp │ ├── day_09b.cpp │ ├── day_10a.cpp │ ├── day_10b.cpp │ ├── day_11a.cpp │ ├── day_11b.cpp │ ├── day_12a.cpp │ ├── day_12b.cpp │ ├── day_13a.cpp │ ├── day_13b.cpp │ ├── day_14a.cpp │ ├── day_14b.cpp │ ├── day_15a.cpp │ ├── day_15b.cpp │ ├── day_16a.cpp │ ├── day_16b.cpp │ ├── day_17a.cpp │ ├── day_17b.cpp │ ├── day_18a.cpp │ ├── day_18b.cpp │ ├── day_19a.cpp │ ├── day_19b.cpp │ ├── day_20a.cpp │ ├── day_20b.cpp │ ├── day_21a.cpp │ ├── day_21b.cpp │ ├── day_22a.cpp │ ├── day_22b.cpp │ ├── day_23a.cpp │ ├── day_23b.cpp │ ├── day_24a.cpp │ ├── day_24b.cpp │ └── day_25a.cpp ├── python │ ├── day_01a.py │ ├── day_01b.py │ ├── day_02a.py │ ├── day_02b.py │ ├── day_03a.py │ ├── day_03b.py │ ├── day_04a.py │ ├── day_04b.py │ ├── day_05a.py │ ├── day_05b.py │ ├── day_06a.py │ ├── day_06b.py │ ├── day_07a.py │ └── day_07b.py └── sample_input │ ├── day_01_sample_input │ ├── day_02_sample_input │ ├── day_03_sample_input │ ├── day_04_sample_input │ ├── day_05_sample_input │ ├── day_06_sample_input │ ├── day_07_sample_input │ ├── day_08_sample_input │ ├── day_09_sample_input │ ├── day_10_sample_input │ ├── day_11_sample_input │ ├── day_12_sample_input │ ├── day_13_sample_input │ ├── day_14_sample_input │ ├── day_15_sample_input │ ├── day_16_sample_input │ ├── day_17_sample_input │ ├── day_18_sample_input │ ├── day_19_sample_input │ ├── day_20_sample_input │ ├── day_21_sample_input │ ├── day_22_sample_input │ ├── day_23_sample_input │ ├── day_24_sample_input │ └── day_25_sample_input ├── 2020 ├── README.md ├── cpp │ ├── day_01a.cpp │ ├── day_01b.cpp │ ├── day_02a.cpp │ ├── day_02b.cpp │ ├── day_03a.cpp │ ├── day_03b.cpp │ ├── day_04a.cpp │ ├── day_04b.cpp │ ├── day_05a.cpp │ ├── day_05b.cpp │ ├── day_06a.cpp │ ├── day_06b.cpp │ ├── day_07a.cpp │ ├── day_07b.cpp │ ├── day_08a.cpp │ ├── day_08b.cpp │ ├── day_09a.cpp │ ├── day_09b.cpp │ ├── day_10a.cpp │ ├── day_10b.cpp │ ├── day_11a.cpp │ ├── day_11b.cpp │ ├── day_12a.cpp │ ├── day_12b.cpp │ ├── day_13a.cpp │ ├── day_13b.cpp │ ├── day_14a.cpp │ ├── day_14b.cpp │ ├── day_15a.cpp │ ├── day_15b.cpp │ ├── day_16a.cpp │ ├── day_16b.cpp │ ├── day_17a.cpp │ ├── day_17b.cpp │ ├── day_18a.cpp │ ├── day_18b.cpp │ ├── day_19a.cpp │ ├── day_19b.cpp │ ├── day_20a.cpp │ ├── day_20b.cpp │ ├── day_21a.cpp │ ├── day_21b.cpp │ ├── day_22a.cpp │ ├── day_22b.cpp │ ├── day_23a.cpp │ ├── day_23b.cpp │ ├── day_24a.cpp │ ├── day_24b.cpp │ └── day_25.cpp ├── python │ ├── day_01a.py │ ├── day_01b.py │ ├── day_02a.py │ ├── day_02b.py │ ├── day_03a.py │ ├── day_03b.py │ ├── day_04a.py │ ├── day_04b.py │ ├── day_05a.py │ ├── day_05b.py │ ├── day_06a.py │ ├── day_06b.py │ ├── day_07a.py │ ├── day_07b.py │ ├── day_08a.py │ ├── day_08b.py │ ├── day_09a.py │ ├── day_09b.py │ ├── day_10a.py │ ├── day_10b.py │ ├── day_11a.py │ ├── day_11b.py │ ├── day_12a.py │ ├── day_12b.py │ ├── day_13a.py │ ├── day_13b.py │ ├── day_14a.py │ ├── day_14b.py │ ├── day_15a.py │ ├── day_15b.py │ ├── day_16a.py │ ├── day_16b.py │ ├── day_17a.py │ ├── day_17b.py │ ├── day_18a.py │ ├── day_18b.py │ ├── day_19a.py │ ├── day_19b.py │ ├── day_20a.py │ ├── day_20b.py │ ├── day_21a.py │ ├── day_21b.py │ ├── day_22a.py │ ├── day_22b.py │ ├── day_23a.py │ ├── day_23b.py │ ├── day_24a.py │ ├── day_24b.py │ └── day_25.py └── sample_input │ ├── day_01_sample_input │ ├── day_02_sample_input │ ├── day_03_sample_input │ ├── day_04_sample_input │ ├── day_05_sample_input │ ├── day_06_sample_input │ ├── day_07_sample_input │ ├── day_08_sample_input │ ├── day_09_sample_input │ ├── day_10_sample_input │ ├── day_11_sample_input │ ├── day_12_sample_input │ ├── day_13_sample_input │ ├── day_14_sample_input │ ├── day_15_sample_input │ ├── day_16_sample_input │ ├── day_17_sample_input │ ├── day_18_sample_input │ ├── day_19_sample_input │ ├── day_20_sample_input │ ├── day_21_sample_input │ ├── day_22_sample_input │ ├── day_23_sample_input │ ├── day_24_sample_input │ └── day_25_sample_input ├── 2021 ├── README.md ├── cpp │ ├── day_01a.cpp │ ├── day_01b.cpp │ ├── day_02a.cpp │ ├── day_02b.cpp │ ├── day_03a.cpp │ ├── day_03b.cpp │ ├── day_04a.cpp │ ├── day_04b.cpp │ ├── day_05a.cpp │ ├── day_05b.cpp │ ├── day_06a.cpp │ ├── day_06b.cpp │ ├── day_07a.cpp │ ├── day_07b.cpp │ ├── day_08a.cpp │ ├── day_08b.cpp │ ├── day_09a.cpp │ ├── day_09b.cpp │ ├── day_10a.cpp │ ├── day_10b.cpp │ ├── day_11a.cpp │ ├── day_11b.cpp │ ├── day_12a.cpp │ ├── day_12b.cpp │ ├── day_13a.cpp │ ├── day_13b.cpp │ ├── day_14a.cpp │ ├── day_14b.cpp │ ├── day_15a.cpp │ ├── day_15b.cpp │ ├── day_16a.cpp │ ├── day_16b.cpp │ ├── day_17a.cpp │ ├── day_17b.cpp │ ├── day_18a.cpp │ ├── day_18b.cpp │ ├── day_19a.cpp │ ├── day_19b.cpp │ ├── day_20a.cpp │ ├── day_20b.cpp │ ├── day_21a.cpp │ ├── day_21b.cpp │ ├── day_22a.cpp │ ├── day_22b.cpp │ ├── day_23a.cpp │ ├── day_23b.cpp │ ├── day_24a.cpp │ ├── day_24b.cpp │ └── day_25a.cpp └── sample_input │ ├── day_01_sample_input │ ├── day_02_sample_input │ ├── day_03_sample_input │ ├── day_04_sample_input │ ├── day_05_sample_input │ ├── day_06_sample_input │ ├── day_07_sample_input │ ├── day_08_sample_input │ ├── day_09_sample_input │ ├── day_10_sample_input │ ├── day_11_sample_input │ ├── day_12_sample_input │ ├── day_13_sample_input │ ├── day_14_sample_input │ ├── day_15_sample_input │ ├── day_16_sample_input │ ├── day_17_sample_input │ ├── day_18_sample_input │ ├── day_19_sample_input │ ├── day_20_sample_input │ ├── day_21_sample_input │ ├── day_22_sample_input │ ├── day_23_sample_input │ ├── day_24_sample_input │ └── day_25_sample_input ├── 2022 ├── README.md ├── cpp │ ├── day_01a.cpp │ ├── day_01b.cpp │ ├── day_02a.cpp │ ├── day_02b.cpp │ ├── day_03a.cpp │ ├── day_03b.cpp │ ├── day_04a.cpp │ ├── day_04b.cpp │ ├── day_05a.cpp │ ├── day_05b.cpp │ ├── day_06a.cpp │ ├── day_06b.cpp │ ├── day_07a.cpp │ ├── day_07b.cpp │ ├── day_08a.cpp │ ├── day_08b.cpp │ ├── day_09a.cpp │ ├── day_09b.cpp │ ├── day_10a.cpp │ ├── day_10b.cpp │ ├── day_11a.cpp │ ├── day_11b.cpp │ ├── day_12a.cpp │ ├── day_12b.cpp │ ├── day_13a.cpp │ ├── day_13b.cpp │ ├── day_14a.cpp │ ├── day_14b.cpp │ ├── day_15a.cpp │ ├── day_15b.cpp │ ├── day_16a.cpp │ ├── day_16b.cpp │ ├── day_17a.cpp │ ├── day_17b.cpp │ ├── day_18a.cpp │ ├── day_18b.cpp │ ├── day_19a.cpp │ ├── day_19b.cpp │ ├── day_20a.cpp │ ├── day_20b.cpp │ ├── day_21a.cpp │ ├── day_21b.cpp │ ├── day_22a.cpp │ ├── day_22b.cpp │ ├── day_23a.cpp │ ├── day_23b.cpp │ ├── day_24a.cpp │ ├── day_24b.cpp │ └── day_25a.cpp └── sample_input │ ├── day_01_sample_input │ ├── day_02_sample_input │ ├── day_03_sample_input │ ├── day_04_sample_input │ ├── day_05_sample_input │ ├── day_06_sample_input │ ├── day_07_sample_input │ ├── day_08_sample_input │ ├── day_09_sample_input │ ├── day_10_sample_input │ ├── day_11_sample_input │ ├── day_12_sample_input │ ├── day_13_sample_input │ ├── day_14_sample_input │ ├── day_15_sample_input │ ├── day_16_sample_input │ ├── day_17_sample_input │ ├── day_18_sample_input │ ├── day_19_sample_input │ ├── day_20_sample_input │ ├── day_21_sample_input │ ├── day_22_sample_input │ ├── day_23_sample_input │ ├── day_24_sample_input │ └── day_25_sample_input ├── 2023 ├── README.md ├── cpp │ ├── day_01a.cpp │ ├── day_01b.cpp │ ├── day_02a.cpp │ ├── day_02b.cpp │ ├── day_03a.cpp │ ├── day_03b.cpp │ ├── day_04a.cpp │ ├── day_04b.cpp │ ├── day_05a.cpp │ ├── day_05b.cpp │ ├── day_06a.cpp │ ├── day_06b.cpp │ ├── day_07a.cpp │ ├── day_07b.cpp │ ├── day_08a.cpp │ ├── day_08b.cpp │ ├── day_09a.cpp │ ├── day_09b.cpp │ ├── day_10a.cpp │ ├── day_10b.cpp │ ├── day_11a.cpp │ ├── day_11b.cpp │ ├── day_12a.cpp │ ├── day_12b.cpp │ ├── day_13a.cpp │ ├── day_13b.cpp │ ├── day_14a.cpp │ ├── day_14b.cpp │ ├── day_15a.cpp │ ├── day_15b.cpp │ ├── day_16a.cpp │ ├── day_16b.cpp │ ├── day_17a.cpp │ ├── day_17b.cpp │ ├── day_18a.cpp │ ├── day_18b.cpp │ ├── day_19a.cpp │ ├── day_19b.cpp │ ├── day_20a.cpp │ ├── day_20b.cpp │ ├── day_21a.cpp │ ├── day_21b.cpp │ ├── day_22a.cpp │ ├── day_22b.cpp │ ├── day_23a.cpp │ ├── day_23b.cpp │ ├── day_24a.cpp │ ├── day_24b.cpp │ └── day_25a.cpp └── sample_input │ ├── day_01_sample_input │ ├── day_02_sample_input │ ├── day_03_sample_input │ ├── day_04_sample_input │ ├── day_05_sample_input │ ├── day_06_sample_input │ ├── day_07_sample_input │ ├── day_08_sample_input │ ├── day_09_sample_input │ ├── day_10_sample_input │ ├── day_11_sample_input │ ├── day_12_sample_input │ ├── day_13_sample_input │ ├── day_14_sample_input │ ├── day_15_sample_input │ ├── day_16_sample_input │ ├── day_17_sample_input │ ├── day_18_sample_input │ ├── day_19_sample_input │ ├── day_20_sample_input │ ├── day_21_sample_input │ ├── day_22_sample_input │ ├── day_23_sample_input │ ├── day_24_sample_input │ └── day_25_sample_input ├── 2024 ├── README.md ├── cpp │ ├── day_01a.cpp │ ├── day_01b.cpp │ ├── day_02a.cpp │ ├── day_02b.cpp │ ├── day_03a.cpp │ ├── day_03b.cpp │ ├── day_04a.cpp │ ├── day_04b.cpp │ ├── day_05a.cpp │ ├── day_05b.cpp │ ├── day_06a.cpp │ ├── day_06b.cpp │ ├── day_07a.cpp │ ├── day_07b.cpp │ ├── day_08a.cpp │ ├── day_08b.cpp │ ├── day_09a.cpp │ ├── day_09b.cpp │ ├── day_10a.cpp │ ├── day_10b.cpp │ ├── day_11a.cpp │ ├── day_11b.cpp │ ├── day_12a.cpp │ ├── day_12b.cpp │ ├── day_13a.cpp │ ├── day_13b.cpp │ ├── day_14a.cpp │ ├── day_14b.cpp │ ├── day_15a.cpp │ ├── day_15b.cpp │ ├── day_16a.cpp │ ├── day_16b.cpp │ ├── day_17a.cpp │ ├── day_17b.cpp │ ├── day_18a.cpp │ ├── day_18b.cpp │ ├── day_19a.cpp │ ├── day_19b.cpp │ ├── day_20a.cpp │ ├── day_20b.cpp │ ├── day_21a.cpp │ ├── day_21b.cpp │ ├── day_22a.cpp │ ├── day_22b.cpp │ ├── day_23a.cpp │ ├── day_23b.cpp │ ├── day_24a.cpp │ ├── day_24b.cpp │ └── day_25a.cpp └── sample_input │ ├── day_01_sample_input │ ├── day_02_sample_input │ ├── day_03_sample_input │ ├── day_04_sample_input │ ├── day_05_sample_input │ ├── day_06_sample_input │ ├── day_07_sample_input │ ├── day_08_sample_input │ ├── day_09_sample_input │ ├── day_10_sample_input │ ├── day_11_sample_input │ ├── day_12_sample_input │ ├── day_13_sample_input │ ├── day_14_sample_input │ ├── day_15_sample_input │ ├── day_16_sample_input │ ├── day_17_sample_input │ ├── day_18_sample_input │ ├── day_19_sample_input │ ├── day_20_sample_input │ ├── day_21_sample_input │ ├── day_22_sample_input │ ├── day_23_sample_input │ ├── day_24_sample_input │ └── day_25_sample_input ├── .github ├── CONTRIBUTING └── ISSUE_TEMPLATE │ ├── algorithm_suggestion.md │ └── bug_report.md ├── .gitignore └── README.md /.github/CONTRIBUTING: -------------------------------------------------------------------------------- 1 | ## Contributing Guidelines ## 2 | 3 | #### Overview #### 4 | 5 | This repository contains solutions to the Advent Of Code puzzles. Bug reports, improvements, refactoring suggestions and suggestions for different/better algorithms and approaches are welcome and highly encouraged. 6 | 7 | However, one of the reasons this repository (and for solving the Advent of Code puzzles) has been created is to learn about different algorithms as well as their potential implementations. As such, suggestions for better algorithms/ideas will be reviewed and might be implemented; contributions to this repository will not be accepted. 8 | 9 | Additionally, as this repository aims to improve the reader's/user's understanding of an algorithm as well, a balance between optimization and readability has to be maintained. 10 | 11 | #### Opening an Issue #### 12 | 13 | Please fill in the appropriate issue template to help communicate the bug/algorithm request. -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/algorithm_suggestion.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Algorithm suggestion 3 | about: Suggest a different algorithm for a particular puzzle 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Description of the algorithm/optimization** 11 | 12 | When the suggestion in an algorithm, please proide: 13 | * a clear and concise description of the algorithm/suggestion 14 | * if the suggestion is a known algorithm, please provide the name of the algorithm 15 | * if possible, links explaining the theory behind the algorithm 16 | 17 | When the suggestion in an optimization, please provide: 18 | * the logic behind the change 19 | * explain why it is an optimization. 20 | * if possible, provide the psseudocode for the change 21 | * bear in mind that there are times when the code is not optimized in favour of readability or making it easier to understand 22 | 23 | **Additional context** 24 | 25 | Add any other context or screenshots about the algorithm/optimization here. 26 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | 12 | A clear and concise description of what the bug is. If possible, please provide a minimal example of an input where the code does not work correctly. 13 | 14 | > [!CAUTION] 15 | > Please do not provide the of your puzzle input. 16 | > References: 17 | > * [Advent of Code wiki](https://www.reddit.com/r/adventofcode/wiki/faqs/copyright/inputs/) 18 | > * [Message](https://www.reddit.com/r/adventofcode/comments/7lesj5/comment/drlt9am/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button) from [u/topaz2078](https://www.reddit.com/user/topaz2078/), the creator of Advent of Code. 19 | 20 | **Expected behavior** 21 | 22 | A clear and concise description of what you expected to happen. 23 | 24 | **Additional context** 25 | 26 | Add any other context about the bug here. 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.out 2 | temp* 3 | *.pyc 4 | *.sh 5 | *answers* 6 | Advent of code* 7 | backup* 8 | out* 9 | TODO* -------------------------------------------------------------------------------- /2015/cpp/day_01a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char* argv[]) { 6 | std::string input = "../input/day_01_input"; 7 | if (argc > 1) { 8 | input = argv[1]; 9 | } 10 | 11 | std::string line; 12 | std::ifstream file(input); 13 | while (std::getline(file, line)) { // to allow for sample input 14 | int floor = 0; 15 | for (const auto ele : line) { 16 | if (ele == '(') { 17 | floor++; 18 | } else if(ele == ')') { 19 | floor--; 20 | } 21 | } 22 | std::cout << floor << '\n'; 23 | } 24 | return 0; 25 | } -------------------------------------------------------------------------------- /2015/cpp/day_01b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char* argv[]) { 6 | std::string input = "../input/day_01_input"; 7 | if (argc > 1) { 8 | input = argv[1]; 9 | } 10 | 11 | std::string line; 12 | std::ifstream file(input); 13 | while (std::getline(file, line)) { // to allow for sample input 14 | int floor = 0; 15 | for (int i = 0; i < line.size(); i++) { 16 | if (line[i] == '(') { 17 | floor++; 18 | } else if(line[i] == ')') { 19 | floor--; 20 | } 21 | if (floor == -1) { 22 | std::cout << i + 1 << '\n'; // index starts at 1 23 | return 0; 24 | } 25 | } 26 | } 27 | return 0; 28 | } -------------------------------------------------------------------------------- /2015/cpp/day_02a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char * argv[]) { 7 | std::string input = "../input/day_02_input"; 8 | if (argc > 1) { 9 | input = argv[1]; 10 | } 11 | std::ifstream file(input); 12 | std::string line; 13 | const std::regex pattern(R"(([0-9]+)x([0-9]+)x([0-9]+))"); 14 | int total = 0; 15 | while(std::getline(file, line)) { 16 | std::smatch match; 17 | std::regex_search(line, match, pattern); 18 | // Sample input 19 | const auto area_1 = (std::stoi(match[1]) * std::stoi(match[2])); 20 | const auto area_2 = (std::stoi(match[2]) * std::stoi(match[3])); 21 | const auto area_3 = (std::stoi(match[3]) * std::stoi(match[1])); 22 | const auto slack = std::min(std::min(area_1, area_2), area_3); 23 | total += (area_1 + area_2 + area_3) * 2 + slack; 24 | } 25 | std::cout << total << '\n'; 26 | return 0; 27 | } -------------------------------------------------------------------------------- /2015/cpp/day_02b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char * argv[]) { 7 | std::string input = "../input/day_02_input"; 8 | if (argc > 1) { 9 | input = argv[1]; 10 | } 11 | std::ifstream file(input); 12 | std::string line; 13 | const std::regex pattern(R"(([0-9]+)x([0-9]+)x([0-9]+))"); 14 | int total = 0; 15 | while(std::getline(file, line)) { 16 | std::smatch match; 17 | std::regex_search(line, match, pattern); 18 | // Sample input 19 | const auto perimeter_1 = (std::stoi(match[1]) + std::stoi(match[2])) * 2; 20 | const auto perimeter_2 = (std::stoi(match[2]) + std::stoi(match[3])) * 2; 21 | const auto perimeter_3 = (std::stoi(match[3]) + std::stoi(match[1])) * 2; 22 | const auto smallest_perimeter = std::min(std::min(perimeter_1, perimeter_2), perimeter_3); 23 | total += smallest_perimeter + (std::stoi(match[1]) * std::stoi(match[2]) * std::stoi(match[3])); 24 | } 25 | std::cout << total << '\n'; 26 | return 0; 27 | } -------------------------------------------------------------------------------- /2015/cpp/day_05a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | bool is_vowel (const char c) { 7 | return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'; 8 | } 9 | 10 | bool is_forbidden(const char c1, const char c2) { 11 | if (c1 == 'a' && c2 == 'b') return true; 12 | if (c1 == 'c' && c2 == 'd') return true; 13 | if (c1 == 'p' && c2 == 'q') return true; 14 | if (c1 == 'x' && c2 == 'y') return true; 15 | return false; 16 | } 17 | 18 | int main(int argc, char* argv[]) { 19 | std::string input = "../input/day_05_input"; 20 | if (argc > 1) { 21 | input = argv[1]; 22 | } 23 | 24 | std::ifstream file(input); 25 | std::string line; 26 | int nice_count = 0; 27 | while(std::getline(file, line)) { 28 | int vowel_count = 0; 29 | bool contains_repeated = false; 30 | bool contains_forbidden = false; 31 | for (int i = 0; i < line.size() - 1; i++) { 32 | if (is_vowel(line[i])) { 33 | vowel_count++; 34 | } 35 | if (line[i] == line[i+1]) { 36 | contains_repeated = true; 37 | } 38 | if (is_forbidden(line[i], line[i+1])) { 39 | contains_forbidden = true; 40 | break; 41 | } 42 | } 43 | if (is_vowel(line[line.size() - 1])) vowel_count++; 44 | if (vowel_count>=3 &&contains_repeated && !contains_forbidden) { 45 | nice_count++; 46 | } 47 | } 48 | std::cout << nice_count << '\n'; 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /2015/cpp/day_08a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // Make sure that the line ending are accurate (let to LF instead of CRLF) 6 | 7 | int parse_line_and_get_delta(const std::string& line) { 8 | std::string just_chars = ""; 9 | for (int i = 1; i < line.size()-1; i++) { 10 | if (line[i] != '\\') { 11 | just_chars += line[i]; 12 | } 13 | else if (line[i+1] == 'x') { 14 | std::string hex_value = line.substr(i + 2, 2); 15 | int num = std::stoi(hex_value, 0, 16); 16 | char c = char(num); 17 | just_chars += (c); 18 | i+=3; 19 | } else { 20 | just_chars += line[i+1]; 21 | i++; 22 | } 23 | } 24 | // std::cout << line << '\n'; 25 | // std::cout << just_chars << '\n'; 26 | return line.size() - just_chars.size(); 27 | } 28 | 29 | int main(int argc, char* argv[]) { 30 | std::string input = "../input/day_08_input"; 31 | if (argc > 1) { 32 | input = argv[1]; 33 | } 34 | 35 | std::ifstream file(input); 36 | std::string line; 37 | int total = 0; 38 | while(std::getline(file, line)) { 39 | total += parse_line_and_get_delta(line); 40 | } 41 | std::cout << total << '\n'; 42 | return 0; 43 | } -------------------------------------------------------------------------------- /2015/cpp/day_08b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // Make sure that the line ending are accurate (let to LF instead of CRLF) 6 | 7 | int parse_line_and_get_delta(const std::string& line) { 8 | std::string just_chars = ""; 9 | for (int i = 0; i < line.size(); i++) { 10 | if (std::isalnum(line[i])) { 11 | just_chars += line[i]; 12 | } else { 13 | just_chars += "\\" + std::string{line[i]}; 14 | } 15 | } 16 | just_chars = '\"' + just_chars + '\"'; 17 | return just_chars.size() - line.size(); 18 | } 19 | 20 | int main(int argc, char* argv[]) { 21 | std::string input = "../input/day_08_input"; 22 | if (argc > 1) { 23 | input = argv[1]; 24 | } 25 | 26 | std::ifstream file(input); 27 | std::string line; 28 | int total = 0; 29 | while(std::getline(file, line)) { 30 | total += parse_line_and_get_delta(line); 31 | } 32 | std::cout << total << '\n'; 33 | return 0; 34 | } -------------------------------------------------------------------------------- /2015/cpp/day_20a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | int presents(const int n) { 12 | int presents = 0; 13 | int i = 1; 14 | while(i * i <= n) { 15 | if (n % i == 0) { 16 | presents += i * 10; 17 | const int i2 = n/i; 18 | if (i2 != i) presents += i2 * 10; 19 | } 20 | i++; 21 | } 22 | // std::cout << n << ": " << presents << '\n'; 23 | return presents; 24 | } 25 | 26 | int main(int argc, char * argv[]) { 27 | std::string input = "../input/day_20_input"; 28 | if (argc > 1) { 29 | input = argv[1]; 30 | } 31 | std::ifstream file(input); 32 | std::string line; 33 | std::getline(file, line); 34 | const int min_presents = std::stoi(line); 35 | int n = 0; 36 | while (presents (n) < min_presents) { 37 | n++; 38 | } 39 | std::cout << n << '\n'; 40 | return 0; 41 | } -------------------------------------------------------------------------------- /2015/cpp/day_20b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | std::unordered_map n_visits; 12 | 13 | int presents(const int n) { 14 | int presents = 0; 15 | int i = 1; 16 | while(i * i <= n) { 17 | if (n % i == 0) { 18 | if (n_visits[i] < 50) { 19 | presents += i * 11; 20 | n_visits[i]++; 21 | } 22 | const int i2 = n/i; 23 | if (i2 != i && n_visits[i2] < 50) { 24 | presents += i2 * 11; 25 | n_visits[i2]++; 26 | } 27 | } 28 | i++; 29 | } 30 | // std::cout << n << ": " << presents << '\n'; 31 | return presents; 32 | } 33 | 34 | int main(int argc, char * argv[]) { 35 | std::string input = "../input/day_20_input"; 36 | if (argc > 1) { 37 | input = argv[1]; 38 | } 39 | std::ifstream file(input); 40 | std::string line; 41 | std::getline(file, line); 42 | const int min_presents = std::stoi(line); 43 | int n = 0; 44 | while (presents (n) < min_presents) { 45 | n++; 46 | } 47 | std::cout << n << '\n'; 48 | return 0; 49 | } -------------------------------------------------------------------------------- /2015/sample_input/day_01_sample_input: -------------------------------------------------------------------------------- 1 | (()) 2 | ()() 3 | ((( 4 | (()(()( 5 | ))((((( 6 | ()) 7 | ))( 8 | ))) 9 | )())()) -------------------------------------------------------------------------------- /2015/sample_input/day_02_sample_input: -------------------------------------------------------------------------------- 1 | 2x3x4 2 | 1x1x10 3 | 1x1x10 -------------------------------------------------------------------------------- /2015/sample_input/day_03_sample_input: -------------------------------------------------------------------------------- 1 | > 2 | ^>v< 3 | ^v^v^v^v^v 4 | ^v 5 | ^>v< 6 | ^v^v^v^v^v -------------------------------------------------------------------------------- /2015/sample_input/day_04_sample_input: -------------------------------------------------------------------------------- 1 | abcdef 2 | pqrstuv 3 | -------------------------------------------------------------------------------- /2015/sample_input/day_05_sample_input: -------------------------------------------------------------------------------- 1 | ugknbfddgicrmopn 2 | aaa 3 | jchzalrnumimnmhp 4 | haegwjzuvuyypxyu 5 | dvszwmarrgswjxmb 6 | qjhvhtzxzqqjkmpb 7 | xxyxx 8 | uurcxstgmygtbstg 9 | ieodomkazucvgmuy -------------------------------------------------------------------------------- /2015/sample_input/day_06_sample_input: -------------------------------------------------------------------------------- 1 | turn on 0,0 through 999,999 2 | toggle 0,0 through 999,0 3 | turn off 499,499 through 500,500 4 | -------------------------------------------------------------------------------- /2015/sample_input/day_07_sample_input: -------------------------------------------------------------------------------- 1 | 123 -> x 2 | 456 -> y 3 | x AND y -> d 4 | x OR y -> e 5 | x LSHIFT 2 -> f 6 | y RSHIFT 2 -> g 7 | NOT x -> h 8 | NOT y -> i -------------------------------------------------------------------------------- /2015/sample_input/day_08_sample_input: -------------------------------------------------------------------------------- 1 | "" 2 | "abc" 3 | "aaa\"aaa" 4 | "\x27" -------------------------------------------------------------------------------- /2015/sample_input/day_09_sample_input: -------------------------------------------------------------------------------- 1 | London to Dublin = 464 2 | London to Belfast = 518 3 | Dublin to Belfast = 141 -------------------------------------------------------------------------------- /2015/sample_input/day_10_sample_input: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /2015/sample_input/day_11_sample_input: -------------------------------------------------------------------------------- 1 | hijklmmn 2 | abbceffg 3 | abbcegjk 4 | abcdefgh 5 | ghijklmn -------------------------------------------------------------------------------- /2015/sample_input/day_12_sample_input: -------------------------------------------------------------------------------- 1 | [1,2,3] 2 | {"a":2,"b":4} 3 | [[[3]]] 4 | {"a":{"b":4},"c":-1} 5 | {"a":[-1,1]} 6 | [-1,{"a":1}] 7 | [] 8 | {} 9 | [1,2,3] 10 | [1,{"c":"red","b":2},3] 11 | {"d":"red","e":[1,2,3,4],"f":5} 12 | [1,"red",5] -------------------------------------------------------------------------------- /2015/sample_input/day_13_sample_input: -------------------------------------------------------------------------------- 1 | Alice would gain 54 happiness units by sitting next to Bob. 2 | Alice would lose 79 happiness units by sitting next to Carol. 3 | Alice would lose 2 happiness units by sitting next to David. 4 | Bob would gain 83 happiness units by sitting next to Alice. 5 | Bob would lose 7 happiness units by sitting next to Carol. 6 | Bob would lose 63 happiness units by sitting next to David. 7 | Carol would lose 62 happiness units by sitting next to Alice. 8 | Carol would gain 60 happiness units by sitting next to Bob. 9 | Carol would gain 55 happiness units by sitting next to David. 10 | David would gain 46 happiness units by sitting next to Alice. 11 | David would lose 7 happiness units by sitting next to Bob. 12 | David would gain 41 happiness units by sitting next to Carol. -------------------------------------------------------------------------------- /2015/sample_input/day_14_sample_input: -------------------------------------------------------------------------------- 1 | Comet can fly 14 km/s for 10 seconds, but then must rest for 127 seconds. 2 | Dancer can fly 16 km/s for 11 seconds, but then must rest for 162 seconds. -------------------------------------------------------------------------------- /2015/sample_input/day_15_sample_input: -------------------------------------------------------------------------------- 1 | Butterscotch: capacity -1, durability -2, flavor 6, texture 3, calories 8 2 | Cinnamon: capacity 2, durability 3, flavor -2, texture -1, calories 3 -------------------------------------------------------------------------------- /2015/sample_input/day_16_sample_input: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vss2sn/advent_of_code/f94d7f5ca09e351e5f7698a2d26776307fdca229/2015/sample_input/day_16_sample_input -------------------------------------------------------------------------------- /2015/sample_input/day_17_sample_input: -------------------------------------------------------------------------------- 1 | 20 2 | 15 3 | 10 4 | 5 5 | 5 -------------------------------------------------------------------------------- /2015/sample_input/day_18_sample_input: -------------------------------------------------------------------------------- 1 | .#.#.# 2 | ...##. 3 | #....# 4 | ..#... 5 | #.#..# 6 | ####.. -------------------------------------------------------------------------------- /2015/sample_input/day_19_sample_input: -------------------------------------------------------------------------------- 1 | H => HO 2 | H => OH 3 | O => HH 4 | 5 | HOH 6 | HOHOHO 7 | 8 | e => H 9 | e => O 10 | H => HO 11 | H => OH 12 | O => HH 13 | 14 | HOH -------------------------------------------------------------------------------- /2015/sample_input/day_20_sample_input: -------------------------------------------------------------------------------- 1 | 150 -------------------------------------------------------------------------------- /2015/sample_input/day_21_sample_input: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vss2sn/advent_of_code/f94d7f5ca09e351e5f7698a2d26776307fdca229/2015/sample_input/day_21_sample_input -------------------------------------------------------------------------------- /2015/sample_input/day_22_sample_input: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vss2sn/advent_of_code/f94d7f5ca09e351e5f7698a2d26776307fdca229/2015/sample_input/day_22_sample_input -------------------------------------------------------------------------------- /2015/sample_input/day_23_sample_input: -------------------------------------------------------------------------------- 1 | inc a 2 | jio a, +2 3 | tpl a 4 | inc a -------------------------------------------------------------------------------- /2015/sample_input/day_24_sample_input: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 7 7 | 8 8 | 9 9 | 10 10 | 11 -------------------------------------------------------------------------------- /2015/sample_input/day_25_sample_input: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vss2sn/advent_of_code/f94d7f5ca09e351e5f7698a2d26776307fdca229/2015/sample_input/day_25_sample_input -------------------------------------------------------------------------------- /2016/cpp/day_02a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char* argv[]) { 7 | std::string input = "../input/day_02_input"; 8 | if (argc > 1) { 9 | input = argv[1]; 10 | } 11 | 12 | std::ifstream file(input); 13 | std::string instructions; 14 | 15 | constexpr int dim = 3; 16 | std::array, dim> keypad{ 17 | std::array{1,2,3}, 18 | std::array{4,5,6}, 19 | std::array{7,8,9} 20 | }; 21 | int current_x = 1; 22 | int current_y = 1; 23 | while(std::getline(file, instructions)) { 24 | for (const auto instruction : instructions) { 25 | if (instruction == 'U') { 26 | if (current_y != 0) current_y -= 1; 27 | } 28 | else if (instruction == 'R') { 29 | if (current_x != 2) current_x += 1; 30 | } 31 | else if (instruction == 'D') { 32 | if (current_y != 2) current_y += 1; 33 | } 34 | else if (instruction == 'L') { 35 | if (current_x != 0) current_x -= 1; 36 | } 37 | // std::cout << keypad[current_y][current_x]; 38 | } 39 | std::cout << keypad[current_y][current_x]; 40 | } 41 | std::cout << '\n'; 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /2016/cpp/day_06a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char* argv[]) { 9 | std::string input = "../input/day_06_input"; 10 | if (argc > 1) { 11 | input = argv[1]; 12 | } 13 | std::string line; 14 | std::fstream file(input); 15 | std::vector> frequencies; 16 | while(std::getline(file, line)) { 17 | while(frequencies.size() < line.size()) { 18 | frequencies.emplace_back(); 19 | } 20 | for (std::size_t idx = 0; idx < line.size(); idx++) { 21 | frequencies[idx][line[idx]]++; 22 | } 23 | } 24 | std::string most_frequent(frequencies.size(), '0'); 25 | for (std::size_t idx = 0; idx < frequencies.size(); idx++) { 26 | int max_f = 0; 27 | for (const auto& [c, f] : frequencies[idx]) { 28 | if (f > max_f) { 29 | max_f = f; 30 | most_frequent[idx] = c; 31 | } 32 | } 33 | } 34 | std::cout << most_frequent << '\n'; 35 | return 0; 36 | } -------------------------------------------------------------------------------- /2016/cpp/day_06b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int main(int argc, char* argv[]) { 10 | std::string input = "../input/day_06_input"; 11 | if (argc > 1) { 12 | input = argv[1]; 13 | } 14 | std::string line; 15 | std::fstream file(input); 16 | std::vector> frequencies; 17 | while(std::getline(file, line)) { 18 | while(frequencies.size() < line.size()) { 19 | frequencies.emplace_back(); 20 | } 21 | for (std::size_t idx = 0; idx < line.size(); idx++) { 22 | frequencies[idx][line[idx]]++; 23 | } 24 | } 25 | std::string least_frequent(frequencies.size(), '0'); 26 | for (std::size_t idx = 0; idx < frequencies.size(); idx++) { 27 | int min_f = std::numeric_limits::max(); 28 | for (const auto& [c, f] : frequencies[idx]) { 29 | if (f < min_f) { 30 | min_f = f; 31 | least_frequent[idx] = c; 32 | } 33 | } 34 | } 35 | std::cout << least_frequent << '\n'; 36 | return 0; 37 | } -------------------------------------------------------------------------------- /2016/cpp/day_19a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char* argv[]) { 7 | std::string input = "../input/day_19_input"; 8 | if (argc > 1) { 9 | input = argv[1]; 10 | } 11 | 12 | std::ifstream file(input); 13 | std::string line; 14 | std::getline(file, line); 15 | const int n_elves = std::stoi(line); 16 | std::unordered_map elves; 17 | for (int i = 1; i <= n_elves;i++) { 18 | elves[i] = i+1; 19 | } 20 | elves[n_elves] = 1; 21 | int current = 1; 22 | while(elves[current] != current) { 23 | // std::cout << elves[current] << " out" << '\n'; 24 | elves[current] = elves[elves[current]]; 25 | current = elves[current]; 26 | } 27 | std::cout << current << '\n'; 28 | return 0; 29 | } -------------------------------------------------------------------------------- /2016/cpp/day_20a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | struct Range { 8 | long long start; 9 | long long end; 10 | }; 11 | 12 | int main(int argc, char* argv[]) { 13 | std::string input = "../input/day_20_input"; 14 | if (argc > 1) { 15 | input = argv[1]; 16 | } 17 | 18 | std::ifstream file(input); 19 | std::string line; 20 | std::vector ranges; 21 | while(std::getline(file, line)) { 22 | const auto dash_idx = line.find('-'); 23 | Range range; 24 | std::cout << '|' << line.substr(0, dash_idx) << '|' << '\n'; 25 | std::cout << '|' << line.substr(dash_idx + 1, line.size() - dash_idx - 1) << '|' << '\n'; 26 | range.start = std::stoll(line.substr(0, dash_idx)); 27 | range.end = std::stoll(line.substr(dash_idx + 1, line.size() - dash_idx - 1)); 28 | ranges.push_back(range); 29 | } 30 | std::sort(std::begin(ranges), std::end(ranges), [](const Range& r1, const Range& r2) { return r1.start < r2.start; }); 31 | if (ranges[0].start != 0) { 32 | std::cout << 0 << '\n'; 33 | return 0; 34 | } 35 | for (std::size_t idx = 0; idx < ranges.size() - 1; idx++) { 36 | if (ranges[idx].end + 1 < ranges[idx+1].start) { 37 | std::cout << ranges[idx].end + 1 << '\n'; 38 | return 0; 39 | } 40 | } 41 | std::cout << ranges.back().end+1 << '\n'; 42 | return 0; 43 | } -------------------------------------------------------------------------------- /2016/sample_input/day_01_sample_input: -------------------------------------------------------------------------------- 1 | R2, L3 2 | R2, R2, R2 3 | R5, L5, R5, R3 4 | R8, R4, R4, R8 5 | -------------------------------------------------------------------------------- /2016/sample_input/day_02_sample_input: -------------------------------------------------------------------------------- 1 | ULL 2 | RRDDD 3 | LURDL 4 | UUUUD -------------------------------------------------------------------------------- /2016/sample_input/day_03_sample_input: -------------------------------------------------------------------------------- 1 | 5 10 25 -------------------------------------------------------------------------------- /2016/sample_input/day_04_sample_input: -------------------------------------------------------------------------------- 1 | aaaaa-bbb-z-y-x-123[abxyz] 2 | a-b-c-d-e-f-g-h-987[abcde] 3 | not-a-real-room-404[oarel] 4 | totally-real-room-200[decoy] 5 | qzmt-zixmtkozy-ivhz-343[very encrypted name] 6 | -------------------------------------------------------------------------------- /2016/sample_input/day_05_sample_input: -------------------------------------------------------------------------------- 1 | abc -------------------------------------------------------------------------------- /2016/sample_input/day_06_sample_input: -------------------------------------------------------------------------------- 1 | eedadn 2 | drvtee 3 | eandsr 4 | raavrd 5 | atevrs 6 | tsrnev 7 | sdttsa 8 | rasrtv 9 | nssdts 10 | ntnada 11 | svetve 12 | tesnvt 13 | vntsnd 14 | vrdear 15 | dvrsen 16 | enarar -------------------------------------------------------------------------------- /2016/sample_input/day_07_sample_input: -------------------------------------------------------------------------------- 1 | abba[mnop]qrst 2 | abcd[bddb]xyyx 3 | aaaa[qwer]tyui 4 | ioxxoj[asdfgh]zxcvbn 5 | aba[bab]xyz 6 | xyx[xyx]xyx 7 | aaa[kek]eke 8 | zazbz[bzb]cdb -------------------------------------------------------------------------------- /2016/sample_input/day_08_sample_input: -------------------------------------------------------------------------------- 1 | rect 3x2 2 | rotate column x=1 by 1 3 | rotate row y=0 by 4 4 | rotate column x=1 by 1 -------------------------------------------------------------------------------- /2016/sample_input/day_09_sample_input: -------------------------------------------------------------------------------- 1 | ADVENT 2 | A(1x5)BC 3 | (3x3)XYZ 4 | A(2x2)BCD(2x2)EFG 5 | (6x1)(1x3)A 6 | X(8x2)(3x3)ABCY 7 | (3x3)XYZ 8 | X(8x2)(3x3)ABCY 9 | (27x12)(20x12)(13x14)(7x10)(1x12)A 10 | (25x3)(3x3)ABC(2x3)XY(5x2)PQRSTX(18x9)(3x2)TWO(5x7)SEVEN -------------------------------------------------------------------------------- /2016/sample_input/day_10_sample_input: -------------------------------------------------------------------------------- 1 | value 5 goes to bot 2 2 | bot 2 gives low to bot 1 and high to bot 0 3 | value 3 goes to bot 1 4 | bot 1 gives low to output 1 and high to bot 0 5 | bot 0 gives low to output 2 and high to output 0 6 | value 2 goes to bot 2 -------------------------------------------------------------------------------- /2016/sample_input/day_11_sample_input: -------------------------------------------------------------------------------- 1 | The first floor contains a hydrogen-compatible microchip and a lithium-compatible microchip. 2 | The second floor contains a hydrogen generator. 3 | The third floor contains a lithium generator. 4 | The fourth floor contains nothing relevant. -------------------------------------------------------------------------------- /2016/sample_input/day_12_sample_input: -------------------------------------------------------------------------------- 1 | cpy 41 a 2 | inc a 3 | inc a 4 | dec a 5 | jnz a 2 6 | dec a -------------------------------------------------------------------------------- /2016/sample_input/day_13_sample_input: -------------------------------------------------------------------------------- 1 | 10 -------------------------------------------------------------------------------- /2016/sample_input/day_14_sample_input: -------------------------------------------------------------------------------- 1 | abc -------------------------------------------------------------------------------- /2016/sample_input/day_15_sample_input: -------------------------------------------------------------------------------- 1 | Disc #1 has 5 positions; at time=0, it is at position 4. 2 | Disc #2 has 2 positions; at time=0, it is at position 1. -------------------------------------------------------------------------------- /2016/sample_input/day_16_sample_input: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vss2sn/advent_of_code/f94d7f5ca09e351e5f7698a2d26776307fdca229/2016/sample_input/day_16_sample_input -------------------------------------------------------------------------------- /2016/sample_input/day_17_sample_input: -------------------------------------------------------------------------------- 1 | hijkl 2 | ihgpwlah 3 | kglvqrro 4 | ulqzkmiv 5 | -------------------------------------------------------------------------------- /2016/sample_input/day_18_sample_input: -------------------------------------------------------------------------------- 1 | ..^^. 2 | .^^.^.^^^^ -------------------------------------------------------------------------------- /2016/sample_input/day_19_sample_input: -------------------------------------------------------------------------------- 1 | 8 -------------------------------------------------------------------------------- /2016/sample_input/day_20_sample_input: -------------------------------------------------------------------------------- 1 | 5-8 2 | 0-2 3 | 4-7 -------------------------------------------------------------------------------- /2016/sample_input/day_21_sample_input: -------------------------------------------------------------------------------- 1 | swap position 4 with position 0 2 | swap letter d with letter b 3 | reverse positions 0 through 4 4 | rotate left 1 step 5 | move position 1 to position 4 6 | move position 3 to position 0 7 | rotate based on position of letter b 8 | rotate based on position of letter d -------------------------------------------------------------------------------- /2016/sample_input/day_22_sample_input: -------------------------------------------------------------------------------- 1 | Filesystem Size Used Avail Use% 2 | /dev/grid/node-x0-y0 10T 8T 2T 80% 3 | /dev/grid/node-x0-y1 11T 6T 5T 54% 4 | /dev/grid/node-x0-y2 32T 28T 4T 87% 5 | /dev/grid/node-x1-y0 9T 7T 2T 77% 6 | /dev/grid/node-x1-y1 8T 0T 8T 0% 7 | /dev/grid/node-x1-y2 11T 7T 4T 63% 8 | /dev/grid/node-x2-y0 10T 6T 4T 60% 9 | /dev/grid/node-x2-y1 9T 8T 1T 88% 10 | /dev/grid/node-x2-y2 9T 6T 3T 66% -------------------------------------------------------------------------------- /2016/sample_input/day_23_sample_input: -------------------------------------------------------------------------------- 1 | cpy 2 a 2 | tgl a 3 | tgl a 4 | tgl a 5 | cpy 1 a 6 | dec a 7 | dec a -------------------------------------------------------------------------------- /2016/sample_input/day_24_sample_input: -------------------------------------------------------------------------------- 1 | ########### 2 | #0.1.....2# 3 | #.#######.# 4 | #4.......3# 5 | ########### -------------------------------------------------------------------------------- /2016/sample_input/day_25_sample_input: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vss2sn/advent_of_code/f94d7f5ca09e351e5f7698a2d26776307fdca229/2016/sample_input/day_25_sample_input -------------------------------------------------------------------------------- /2017/cpp/day_01a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char* argv[]) { 6 | std::string input = "../input/day_01_input"; 7 | if (argc > 1) { 8 | input = argv[1]; 9 | } 10 | 11 | long long sum = 0; 12 | std::ifstream file(input); 13 | std::string num; 14 | std::getline(file, num); 15 | std::size_t count = 0; 16 | for(std::size_t idx = 0; idx < num.size()-1; idx++) { 17 | if (num[idx] == num[idx+1]) { 18 | count += num[idx] - '0'; 19 | } 20 | } 21 | if (num.size() > 0 && num[num.size() - 1] == num[0]) { 22 | count += num[0] - '0'; 23 | } 24 | std::cout << count << '\n'; 25 | return count; 26 | } 27 | -------------------------------------------------------------------------------- /2017/cpp/day_01b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char* argv[]) { 6 | std::string input = "../input/day_01_input"; 7 | if (argc > 1) { 8 | input = argv[1]; 9 | } 10 | 11 | long long sum = 0; 12 | std::ifstream file(input); 13 | std::string num; 14 | std::getline(file, num); 15 | std::size_t count = 0; 16 | const auto n = num.size() / 2; 17 | for(std::size_t idx = 0; idx < n; idx++) { 18 | if (num[idx] == num[idx + n]) { 19 | count += num[idx] - '0'; 20 | } 21 | } 22 | count *= 2; 23 | std::cout << count << '\n'; 24 | return count; 25 | } 26 | -------------------------------------------------------------------------------- /2017/cpp/day_02a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char* argv[]) { 9 | const std::string input = (argc > 1) ? argv[1] : "../input/day_02_input" ; 10 | std::ifstream file(input); 11 | std::string line; 12 | int checksum = 0; 13 | while(std::getline(file, line)) { 14 | auto numbers = line 15 | | std::ranges::views::split(' ') 16 | | std::ranges::views::transform([](auto&& rng) { 17 | return std::string_view(&*rng.begin(), std::ranges::distance(rng)); }); 18 | int min_val = std::numeric_limits::max(); 19 | int max_val = std::numeric_limits::min(); 20 | for (const auto n : numbers) { 21 | int val; 22 | std::from_chars(n.data(), n.data() + n.size(), val); 23 | max_val = std::max(val, max_val); 24 | min_val = std::min(val, min_val); 25 | } 26 | checksum += max_val - min_val; 27 | } 28 | std::cout << checksum << '\n'; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /2017/cpp/day_02b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char* argv[]) { 8 | const std::string input = (argc > 1) ? argv[1] : "../input/day_02_input" ; 9 | std::ifstream file(input); 10 | std::string line; 11 | int checksum = 0; 12 | while(std::getline(file, line)) { 13 | std::vector numbers; 14 | const std::string delimiter = " "; 15 | size_t start = 0; 16 | size_t end = line.find(delimiter); 17 | while (end < std::string::npos) { 18 | numbers.emplace_back(std::stoi(line.substr(start, end - start))); 19 | start = end + delimiter.size(); 20 | end = line.find(delimiter, start); 21 | } 22 | numbers.emplace_back(std::stoi(line.substr(start, line.size() - start))); 23 | 24 | bool found = false; 25 | for (int i = 0; i < numbers.size() && !found; i++) { 26 | for (int j = i + 1; j < numbers.size() && !found; j++) { 27 | if (numbers[j] % numbers[i] == 0) { 28 | found = true; 29 | checksum += numbers[j] / numbers[i]; 30 | } 31 | if ( numbers[i] % numbers[j] == 0) { 32 | found = true; 33 | checksum += numbers[i] / numbers[j]; 34 | } 35 | } 36 | } 37 | } 38 | std::cout << checksum << '\n'; 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /2017/cpp/day_04a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char* argv[]) { 7 | const std::string input = (argc > 1) ? argv[1] : "../input/day_04_input" ; 8 | std::ifstream file(input); 9 | std::string line; 10 | int n_valid = 0; 11 | while(std::getline(file, line)) { 12 | bool valid = true; 13 | std::size_t start = 0; 14 | std::size_t end = line.find(' ', start); 15 | std::unordered_set words; 16 | while(end != std::string::npos) { 17 | const auto word = line.substr(start, end - start); 18 | std::cout << '|' << word << '|' << '\n'; 19 | if(!words.insert(word).second) { 20 | std::cout << "Duplicate word " << word << " detected. Invalid passphrase." << '\n'; 21 | valid = false; 22 | break; 23 | } 24 | start = end + 1; 25 | end = line.find(' ', start); 26 | } 27 | if (valid) { 28 | const auto word = line.substr(start, line.size() - start); 29 | std::cout << '|' << word << '|' << '\n'; 30 | if(!words.insert(word).second) { 31 | std::cout << "Duplicate word " << word << " detected. Invalid passphrase." << '\n'; 32 | valid = false; 33 | } 34 | } 35 | 36 | if (valid) { 37 | std::cout << "Valid passphrase." << '\n'; 38 | n_valid++; 39 | } 40 | } 41 | std::cout << "Number of valid passphrases: " << n_valid << '\n'; 42 | return 0; 43 | } -------------------------------------------------------------------------------- /2017/cpp/day_05a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char* argv[]) { 9 | const std::string input = (argc > 1) ? argv[1] : "../input/day_05_input" ; 10 | std::ifstream file(input); 11 | std::string line; 12 | std::size_t n_steps = 0; 13 | int pointer = 0; 14 | std::vector instructions; 15 | while(std::getline(file, line)) { 16 | instructions.emplace_back(std::stoi(line)); 17 | } 18 | while (pointer >= 0 && pointer < instructions.size()) { 19 | const auto prev_pointer = pointer; 20 | pointer += instructions[pointer]; 21 | instructions[prev_pointer]++; 22 | n_steps++; 23 | } 24 | std::cout << n_steps << '\n'; 25 | return 0; 26 | } -------------------------------------------------------------------------------- /2017/cpp/day_05b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char* argv[]) { 9 | const std::string input = (argc > 1) ? argv[1] : "../input/day_05_input" ; 10 | std::ifstream file(input); 11 | std::string line; 12 | std::size_t n_steps = 0; 13 | int pointer = 0; 14 | std::vector instructions; 15 | while(std::getline(file, line)) { 16 | instructions.emplace_back(std::stoi(line)); 17 | } 18 | while (pointer >= 0 && pointer < instructions.size()) { 19 | const auto prev_pointer = pointer; 20 | pointer += instructions[pointer]; 21 | if (instructions[prev_pointer] >= 3) { 22 | instructions[prev_pointer]--; 23 | } else { 24 | instructions[prev_pointer]++; 25 | } 26 | n_steps++; 27 | } 28 | std::cout << n_steps << '\n'; 29 | return 0; 30 | } -------------------------------------------------------------------------------- /2017/cpp/day_09a.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | int main(int argc, char* argv[]) { 13 | const std::string input = (argc > 1) ? argv[1] : "../input/day_09_input" ; 14 | std::ifstream file(input); 15 | std::string line; 16 | while(std::getline(file, line)) { 17 | int idx = 0; 18 | bool is_in_garbage = false; 19 | int level = 0; 20 | int score = 0; 21 | int groups = 0; 22 | while(idx < line.size()) { 23 | if (!is_in_garbage) { 24 | if (line[idx] == '{') { 25 | level++; 26 | score += level; 27 | groups++; 28 | } 29 | else if (line[idx] == '}') { 30 | level--; 31 | } 32 | else if (line[idx] == '<') { 33 | is_in_garbage = true; 34 | } 35 | } else { 36 | if (line[idx] == '!') { 37 | idx++; 38 | } else if (line[idx] == '>') { 39 | is_in_garbage = false; 40 | } 41 | } 42 | idx++; 43 | } 44 | std::cout << "groups: " << groups << '\n'; 45 | std::cout << "score: " << score << '\n'; 46 | std::cout << '\n'; 47 | } 48 | return 0; 49 | } -------------------------------------------------------------------------------- /2017/cpp/day_09b.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | int main(int argc, char* argv[]) { 13 | const std::string input = (argc > 1) ? argv[1] : "../input/day_09_input" ; 14 | std::ifstream file(input); 15 | std::string line; 16 | while(std::getline(file, line)) { 17 | int idx = 0; 18 | bool is_in_garbage = false; 19 | int level = 0; 20 | int score = 0; 21 | int groups = 0; 22 | int char_count = 0; 23 | while(idx < line.size()) { 24 | if (!is_in_garbage) { 25 | if (line[idx] == '{') { 26 | level++; 27 | score += level; 28 | groups++; 29 | } 30 | else if (line[idx] == '}') { 31 | level--; 32 | } 33 | else if (line[idx] == '<') { 34 | is_in_garbage = true; 35 | } 36 | } else { 37 | if (line[idx] == '!') { 38 | idx++; 39 | } else if (line[idx] == '>') { 40 | is_in_garbage = false; 41 | } else { 42 | char_count++; 43 | } 44 | } 45 | idx++; 46 | } 47 | std::cout << "groups: " << groups << '\n'; 48 | std::cout << "score: " << score << '\n'; 49 | std::cout << "char_count: " << char_count << '\n'; 50 | std::cout << '\n'; 51 | } 52 | return 0; 53 | } -------------------------------------------------------------------------------- /2017/cpp/day_13a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | void parse_input(const std::string& line, std::unordered_map& map) { 14 | std::size_t start = 0; 15 | const std::string delimiter = ": "; 16 | std::size_t end = line.find(delimiter); 17 | const auto depth = std::stoi(line.substr(start, end - start)); 18 | start = end + delimiter.size(); 19 | end = line.find(delimiter, start); 20 | const auto range = std::stoi(line.substr(start, end - start)); 21 | map[depth] = range; 22 | } 23 | 24 | int main(int argc, char* argv[]) { 25 | const std::string input = (argc > 1) ? argv[1] : "../input/day_13_input" ; 26 | std::ifstream file(input); 27 | std::string line; 28 | std::unordered_map map; 29 | while(std::getline(file, line)) { 30 | parse_input(line, map); 31 | } 32 | int total_severity = 0; 33 | for (const auto& [depth, range] : map) { 34 | if (depth % ((range - 1) * 2) == 0) { 35 | total_severity += depth * range; 36 | } 37 | } 38 | std::cout << total_severity << '\n'; 39 | return 0; 40 | } -------------------------------------------------------------------------------- /2017/cpp/day_17a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | int main(int argc, char* argv[]) { 14 | const std::string input = (argc > 1) ? argv[1] : "../input/day_17_input" ; 15 | std::ifstream file(input); 16 | std::string line; 17 | std::getline(file, line); 18 | std::vector buffer{0}; 19 | buffer.reserve(2018); 20 | int current_position = 0; 21 | const int number = std::stoi(line); 22 | for (int i = 1 ; i <= 2017; i++) { 23 | const int rem = (current_position + number + 1) % buffer.size(); 24 | if (rem == buffer.size()) { 25 | buffer.push_back(i); 26 | } else { 27 | buffer.insert(std::next(std::begin(buffer) + rem), i); 28 | } 29 | current_position = rem; 30 | // std::cout << i << " inserted at " << current_position << '\n'; 31 | // for (const auto ele : buffer ) { 32 | // std::cout << ele << ' '; 33 | // } 34 | // std::cout << '\n'; 35 | } 36 | std::cout << buffer [(current_position + 2) % buffer.size()] << '\n'; 37 | return 0; 38 | } -------------------------------------------------------------------------------- /2017/cpp/day_17b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char* argv[]) { 6 | const std::string input = (argc > 1) ? argv[1] : "../input/day_17_input" ; 7 | std::ifstream file(input); 8 | std::string line; 9 | std::getline(file, line); 10 | int current_value = 0; 11 | int current_position = 0; 12 | const int n_jumps = std::stoi(line); 13 | for (int i = 1 ; i <= 50000001; i++) { 14 | // Not current_position = (current_position + n_jumps + 1) % i; 15 | current_position = (current_position + n_jumps) % i + 1; 16 | if (current_position == 1) { 17 | current_value = i; 18 | } 19 | } 20 | std::cout << current_value << '\n'; 21 | return 0; 22 | } -------------------------------------------------------------------------------- /2017/sample_input/day_01_sample_input: -------------------------------------------------------------------------------- 1 | 1122 2 | 1111 3 | 1234 4 | 91212129 5 | 6 | 1212 7 | 1221 8 | 123425 9 | 123123 10 | 12131415 -------------------------------------------------------------------------------- /2017/sample_input/day_02_sample_input: -------------------------------------------------------------------------------- 1 | 5 1 9 5 2 | 7 5 3 3 | 2 4 6 8 4 | 5 | 5 9 2 8 6 | 9 4 7 3 7 | 3 8 6 5 -------------------------------------------------------------------------------- /2017/sample_input/day_03_sample_input: -------------------------------------------------------------------------------- 1 | 747 -------------------------------------------------------------------------------- /2017/sample_input/day_04_sample_input: -------------------------------------------------------------------------------- 1 | aa bb cc dd ee 2 | aa bb cc dd aa 3 | aa bb cc dd aaa -------------------------------------------------------------------------------- /2017/sample_input/day_05_sample_input: -------------------------------------------------------------------------------- 1 | 0 2 | 3 3 | 0 4 | 1 5 | -3 -------------------------------------------------------------------------------- /2017/sample_input/day_06_sample_input: -------------------------------------------------------------------------------- 1 | 0 2 7 0 -------------------------------------------------------------------------------- /2017/sample_input/day_07_sample_input: -------------------------------------------------------------------------------- 1 | pbga (66) 2 | xhth (57) 3 | ebii (61) 4 | havc (66) 5 | ktlj (57) 6 | fwft (72) -> ktlj, cntj, xhth 7 | qoyq (66) 8 | padx (45) -> pbga, havc, qoyq 9 | tknk (41) -> ugml, padx, fwft 10 | jptl (61) 11 | ugml (68) -> gyxo, ebii, jptl 12 | gyxo (61) 13 | cntj (57) -------------------------------------------------------------------------------- /2017/sample_input/day_08_sample_input: -------------------------------------------------------------------------------- 1 | b inc 5 if a > 1 2 | a inc 1 if b < 5 3 | c dec -10 if a >= 1 4 | c inc -20 if c == 10 -------------------------------------------------------------------------------- /2017/sample_input/day_09_sample_input: -------------------------------------------------------------------------------- 1 | {} 2 | {{{}}} 3 | {{},{}} 4 | {{{},{},{{}}}} 5 | {<{},{},{{}}>} 6 | {,,,} 7 | {{},{},{},{}} 8 | {{},{},{},{}} 9 | {{},{},{},{}} 10 | {{},{},{},{}} 11 | {{},{},{},{}} 12 | <> 13 | 14 | <<<<> 15 | <{!>}> 16 | 17 | > 18 | <{o"i!a,<{i -------------------------------------------------------------------------------- /2017/sample_input/day_10_sample_input: -------------------------------------------------------------------------------- 1 | 3, 4, 1, 5 2 | AoC 2017 3 | 1,2,3 4 | 1,2,4 -------------------------------------------------------------------------------- /2017/sample_input/day_11_sample_input: -------------------------------------------------------------------------------- 1 | ne,ne,ne 2 | ne,ne,sw,sw 3 | ne,ne,s,s 4 | se,sw,se,sw,sw -------------------------------------------------------------------------------- /2017/sample_input/day_12_sample_input: -------------------------------------------------------------------------------- 1 | 0 <-> 2 2 | 1 <-> 1 3 | 2 <-> 0, 3, 4 4 | 3 <-> 2, 4 5 | 4 <-> 2, 3, 6 6 | 5 <-> 6 7 | 6 <-> 4, 5 -------------------------------------------------------------------------------- /2017/sample_input/day_13_sample_input: -------------------------------------------------------------------------------- 1 | 0: 3 2 | 1: 2 3 | 4: 4 4 | 6: 4 -------------------------------------------------------------------------------- /2017/sample_input/day_14_sample_input: -------------------------------------------------------------------------------- 1 | flqrgnkx -------------------------------------------------------------------------------- /2017/sample_input/day_15_sample_input: -------------------------------------------------------------------------------- 1 | Generator A starts with 65 2 | Generator B starts with 8921 -------------------------------------------------------------------------------- /2017/sample_input/day_16_sample_input: -------------------------------------------------------------------------------- 1 | s1,x3/4,pe/b -------------------------------------------------------------------------------- /2017/sample_input/day_17_sample_input: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /2017/sample_input/day_18_sample_input: -------------------------------------------------------------------------------- 1 | set a 1 2 | add a 2 3 | mul a a 4 | mod a 5 5 | snd a 6 | set a 0 7 | rcv a 8 | jgz a -1 9 | set a 1 10 | jgz a -2 11 | 12 | snd 1 13 | snd 2 14 | snd p 15 | rcv a 16 | rcv b 17 | rcv c 18 | rcv d -------------------------------------------------------------------------------- /2017/sample_input/day_19_sample_input: -------------------------------------------------------------------------------- 1 | | 2 | | +--+ 3 | A | C 4 | F---|----E|--+ 5 | | | | D 6 | +B-+ +--+ 7 | -------------------------------------------------------------------------------- /2017/sample_input/day_20_sample_input: -------------------------------------------------------------------------------- 1 | p=< 3,0,0>, v=< 2,0,0>, a=<-1,0,0> 2 | p=< 4,0,0>, v=< 0,0,0>, a=<-2,0,0> 3 | 4 | p=<-6,0,0>, v=<3,0,0>, a=<0,0,0> 5 | p=<-4,0,0>, v=<2,0,0>, a=<0,0,0> 6 | p=<-2,0,0>, v=<1,0,0>, a=<0,0,0> 7 | p=<4,0,0>, v=<-1,0,0>, a=<-1,0,0> -------------------------------------------------------------------------------- /2017/sample_input/day_21_sample_input: -------------------------------------------------------------------------------- 1 | ../.# => ##./#../... 2 | .#./..#/### => #..#/..../..../#..# -------------------------------------------------------------------------------- /2017/sample_input/day_22_sample_input: -------------------------------------------------------------------------------- 1 | ..# 2 | #.. 3 | ... -------------------------------------------------------------------------------- /2017/sample_input/day_23_sample_input: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vss2sn/advent_of_code/f94d7f5ca09e351e5f7698a2d26776307fdca229/2017/sample_input/day_23_sample_input -------------------------------------------------------------------------------- /2017/sample_input/day_24_sample_input: -------------------------------------------------------------------------------- 1 | 0/2 2 | 2/2 3 | 2/3 4 | 3/4 5 | 3/5 6 | 0/1 7 | 10/1 8 | 9/10 -------------------------------------------------------------------------------- /2017/sample_input/day_25_sample_input: -------------------------------------------------------------------------------- 1 | Begin in state A. 2 | Perform a diagnostic checksum after 6 steps. 3 | 4 | In state A: 5 | If the current value is 0: 6 | - Write the value 1. 7 | - Move one slot to the right. 8 | - Continue with state B. 9 | If the current value is 1: 10 | - Write the value 0. 11 | - Move one slot to the left. 12 | - Continue with state B. 13 | 14 | In state B: 15 | If the current value is 0: 16 | - Write the value 1. 17 | - Move one slot to the left. 18 | - Continue with state A. 19 | If the current value is 1: 20 | - Write the value 1. 21 | - Move one slot to the right. 22 | - Continue with state A. -------------------------------------------------------------------------------- /2018/cpp/day_01a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char* argv[]) { 7 | constexpr int start_f = 0; 8 | std::string input = "../input/day_01_input"; 9 | if (argc > 1) { 10 | input = argv[1]; 11 | } 12 | 13 | long long sum = 0; 14 | std::ifstream file(input); 15 | std::string num; 16 | while(std::getline(file, num)) { 17 | if (num.substr(0, 1) == "+") { 18 | sum += stoll(num.substr(1, num.size() - 1)); 19 | } else { 20 | sum += stoll(num); 21 | } 22 | } 23 | std::cout << sum << '\n'; 24 | return sum; 25 | } 26 | -------------------------------------------------------------------------------- /2018/cpp/day_01b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char* argv[]) { 8 | constexpr int start_f = 0; 9 | std::string input = "../input/day_01_input"; 10 | if (argc > 1) { 11 | input = argv[1]; 12 | } 13 | 14 | long long sum = 0; 15 | std::unordered_set seen_vals; 16 | seen_vals.insert(start_f); 17 | bool duplicate_found = false; 18 | 19 | while (!duplicate_found) { 20 | std::ifstream file(input); 21 | std::string num; 22 | while(std::getline(file, num)) { 23 | if (num.substr(0, 1) == "+") { 24 | sum += stoll(num.substr(1, num.size() - 1)); 25 | } else { 26 | sum += stoll(num); 27 | } 28 | if (const auto [iter, inserted] = seen_vals.insert(sum); !inserted) { 29 | duplicate_found = true; 30 | break; 31 | } 32 | } 33 | } 34 | std::cout << sum << '\n'; 35 | return sum; 36 | } 37 | -------------------------------------------------------------------------------- /2018/cpp/day_02a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char* argv[]) { 7 | 8 | std::string input = "../input/day_02_input"; 9 | if (argc > 1) { 10 | input = argv[1]; 11 | } 12 | 13 | std::string line; 14 | long long n_2_reps = 0; 15 | long long n_3_reps = 0; 16 | 17 | std::fstream file(input); 18 | while (std::getline(file, line)) { 19 | std::vector counts(26, 0); 20 | for (const auto c : line) { 21 | counts[c - 'a']++; 22 | } 23 | if(std::find(std::begin(counts), std::end(counts), 2) != std::end(counts)) { 24 | n_2_reps++; 25 | } 26 | if(std::find(std::begin(counts), std::end(counts), 3) != std::end(counts)) { 27 | n_3_reps++; 28 | } 29 | } 30 | const long long ans = n_2_reps * n_3_reps; 31 | std::cout << ans << '\n'; 32 | return ans; 33 | } 34 | -------------------------------------------------------------------------------- /2018/cpp/day_05a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char* argv[]) { 8 | std::string input = "../input/day_05_input"; 9 | if (argc > 1) { 10 | input = argv[1]; 11 | } 12 | 13 | std::ifstream file(input); 14 | std::string polymer; 15 | std:getline(file, polymer); 16 | 17 | const size_t delta1 = int('a') - int('A'); 18 | const size_t delta2 = int('A') - int('a'); 19 | std::size_t start = 0; 20 | std::size_t end = 1; 21 | while(end < polymer.size()) { 22 | if (polymer[start] - polymer[end] == delta1 || polymer[start] - polymer[end] == delta2) { 23 | polymer[start] = ' '; 24 | polymer[end] = ' '; 25 | while (polymer[start] == ' ' && start > 0) { 26 | start--; 27 | } 28 | } else { 29 | start += 1; 30 | } 31 | while (polymer[start] == ' ') { 32 | start++; 33 | } 34 | end = start + 1; 35 | while (polymer[end] == ' ') { 36 | end++; 37 | } 38 | } 39 | auto it = std::remove(std::begin(polymer), std::end(polymer), ' '); 40 | polymer.erase(it, std::end(polymer)); 41 | const auto ans = polymer.size(); 42 | std::cout << ans << '\n'; 43 | return ans; 44 | } 45 | -------------------------------------------------------------------------------- /2018/cpp/day_14a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char* argv[]) { 7 | std::string input = "../input/day_14_input"; 8 | if (argc > 1) { 9 | input = argv[1]; 10 | } 11 | std::ifstream file(input); 12 | std::string line; 13 | std::getline(file, line); 14 | int n = stoi(line); 15 | const int n_recipes = n + 11; 16 | int e1 = 0; 17 | int e2 = 1; 18 | std::vector scores{3, 7}; 19 | while (scores.size() < n_recipes) { 20 | int total_score = scores[e1] + scores[e2]; 21 | if (total_score > 9) { 22 | scores.push_back(total_score / 10); 23 | } 24 | scores.push_back(total_score % 10); 25 | e1 = (e1 + scores[e1] + 1) % scores.size(); 26 | e2 = (e2 + scores[e2] + 1) % scores.size(); 27 | } 28 | 29 | long long ans = 0; 30 | for (int i = n_recipes - 11; i < n_recipes - 1; i++) { 31 | ans = ans * 10 + scores[i]; 32 | } 33 | std::cout << ans << '\n'; 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /2018/cpp/day_23a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | struct NanoBot { 9 | long long x, y, z, r; 10 | 11 | NanoBot (const long long x, const long long y, const long long z, const long long r) : x(x), y(y), z(z), r(r) {} 12 | }; 13 | 14 | int main(int argc, char* argv[]) { 15 | std::string input = "../input/day_23_input"; 16 | if (argc > 1) { 17 | input = argv[1]; 18 | } 19 | 20 | std::string line; 21 | std::ifstream file(input); 22 | const std::regex pattern(R"(<(-?[0-9]+),(-?[0-9]+),(-?[0-9]+)>, r=([0-9]+))"); 23 | std::vector bots; 24 | while(std::getline(file, line)) { 25 | std::smatch match; 26 | std::regex_search(line, match, pattern); 27 | bots.emplace_back(std::stoll(match[1]), std::stoll(match[2]), std::stoll(match[3]), std::stoll(match[4])); 28 | } 29 | 30 | std::sort(std::begin(bots), std::end(bots), [](const auto& b1, const auto& b2) { return b1.r > b2.r; }); 31 | const auto ans = std::count_if ( 32 | std::begin(bots), 33 | std::end(bots), 34 | [&bot_main=std::as_const(bots[0])](const auto& bot) { 35 | return std::abs(bot.x-bot_main.x) + std::abs(bot.y-bot_main.y) + std::abs(bot.z-bot_main.z) <= bot_main.r; 36 | } 37 | ); 38 | 39 | std::cout << ans << '\n'; 40 | return ans; 41 | } 42 | -------------------------------------------------------------------------------- /2018/sample_input/day_01_sample_input: -------------------------------------------------------------------------------- 1 | +1 2 | -2 3 | +3 4 | +1, 5 | -------------------------------------------------------------------------------- /2018/sample_input/day_02_sample_input: -------------------------------------------------------------------------------- 1 | abcde 2 | fghij 3 | klmno 4 | pqrst 5 | fguij 6 | axcye 7 | wvxyz 8 | -------------------------------------------------------------------------------- /2018/sample_input/day_03_sample_input: -------------------------------------------------------------------------------- 1 | #1 @ 1,3: 4x4 2 | #2 @ 3,1: 4x4 3 | #3 @ 5,5: 2x2 4 | -------------------------------------------------------------------------------- /2018/sample_input/day_04_sample_input: -------------------------------------------------------------------------------- 1 | [1518-11-01 00:00] Guard #10 begins shift 2 | [1518-11-01 00:05] falls asleep 3 | [1518-11-01 00:25] wakes up 4 | [1518-11-01 00:30] falls asleep 5 | [1518-11-01 00:55] wakes up 6 | [1518-11-01 23:58] Guard #99 begins shift 7 | [1518-11-02 00:40] falls asleep 8 | [1518-11-02 00:50] wakes up 9 | [1518-11-03 00:05] Guard #10 begins shift 10 | [1518-11-03 00:24] falls asleep 11 | [1518-11-03 00:29] wakes up 12 | [1518-11-04 00:02] Guard #99 begins shift 13 | [1518-11-04 00:36] falls asleep 14 | [1518-11-04 00:46] wakes up 15 | [1518-11-05 00:03] Guard #99 begins shift 16 | [1518-11-05 00:45] falls asleep 17 | [1518-11-05 00:55] wakes up 18 | -------------------------------------------------------------------------------- /2018/sample_input/day_05_sample_input: -------------------------------------------------------------------------------- 1 | dabAcCaCBAcCcaDA 2 | -------------------------------------------------------------------------------- /2018/sample_input/day_06_sample_input: -------------------------------------------------------------------------------- 1 | 1, 1 2 | 1, 6 3 | 8, 3 4 | 3, 4 5 | 5, 5 6 | 8, 9 7 | -------------------------------------------------------------------------------- /2018/sample_input/day_07_sample_input: -------------------------------------------------------------------------------- 1 | Step C must be finished before step A can begin. 2 | Step C must be finished before step F can begin. 3 | Step A must be finished before step B can begin. 4 | Step A must be finished before step D can begin. 5 | Step B must be finished before step E can begin. 6 | Step D must be finished before step E can begin. 7 | Step F must be finished before step E can begin. 8 | -------------------------------------------------------------------------------- /2018/sample_input/day_08_sample_input: -------------------------------------------------------------------------------- 1 | 2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2 2 | -------------------------------------------------------------------------------- /2018/sample_input/day_09_sample_input: -------------------------------------------------------------------------------- 1 | 9 players; last marble is worth 25 points: high score is 32 2 | 10 players; last marble is worth 1618 points: high score is 8317 3 | 13 players; last marble is worth 7999 points: high score is 146373 4 | 17 players; last marble is worth 1104 points: high score is 2764 5 | 21 players; last marble is worth 6111 points: high score is 54718 6 | 30 players; last marble is worth 5807 points: high score is 37305 7 | -------------------------------------------------------------------------------- /2018/sample_input/day_10_sample_input: -------------------------------------------------------------------------------- 1 | position=< 9, 1> velocity=< 0, 2> 2 | position=< 7, 0> velocity=<-1, 0> 3 | position=< 3, -2> velocity=<-1, 1> 4 | position=< 6, 10> velocity=<-2, -1> 5 | position=< 2, -4> velocity=< 2, 2> 6 | position=<-6, 10> velocity=< 2, -2> 7 | position=< 1, 8> velocity=< 1, -1> 8 | position=< 1, 7> velocity=< 1, 0> 9 | position=<-3, 11> velocity=< 1, -2> 10 | position=< 7, 6> velocity=<-1, -1> 11 | position=<-2, 3> velocity=< 1, 0> 12 | position=<-4, 3> velocity=< 2, 0> 13 | position=<10, -3> velocity=<-1, 1> 14 | position=< 5, 11> velocity=< 1, -2> 15 | position=< 4, 7> velocity=< 0, -1> 16 | position=< 8, -2> velocity=< 0, 1> 17 | position=<15, 0> velocity=<-2, 0> 18 | position=< 1, 6> velocity=< 1, 0> 19 | position=< 8, 9> velocity=< 0, -1> 20 | position=< 3, 3> velocity=<-1, 1> 21 | position=< 0, 5> velocity=< 0, -1> 22 | position=<-2, 2> velocity=< 2, 0> 23 | position=< 5, -2> velocity=< 1, 2> 24 | position=< 1, 4> velocity=< 2, 1> 25 | position=<-2, 7> velocity=< 2, -2> 26 | position=< 3, 6> velocity=<-1, -1> 27 | position=< 5, 0> velocity=< 1, 0> 28 | position=<-6, 0> velocity=< 2, 0> 29 | position=< 5, 9> velocity=< 1, -2> 30 | position=<14, 7> velocity=<-2, 0> 31 | position=<-3, 6> velocity=< 2, -1> 32 | -------------------------------------------------------------------------------- /2018/sample_input/day_11_sample_input: -------------------------------------------------------------------------------- 1 | Fuel cell at 3,5, grid serial number 8: power level 4. 2 | Fuel cell at 122,79, grid serial number 57: power level -5. 3 | Fuel cell at 217,196, grid serial number 39: power level 0. 4 | Fuel cell at 101,153, grid serial number 71: power level 4. 5 | 6 | 18 7 | 42 8 | -------------------------------------------------------------------------------- /2018/sample_input/day_12_sample_input: -------------------------------------------------------------------------------- 1 | initial state: #..#.#..##......###...### 2 | 3 | ...## => # 4 | ..#.. => # 5 | .#... => # 6 | .#.#. => # 7 | .#.## => # 8 | .##.. => # 9 | .#### => # 10 | #.#.# => # 11 | #.### => # 12 | ##.#. => # 13 | ##.## => # 14 | ###.. => # 15 | ###.# => # 16 | ####. => # 17 | -------------------------------------------------------------------------------- /2018/sample_input/day_13_sample_input: -------------------------------------------------------------------------------- 1 | /->-\ 2 | | | /----\ 3 | | /-+--+-\ | 4 | | | | | v | 5 | \-+-/ \-+--/ 6 | \------/ 7 | 8 | />-<\ 9 | | | 10 | | /<+-\ 11 | | | | v 12 | \>+/ 15 | -------------------------------------------------------------------------------- /2018/sample_input/day_14_sample_input: -------------------------------------------------------------------------------- 1 | 9 2 | 5 3 | 18 4 | 2018 5 | 6 | 51589 7 | 01245 8 | 92510 9 | 59414 10 | -------------------------------------------------------------------------------- /2018/sample_input/day_15_sample_input: -------------------------------------------------------------------------------- 1 | ####### 2 | #.G...# 3 | #...EG# 4 | #.#.#G# 5 | #..G#E# 6 | #.....# 7 | ####### 8 | 9 | ####### 10 | #G..#E# 11 | #E#E.E# 12 | #G.##.# 13 | #...#E# 14 | #...E.# 15 | ####### 16 | 17 | ####### 18 | #E..EG# 19 | #.#G.E# 20 | #E.##E# 21 | #G..#.# 22 | #..E#.# 23 | ####### 24 | 25 | ####### 26 | #E.G#.# 27 | #.#G..# 28 | #G.#.G# 29 | #G..#.# 30 | #...E.# 31 | ####### 32 | 33 | ####### 34 | #.E...# 35 | #.#..G# 36 | #.###.# 37 | #E#G#G# 38 | #...#G# 39 | ####### 40 | 41 | ######### 42 | #G......# 43 | #.E.#...# 44 | #..##..G# 45 | #...##..# 46 | #...#...# 47 | #.G...G.# 48 | #.....G.# 49 | ######### 50 | 51 | ####### 52 | #.G...# 53 | #...EG# 54 | #.#.#G# 55 | #..G#E# 56 | #.....# 57 | ####### 58 | 59 | ####### 60 | #E..EG# 61 | #.#G.E# 62 | #E.##E# 63 | #G..#.# 64 | #..E#.# 65 | ####### 66 | 67 | ####### 68 | #E.G#.# 69 | #.#G..# 70 | #G.#.G# 71 | #G..#.# 72 | #...E.# 73 | ####### 74 | 75 | ####### 76 | #.E...# 77 | #.#..G# 78 | #.###.# 79 | #E#G#G# 80 | #...#G# 81 | ####### 82 | 83 | ######### 84 | #G......# 85 | #.E.#...# 86 | #..##..G# 87 | #...##..# 88 | #...#...# 89 | #.G...G.# 90 | #.....G.# 91 | ######### 92 | -------------------------------------------------------------------------------- /2018/sample_input/day_16_sample_input: -------------------------------------------------------------------------------- 1 | Before: [3, 2, 1, 1] 2 | 9 2 1 2 3 | After: [3, 2, 2, 1] 4 | -------------------------------------------------------------------------------- /2018/sample_input/day_17_sample_input: -------------------------------------------------------------------------------- 1 | x=495, y=2..7 2 | y=7, x=495..501 3 | x=501, y=3..7 4 | x=498, y=2..4 5 | x=506, y=1..2 6 | x=498, y=10..13 7 | x=504, y=10..13 8 | y=13, x=498..504 9 | -------------------------------------------------------------------------------- /2018/sample_input/day_18_sample_input: -------------------------------------------------------------------------------- 1 | .#.#...|#. 2 | .....#|##| 3 | .|..|...#. 4 | ..|#.....# 5 | #.#|||#|#| 6 | ...#.||... 7 | .|....|... 8 | ||...#|.#| 9 | |.||||..|. 10 | ...#.|..|. 11 | -------------------------------------------------------------------------------- /2018/sample_input/day_19_sample_input: -------------------------------------------------------------------------------- 1 | #ip 0 2 | seti 5 0 1 3 | seti 6 0 2 4 | addi 0 1 0 5 | addr 1 2 3 6 | setr 1 0 0 7 | seti 8 0 4 8 | seti 9 0 5 9 | -------------------------------------------------------------------------------- /2018/sample_input/day_20_sample_input: -------------------------------------------------------------------------------- 1 | ^ENNWSWW(NEWS|)SSSEEN(WNSE|)EE(SWEN|)NNN$ 2 | ^ESSWWN(E|NNENN(EESS(WNSE|)SSS|WWWSSSSE(SW|NNNE)))$ 3 | ^WSSEESWWWNW(S|NENNEEEENN(ESSSSW(NWSW|SSEN)|WSWWN(E|WWS(E|SS))))$ 4 | -------------------------------------------------------------------------------- /2018/sample_input/day_21_sample_input: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vss2sn/advent_of_code/f94d7f5ca09e351e5f7698a2d26776307fdca229/2018/sample_input/day_21_sample_input -------------------------------------------------------------------------------- /2018/sample_input/day_22_sample_input: -------------------------------------------------------------------------------- 1 | depth: 510 2 | target: 10,10 3 | -------------------------------------------------------------------------------- /2018/sample_input/day_23_sample_input: -------------------------------------------------------------------------------- 1 | pos=<10,12,12>, r=2 2 | pos=<12,14,12>, r=2 3 | pos=<16,12,12>, r=4 4 | pos=<14,14,14>, r=6 5 | pos=<50,50,50>, r=200 6 | pos=<10,10,10>, r=5 7 | -------------------------------------------------------------------------------- /2018/sample_input/day_24_sample_input: -------------------------------------------------------------------------------- 1 | Immune System: 2 | 17 units each with 5390 hit points (weak to radiation, bludgeoning) with an attack that does 4507 fire damage at initiative 2 3 | 989 units each with 1274 hit points (immune to fire; weak to bludgeoning, slashing) with an attack that does 25 slashing damage at initiative 3 4 | 5 | Infection: 6 | 801 units each with 4706 hit points (weak to radiation) with an attack that does 116 bludgeoning damage at initiative 1 7 | 4485 units each with 2961 hit points (immune to radiation; weak to fire, cold) with an attack that does 12 slashing damage at initiative 4 8 | -------------------------------------------------------------------------------- /2018/sample_input/day_25_sample_input: -------------------------------------------------------------------------------- 1 | 0,0,0,0 2 | 3,0,0,0 3 | 0,3,0,0 4 | 0,0,3,0 5 | 0,0,0,3 6 | 0,0,0,6 7 | 9,0,0,0 8 | 12,0,0,0 9 | 10 | -1,2,2,0 11 | 0,0,2,-2 12 | 0,0,0,-2 13 | -1,2,0,0 14 | -2,-2,-2,2 15 | 3,0,2,-1 16 | -1,3,2,2 17 | -1,0,-1,0 18 | 0,2,1,-2 19 | 3,0,0,0 20 | 21 | 1,-1,0,1 22 | 2,0,-1,0 23 | 3,2,-1,0 24 | 0,0,3,1 25 | 0,0,-1,-1 26 | 2,3,-2,0 27 | -2,2,0,0 28 | 2,-2,0,-1 29 | 1,-1,0,-1 30 | 3,2,0,2 31 | 32 | 1,-1,-1,-2 33 | -2,-2,0,1 34 | 0,2,1,3 35 | -2,3,-2,1 36 | 0,2,3,-2 37 | -1,-1,1,-2 38 | 0,-2,-1,0 39 | -2,2,3,-1 40 | 1,2,2,0 41 | -1,-2,0,-2 42 | -------------------------------------------------------------------------------- /2019/cpp/day_01a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char* argv[]) { 8 | // Get input 9 | std::string input = "../input/day_01_input"; 10 | if (argc > 1) { 11 | input = argv[1]; 12 | } 13 | std::ifstream file(input); 14 | std::istream_iterator start(file), end; 15 | const std::vector masses(start, end); 16 | 17 | // Solve 18 | long long total_fuel = 0; 19 | constexpr int divisor = 3; 20 | constexpr int subtract = 2; 21 | for (const auto& mass : masses) { 22 | total_fuel += mass / divisor - subtract; 23 | } 24 | 25 | // STL variant 26 | // long long total_fuel = std::accumulate(start, end, 0, [](long long 27 | // sum_fuel, const int ele) { return sum_fuel + getRecursiveFuel(ele);} ); 28 | 29 | std::cout << total_fuel << '\n'; 30 | return total_fuel; 31 | } 32 | -------------------------------------------------------------------------------- /2019/cpp/day_01b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int getRecursiveFuel(const int mass) { 8 | constexpr int divisor = 3; 9 | constexpr int subtract = 2; 10 | constexpr int minimum_mass = divisor * subtract; 11 | if (mass < minimum_mass) { 12 | return 0; 13 | } 14 | const int fuel = mass / divisor - subtract; 15 | return fuel + getRecursiveFuel(fuel); 16 | } 17 | 18 | int main(int argc, char* argv[]) { 19 | // Get input 20 | std::string input = "../input/day_01_input"; 21 | if (argc > 1) { 22 | input = argv[1]; 23 | } 24 | std::ifstream file(input); 25 | std::istream_iterator start(file), end; 26 | const std::vector masses(start, end); 27 | 28 | // Solve 29 | long long total_fuel = 0; 30 | for (const auto& mass : masses) { 31 | total_fuel += getRecursiveFuel(mass); 32 | } 33 | std::cout << total_fuel << '\n'; 34 | return total_fuel; 35 | } 36 | -------------------------------------------------------------------------------- /2019/cpp/day_02a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char *argv[]) { 8 | // Get input 9 | std::string input = "../input/day_02_input"; 10 | if (argc > 1) { 11 | input = argv[1]; 12 | } 13 | std::ifstream file(input); 14 | std::string input_str; 15 | const std::string delimiter = ","; 16 | std::getline(file, input_str); 17 | std::size_t start = 0; 18 | std::size_t end = input_str.find(delimiter); 19 | std::vector program; 20 | while (end != std::string::npos) { 21 | program.emplace_back(std::stoi(input_str.substr(start, end - start))); 22 | start = end + delimiter.size(); 23 | end = input_str.find(delimiter, start); 24 | } 25 | program.emplace_back(std::stoi(input_str.substr(start, end - start))); 26 | 27 | // Modify input according to puzzle instructions 28 | program[1] = 12; 29 | program[2] = 2; 30 | 31 | // Solve 32 | size_t index = 0; 33 | while (program[index] != 99) { 34 | if (program[index] == 1) { 35 | program[program[index + 3]] = 36 | program[program[index + 1]] + program[program[index + 2]]; 37 | } else if (program[index] == 2) { 38 | program[program[index + 3]] = 39 | program[program[index + 1]] * program[program[index + 2]]; 40 | } else { 41 | std::cout << "Error" << '\n'; 42 | } 43 | index += 4; 44 | } 45 | std::cout << program[0] << '\n'; 46 | return program[0]; 47 | } 48 | -------------------------------------------------------------------------------- /2019/cpp/day_04a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | bool meetsConditions(int num) { 6 | int prev_val = 10; 7 | bool repeat = false; 8 | while (num > 0) { 9 | const auto val = num % 10; 10 | num = int(num / 10); 11 | if (val > prev_val) { 12 | return false; 13 | } 14 | if (prev_val == val) { 15 | repeat = true; 16 | } 17 | prev_val = val; 18 | } 19 | return repeat; 20 | } 21 | 22 | int main(int argc, char *argv[]) { 23 | // Get input 24 | std::string input = "../input/day_04_input"; 25 | if (argc > 1) { 26 | input = argv[1]; 27 | } 28 | std::ifstream file(input); 29 | std::string input_str; 30 | std::getline(file, input_str); 31 | 32 | const auto delimiter_index = input_str.find("-"); 33 | auto min_val = std::stoi(input_str.substr(0, delimiter_index)); 34 | auto max_val = std::stoi(input_str.substr( 35 | delimiter_index + 1, input_str.size() - delimiter_index - 1)); 36 | 37 | // Solve 38 | size_t count = 0; 39 | for (int num = min_val; num < max_val; ++num) { 40 | if (meetsConditions(num)) { 41 | count += 1; 42 | } 43 | } 44 | 45 | std::cout << count << '\n'; 46 | return count; 47 | } 48 | -------------------------------------------------------------------------------- /2019/cpp/day_04b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | bool meetsConditions(int num) { 6 | int prev_val = 10; 7 | bool repeat = false; 8 | int n_repeats = 0; 9 | while (num > 0) { 10 | const auto val = num % 10; 11 | num = int(num / 10); 12 | if (val > prev_val) { 13 | return false; 14 | } 15 | if (prev_val == val) { 16 | n_repeats += 1; 17 | } else { 18 | if (n_repeats == 1) { 19 | repeat = true; 20 | } 21 | n_repeats = 0; 22 | } 23 | prev_val = val; 24 | } 25 | if (n_repeats == 1) { 26 | repeat = true; 27 | } 28 | return repeat; 29 | } 30 | 31 | int main(int argc, char *argv[]) { 32 | // Get input 33 | std::string input = "../input/day_04_input"; 34 | if (argc > 1) { 35 | input = argv[1]; 36 | } 37 | std::ifstream file(input); 38 | std::string input_str; 39 | std::getline(file, input_str); 40 | const auto delimiter_index = input_str.find("-"); 41 | auto min_val = std::stoi(input_str.substr(0, delimiter_index)); 42 | auto max_val = std::stoi(input_str.substr( 43 | delimiter_index + 1, input_str.size() - delimiter_index - 1)); 44 | 45 | // Solve 46 | size_t count = 0; 47 | for (int num = min_val; num < max_val; ++num) { 48 | if (meetsConditions(num)) { 49 | count += 1; 50 | } 51 | } 52 | 53 | std::cout << count << '\n'; 54 | return count; 55 | } 56 | -------------------------------------------------------------------------------- /2019/cpp/day_08b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char* argv[]) { 8 | // Get input 9 | std::string input = "../input/day_08_input"; 10 | if (argc > 1) { 11 | input = argv[1]; 12 | } 13 | std::ifstream file(input); 14 | std::string line; 15 | std::getline(file, line); 16 | std::vector image; 17 | image.reserve(line.size()); 18 | for (const auto c : line) { 19 | image.emplace_back(c - '0'); 20 | } 21 | 22 | // Solve 23 | constexpr int n_rows = 6; 24 | constexpr int n_cols = 25; 25 | constexpr int pixels_in_layer = n_rows * n_cols; 26 | std::array final_image; 27 | size_t index = 0; 28 | size_t min_index = 0; 29 | size_t n_zeros = pixels_in_layer; 30 | 31 | std::fill(std::begin(final_image), std::end(final_image), 2); 32 | for (int i = 0; i < pixels_in_layer; i++) { 33 | auto it = std::begin(image) + i; 34 | while (it < std::end(image)) { 35 | if (*it != 2) { 36 | final_image[i] = *it; 37 | break; 38 | } 39 | it += pixels_in_layer; 40 | } 41 | } 42 | 43 | for (int i = 0; i < n_rows; i++) { 44 | for (int j = 0; j < n_cols; j++) { 45 | std::cout << final_image[i * n_cols + j] << ' '; 46 | } 47 | std::cout << '\n'; 48 | } 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /2019/cpp/day_16b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int main(int argc, char* argv[]) { 11 | // Get input 12 | std::string input = "../input/day_16_input"; 13 | if (argc > 1) { 14 | input = argv[1]; 15 | } 16 | std::ifstream file(input); 17 | std::string input_line; 18 | std::getline(file, input_line); 19 | std::cout << input_line << '\n'; 20 | std::vector signal; 21 | for (const char c : input_line) { 22 | signal.emplace_back(c - '0'); 23 | } 24 | const auto init_signal = signal; 25 | 26 | // Solve 27 | const int offset = std::stoi(input_line.substr(0, 7)); 28 | for (int i = 1; i < 10000; i++) { 29 | std::copy(std::begin(init_signal), std::end(init_signal), std::back_inserter(signal)); 30 | } 31 | const std::vector pattern{0,1,0,-1}; 32 | 33 | constexpr int n_phases = 100; 34 | for (int i = 0; i < n_phases; i++) { 35 | long long sm = std::accumulate(std::begin(signal) + offset, std::end(signal), 0, std::plus()); 36 | for (int j = offset; j < signal.size(); j++) { 37 | const auto sm_i = sm; 38 | sm -= signal[j]; 39 | signal[j] = sm_i % 10; 40 | } 41 | } 42 | 43 | long long msg = 0; 44 | for (int i = 0 ; i < 8; i++) { 45 | msg = msg * 10 + signal[offset + i]; 46 | } 47 | 48 | std::cout << msg << '\n'; 49 | return msg; 50 | } 51 | -------------------------------------------------------------------------------- /2019/cpp/day_22a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | constexpr int n_cards = 10007; 6 | constexpr int start_position = 2019; 7 | 8 | int64_t mod(const int64_t a, const int64_t b) { 9 | return (a >= 0) ? (a % b) : (b - (-a) % b); 10 | } 11 | 12 | int main(int argc, char* argv[]) { 13 | // Get input 14 | std::string input = "../input/day_22_input"; 15 | if (argc > 1) { 16 | input = argv[1]; 17 | } 18 | std::ifstream file(input); 19 | std::string input_line; 20 | 21 | int A = 1; 22 | int B = 0; 23 | while(std::getline(file, input_line)) { 24 | int a, b; 25 | if (input_line.substr(0,19) == "deal with increment") { 26 | a = std::stoi(input_line.substr(19, input_line.size() - 19)); 27 | b = 0; 28 | } else if (input_line.substr(0,19) == "deal into new stack") { 29 | a = -1; 30 | b = n_cards - 1; 31 | } else if (input_line.substr(0,3) == "cut") { 32 | auto n_cut = std::stoi(input_line.substr(3, input_line.size() - 3)); 33 | if (n_cut < 0) { 34 | n_cut += n_cards; 35 | } 36 | a = 1; 37 | b = n_cards - n_cut; 38 | } 39 | A = mod(a * A, n_cards); 40 | B = mod(a * B + b, n_cards); 41 | } 42 | 43 | int64_t current_position = start_position; 44 | // Shuffle once 45 | current_position = mod(A * current_position + B, n_cards); 46 | 47 | std::cout << current_position << '\n'; 48 | return current_position; 49 | } 50 | -------------------------------------------------------------------------------- /2019/python/day_01a.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import sys 4 | 5 | 6 | def main(): 7 | # Get input 8 | file_name = "../input/day_01_input" 9 | if len(sys.argv) > 1: 10 | file_name = sys.argv[1] 11 | file = open(file_name) 12 | input = [int(ele) for ele in file] 13 | 14 | # Solve 15 | total_fuel = 0 16 | for mass in input: 17 | total_fuel = total_fuel + int(mass / 3) - 2 18 | print(total_fuel) 19 | return total_fuel 20 | 21 | 22 | if __name__ == "__main__": 23 | main() 24 | -------------------------------------------------------------------------------- /2019/python/day_01b.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import sys 4 | 5 | 6 | def getRecursiveFuel(mass): 7 | divisor = 3 8 | subtract = 2 9 | minimum_mass = divisor * subtract 10 | if mass < minimum_mass: 11 | return 0 12 | fuel = int(mass / divisor) - subtract 13 | return fuel + getRecursiveFuel(fuel) 14 | 15 | 16 | def main(): 17 | # Get input 18 | file_name = "../input/day_01_input" 19 | if len(sys.argv) > 1: 20 | file_name = sys.argv[1] 21 | file = open(file_name) 22 | input = [int(ele) for ele in file] 23 | 24 | # Solve 25 | total_fuel = 0 26 | for mass in input: 27 | total_fuel = total_fuel + getRecursiveFuel(mass) 28 | print(total_fuel) 29 | return total_fuel 30 | 31 | 32 | if __name__ == "__main__": 33 | main() 34 | -------------------------------------------------------------------------------- /2019/python/day_02a.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import sys 4 | 5 | 6 | def main(): 7 | # Get input 8 | file_name = "../input/day_02_input" 9 | if len(sys.argv) > 1: 10 | file_name = sys.argv[1] 11 | file = open(file_name) 12 | program = list(map(int, file.readline().split(","))) 13 | 14 | # Modify program according to puzzle instructions 15 | program[1] = 12 16 | program[2] = 2 17 | 18 | # Solve 19 | index = 0 20 | while program[index] != 99: 21 | if program[index] == 1: 22 | program[program[index + 3]] = ( 23 | program[program[index + 1]] + program[program[index + 2]] 24 | ) 25 | elif program[index] == 2: 26 | program[program[index + 3]] = ( 27 | program[program[index + 1]] * program[program[index + 2]] 28 | ) 29 | index = index + 4 30 | print(program[0]) 31 | 32 | 33 | if __name__ == "__main__": 34 | main() 35 | -------------------------------------------------------------------------------- /2019/python/day_02b.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import copy 4 | import sys 5 | 6 | 7 | def main(): 8 | # Get program 9 | file_name = "../input/day_02_input" 10 | desired_output = 19690720 11 | if len(sys.argv) > 1: 12 | file_name = sys.argv[1] 13 | file = open(file_name) 14 | noun_verb_list = list(range(0, 100)) 15 | program_str = file.readline() 16 | 17 | # Solve 18 | ans = -1 19 | for noun in noun_verb_list: 20 | for verb in noun_verb_list: 21 | if noun == verb: 22 | continue 23 | program = list(map(int, program_str.split(","))) 24 | program[1] = noun 25 | program[2] = verb 26 | inst_ptr = 0 27 | while program[inst_ptr] != 99: 28 | if program[inst_ptr] == 1: 29 | program[program[inst_ptr + 3]] = ( 30 | program[program[inst_ptr + 1]] + program[program[inst_ptr + 2]] 31 | ) 32 | elif program[inst_ptr] == 2: 33 | program[program[inst_ptr + 3]] = ( 34 | program[program[inst_ptr + 1]] * program[program[inst_ptr + 2]] 35 | ) 36 | inst_ptr = inst_ptr + 4 37 | if program[0] == desired_output: 38 | ans = noun * 100 + verb 39 | print(ans) 40 | return ans 41 | return ans 42 | 43 | 44 | if __name__ == "__main__": 45 | main() 46 | -------------------------------------------------------------------------------- /2019/python/day_04a.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import sys 4 | 5 | 6 | def meetsConditions(num): 7 | prev_val = 10 8 | repeat = False 9 | while num > 0: 10 | val = num % 10 11 | num = int(num / 10) 12 | if val > prev_val: 13 | return False 14 | if prev_val == val: 15 | repeat = True 16 | prev_val = val 17 | return repeat 18 | 19 | 20 | def main(): 21 | # Get input 22 | file_name = "../input/day_04_input" 23 | if len(sys.argv) > 1: 24 | file_name = sys.argv[1] 25 | file = open(file_name) 26 | val_range = [int(ele) for ele in file.readline().strip("\n").split("-")] 27 | 28 | # Solve 29 | count = 0 30 | for num in range(val_range[0], val_range[1] + 1): 31 | if meetsConditions(num): 32 | count += 1 33 | print(count) 34 | return count 35 | 36 | 37 | if __name__ == "__main__": 38 | main() 39 | -------------------------------------------------------------------------------- /2019/python/day_04b.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import sys 4 | 5 | 6 | def meetsConditions(num): 7 | prev_val = 10 8 | n_repeat = 0 9 | repeat = False 10 | while num > 0: 11 | val = num % 10 12 | num = int(num / 10) 13 | if val > prev_val: 14 | return False 15 | if prev_val == val: 16 | n_repeat = n_repeat + 1 17 | else: 18 | if n_repeat == 1: 19 | repeat = True 20 | n_repeat = 0 21 | prev_val = val 22 | if n_repeat == 1: 23 | repeat = True 24 | return repeat 25 | 26 | 27 | if __name__ == "__main__": 28 | # Get input 29 | file_name = "../input/day_04_input" 30 | if len(sys.argv) > 1: 31 | file_name = sys.argv[1] 32 | file = open(file_name) 33 | val_range = [int(ele) for ele in file.readline().strip("\n").split("-")] 34 | 35 | # Solve 36 | count = 0 37 | for num in range(val_range[0], val_range[1] + 1): 38 | if meetsConditions(num): 39 | count += 1 40 | print(count) 41 | -------------------------------------------------------------------------------- /2019/python/day_06a.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import sys 4 | 5 | 6 | def recursiveOrbitCount(current_object, is_orbitted_by, n_orbits): 7 | if current_object not in is_orbitted_by.keys(): 8 | n_orbits[current_object] = 0 9 | else: 10 | n_orbits[current_object] = 0 11 | for orbitting_object in is_orbitted_by[current_object]: 12 | recursiveOrbitCount(orbitting_object, is_orbitted_by, n_orbits) 13 | n_orbits[current_object] += n_orbits[orbitting_object] + 1 14 | 15 | 16 | def main(): 17 | # Get input 18 | file_name = "../input/day_06_input" 19 | if len(sys.argv) > 1: 20 | file_name = sys.argv[1] 21 | file = open(file_name) 22 | orbits = dict() 23 | is_orbitted_by = dict() 24 | n_orbits = dict() 25 | input = list() 26 | for line in file: 27 | line = line.strip("\n") 28 | input.append(line) 29 | 30 | # Solve 31 | for line in input: 32 | orbit = line.split(")") 33 | orbits[orbit[1]] = orbit[0] 34 | if orbit[0] not in is_orbitted_by.keys(): 35 | is_orbitted_by[orbit[0]] = set() 36 | is_orbitted_by[orbit[0]].add(orbit[1]) 37 | recursiveOrbitCount("COM", is_orbitted_by, n_orbits) 38 | total = 0 39 | for n in n_orbits.values(): 40 | total += n 41 | print(total) 42 | return total 43 | 44 | 45 | if __name__ == "__main__": 46 | main() 47 | -------------------------------------------------------------------------------- /2019/sample_input/day_01_sample_input: -------------------------------------------------------------------------------- 1 | 12 2 | 14 3 | 1969 4 | 100756 5 | -------------------------------------------------------------------------------- /2019/sample_input/day_02_sample_input: -------------------------------------------------------------------------------- 1 | 1,9,10,3,2,3,11,0,99,30,40,50 2 | 1,0,0,0,99 3 | 2,3,0,3,99 4 | 2,4,4,5,99,0 5 | 1,1,1,4,99,5,6,0,99 6 | -------------------------------------------------------------------------------- /2019/sample_input/day_03_sample_input: -------------------------------------------------------------------------------- 1 | R8,U5,L5,D3 2 | U7,R6,D4,L4 3 | 4 | R75,D30,R83,U83,L12,D49,R71,U7,L72 5 | U62,R66,U55,R34,D71,R55,D58,R83 6 | 7 | R98,U47,R26,D63,R33,U87,L62,D20,R33,U53,R51 8 | U98,R91,D20,R16,D67,R40,U7,R15,U6,R7 9 | 10 | R75,D30,R83,U83,L12,D49,R71,U7,L72 11 | U62,R66,U55,R34,D71,R55,D58,R83 12 | 13 | R98,U47,R26,D63,R33,U87,L62,D20,R33,U53,R51 14 | U98,R91,D20,R16,D67,R40,U7,R15,U6,R7 15 | -------------------------------------------------------------------------------- /2019/sample_input/day_04_sample_input: -------------------------------------------------------------------------------- 1 | 111111 2 | 223450 3 | 123789 4 | 112233 5 | 123444 6 | 111122 7 | -------------------------------------------------------------------------------- /2019/sample_input/day_05_sample_input: -------------------------------------------------------------------------------- 1 | 1002,4,3,4,33 2 | 3,9,8,9,10,9,4,9,99,-1,8 3 | 3,9,7,9,10,9,4,9,99,-1,8 4 | 3,3,1108,-1,8,3,4,3,99 5 | 3,3,1107,-1,8,3,4,3,99 6 | 3,12,6,12,15,1,13,14,13,4,13,99,-1,0,1,9 7 | 3,3,1105,-1,9,1101,0,0,12,4,12,99,1 8 | 3,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31,1106,0,36,98,0,0,1002,21,125,20,4,20,1105,1,46,104,999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99 9 | -------------------------------------------------------------------------------- /2019/sample_input/day_06_sample_input: -------------------------------------------------------------------------------- 1 | COM)B 2 | B)C 3 | C)D 4 | D)E 5 | E)F 6 | B)G 7 | G)H 8 | D)I 9 | E)J 10 | J)K 11 | K)L 12 | 13 | COM)B 14 | B)C 15 | C)D 16 | D)E 17 | E)F 18 | B)G 19 | G)H 20 | D)I 21 | E)J 22 | J)K 23 | K)L 24 | K)YOU 25 | I)SAN 26 | -------------------------------------------------------------------------------- /2019/sample_input/day_07_sample_input: -------------------------------------------------------------------------------- 1 | 3,15,3,16,1002,16,10,16,1,16,15,15,4,15,99,0,0 2 | 3,23,3,24,1002,24,10,24,1002,23,-1,23,101,5,23,23,1,24,23,23,4,23,99,0,0 3 | 3,31,3,32,1002,32,10,32,1001,31,-2,31,1007,31,0,33,1002,33,7,33,1,33,31,31,1,32,31,31,4,31,99,0,0,0 4 | 5 | 3,26,1001,26,-4,26,3,27,1002,27,2,27,1,27,26,27,4,27,1001,28,-1,28,1005,28,6,99,0,0,5 6 | 3,52,1001,52,-5,52,3,53,1,52,56,54,1007,54,5,55,1005,55,26,1001,54,-5,54,1105,1,12,1,53,54,53,1008,54,0,55,1001,55,1,55,2,53,55,53,4,53,1001,56,-1,56,1005,56,6,99,0,0,0,0,10 7 | -------------------------------------------------------------------------------- /2019/sample_input/day_08_sample_input: -------------------------------------------------------------------------------- 1 | 123456789012 2 | 3 | 0222112222120000 4 | -------------------------------------------------------------------------------- /2019/sample_input/day_09_sample_input: -------------------------------------------------------------------------------- 1 | 109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99 2 | 1102,34915192,34915192,7,4,7,99,0 3 | 104,1125899906842624,99 4 | -------------------------------------------------------------------------------- /2019/sample_input/day_10_sample_input: -------------------------------------------------------------------------------- 1 | .#..##.###...####### 2 | ##.############..##. 3 | .#.######.########.# 4 | .###.#######.####.#. 5 | #####.##.#.##.###.## 6 | ..#####..#.######### 7 | #################### 8 | #.####....###.#.#.## 9 | ##.################# 10 | #####.##.###..####.. 11 | ..######..##.####### 12 | ####.##.####...##..# 13 | .#####..#.######.### 14 | ##...#.##########... 15 | #.##########.####### 16 | .####.#.###.###.#.## 17 | ....##.##.###..##### 18 | .#.#.###########.### 19 | #.#.#.#####.####.### 20 | ###.##.####.##.#..## 21 | -------------------------------------------------------------------------------- /2019/sample_input/day_11_sample_input: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vss2sn/advent_of_code/f94d7f5ca09e351e5f7698a2d26776307fdca229/2019/sample_input/day_11_sample_input -------------------------------------------------------------------------------- /2019/sample_input/day_12_sample_input: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /2019/sample_input/day_13_sample_input: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vss2sn/advent_of_code/f94d7f5ca09e351e5f7698a2d26776307fdca229/2019/sample_input/day_13_sample_input -------------------------------------------------------------------------------- /2019/sample_input/day_14_sample_input: -------------------------------------------------------------------------------- 1 | 171 ORE => 8 CNZTR 2 | 7 ZLQW, 3 BMBT, 9 XCVML, 26 XMNCP, 1 WPTQ, 2 MZWV, 1 RJRHP => 4 PLWSL 3 | 114 ORE => 4 BHXH 4 | 14 VRPVC => 6 BMBT 5 | 6 BHXH, 18 KTJDG, 12 WPTQ, 7 PLWSL, 31 FHTLT, 37 ZDVW => 1 FUEL 6 | 6 WPTQ, 2 BMBT, 8 ZLQW, 18 KTJDG, 1 XMNCP, 6 MZWV, 1 RJRHP => 6 FHTLT 7 | 15 XDBXC, 2 LTCX, 1 VRPVC => 6 ZLQW 8 | 13 WPTQ, 10 LTCX, 3 RJRHP, 14 XMNCP, 2 MZWV, 1 ZLQW => 1 ZDVW 9 | 5 BMBT => 4 WPTQ 10 | 189 ORE => 9 KTJDG 11 | 1 MZWV, 17 XDBXC, 3 XCVML => 2 XMNCP 12 | 12 VRPVC, 27 CNZTR => 2 XDBXC 13 | 15 KTJDG, 12 BHXH => 5 XCVML 14 | 3 BHXH, 2 VRPVC => 7 MZWV 15 | 121 ORE => 7 VRPVC 16 | 7 XCVML => 6 RJRHP 17 | 5 BHXH, 4 VRPVC => 5 LTCX 18 | -------------------------------------------------------------------------------- /2019/sample_input/day_15_sample_input: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vss2sn/advent_of_code/f94d7f5ca09e351e5f7698a2d26776307fdca229/2019/sample_input/day_15_sample_input -------------------------------------------------------------------------------- /2019/sample_input/day_16_sample_input: -------------------------------------------------------------------------------- 1 | 03036732577212944063491565474664 2 | -------------------------------------------------------------------------------- /2019/sample_input/day_17_sample_input: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vss2sn/advent_of_code/f94d7f5ca09e351e5f7698a2d26776307fdca229/2019/sample_input/day_17_sample_input -------------------------------------------------------------------------------- /2019/sample_input/day_18_sample_input: -------------------------------------------------------------------------------- 1 | ############# 2 | #g#f.D#..h#l# 3 | #F###e#E###.# 4 | #dCba...BcIJ# 5 | ######@###### 6 | #nK.L...G...# 7 | #M###N#H###.# 8 | #o#m..#i#jk.# 9 | ############# 10 | -------------------------------------------------------------------------------- /2019/sample_input/day_19_sample_input: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vss2sn/advent_of_code/f94d7f5ca09e351e5f7698a2d26776307fdca229/2019/sample_input/day_19_sample_input -------------------------------------------------------------------------------- /2019/sample_input/day_21_sample_input: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vss2sn/advent_of_code/f94d7f5ca09e351e5f7698a2d26776307fdca229/2019/sample_input/day_21_sample_input -------------------------------------------------------------------------------- /2019/sample_input/day_22_sample_input: -------------------------------------------------------------------------------- 1 | deal with increment 7 2 | deal into new stack 3 | deal into new stack 4 | cut 6 5 | deal with increment 7 6 | deal into new stack 7 | deal with increment 7 8 | deal with increment 9 9 | cut -2 10 | deal into new stack 11 | cut -2 12 | deal with increment 7 13 | cut 8 14 | cut -4 15 | deal with increment 7 16 | cut 3 17 | deal with increment 9 18 | deal with increment 3 19 | cut -1 20 | -------------------------------------------------------------------------------- /2019/sample_input/day_23_sample_input: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vss2sn/advent_of_code/f94d7f5ca09e351e5f7698a2d26776307fdca229/2019/sample_input/day_23_sample_input -------------------------------------------------------------------------------- /2019/sample_input/day_24_sample_input: -------------------------------------------------------------------------------- 1 | ....# 2 | #..#. 3 | #..## 4 | ..#.. 5 | #.... 6 | -------------------------------------------------------------------------------- /2019/sample_input/day_25_sample_input: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vss2sn/advent_of_code/f94d7f5ca09e351e5f7698a2d26776307fdca229/2019/sample_input/day_25_sample_input -------------------------------------------------------------------------------- /2020/cpp/day_01a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | constexpr int total = 2020; 7 | std::ifstream file; 8 | file.open("../input/day_01_input"); 9 | std::unordered_set entries; 10 | int num = 0; 11 | while (file >> num) { 12 | const int delta = 2020 - num; 13 | if (entries.find(delta) != entries.end()) { 14 | std::cout << delta * num << '\n'; 15 | return delta * num; 16 | } else { 17 | entries.insert(num); 18 | } 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /2020/cpp/day_01b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main() { 8 | constexpr int total = 2020; 9 | std::ifstream file; 10 | file.open("../input/day_01_input"); 11 | int num = 0; 12 | 13 | std::vector entries_v{std::istream_iterator{file}, 14 | {}}; // Ref: C++'s most vexing parse :D 15 | std::sort(std::begin(entries_v), std::end(entries_v)); 16 | 17 | const size_t size = entries_v.size(); 18 | for (size_t start = 0; start < size - 2; ++start) { 19 | size_t mid = start + 1; 20 | size_t end = size - 1; 21 | while (mid < end) { 22 | const int rem = 23 | total - entries_v[start] - entries_v[mid] - entries_v[end]; 24 | if (rem == 0) { 25 | std::cout << entries_v[start] * entries_v[mid] * entries_v[end] << '\n'; 26 | return entries_v[start] * entries_v[mid] * entries_v[end]; 27 | } else if (rem > 0) { 28 | ++mid; 29 | } else { 30 | --end; 31 | } 32 | } 33 | } 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /2020/cpp/day_02a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | std::ifstream file; 8 | file.open("../input/day_02_input"); 9 | std::unordered_set entries; 10 | char dash, letter, colon; 11 | std::string pwd; 12 | int low, high; 13 | int count = 0; 14 | while (file >> low >> dash >> high >> letter >> colon >> pwd) { 15 | const int reps = 16 | std::count_if(std::begin(pwd), std::end(pwd), 17 | [=](const auto ele) { return ele == letter; }); 18 | if (low <= reps && reps <= high) { 19 | ++count; 20 | } 21 | } 22 | std::cout << count << '\n'; 23 | return count; 24 | } 25 | -------------------------------------------------------------------------------- /2020/cpp/day_02b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | std::ifstream file; 8 | file.open("../input/day_02_input"); 9 | std::unordered_set entries; 10 | char dash, letter, colon; 11 | std::string pwd; 12 | int i1, i2; 13 | int count = 0; 14 | while (file >> i1 >> dash >> i2 >> letter >> colon >> pwd) { 15 | const bool valid = (pwd[i1 - 1] == letter) ^ (pwd[i2 - 1] == letter); 16 | if (valid) { 17 | ++count; 18 | } 19 | } 20 | std::cout << count << '\n'; 21 | return count; 22 | } 23 | -------------------------------------------------------------------------------- /2020/cpp/day_03a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | std::ifstream file; 7 | file.open("../input/day_03_input"); 8 | std::string row; 9 | std::vector map; 10 | while (file >> row) { 11 | map.push_back(row); 12 | } 13 | 14 | const int n_rows = map.size(); 15 | if (n_rows == 0) return 0; 16 | const int n_cols = map[0].size(); 17 | const int inc_x = 3, inc_y = 1; 18 | int position_x = 0, position_y = 0; 19 | int n_tree = 0; 20 | 21 | while (position_y < n_rows) { 22 | if (map[position_y][position_x] == '#') { 23 | ++n_tree; 24 | } 25 | position_x += inc_x; 26 | position_x %= n_cols; 27 | position_y += inc_y; 28 | } 29 | std::cout << n_tree << '\n'; 30 | return n_tree; 31 | } 32 | -------------------------------------------------------------------------------- /2020/cpp/day_03b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | std::ifstream file; 7 | file.open("../input/day_03_input"); 8 | std::string row; 9 | std::vector map; 10 | std::vector slopes = {{1, 1}, {3, 1}, {5, 1}, {7, 1}, {1, 2}}; 11 | while (file >> row) { 12 | map.push_back(row); 13 | } 14 | const int n_rows = map.size(); 15 | if (n_rows == 0) return 0; 16 | 17 | const int n_cols = map[0].size(); 18 | long long product = 1; 19 | 20 | for (const auto& slope : slopes) { 21 | const int inc_x = slope[0], inc_y = slope[1]; 22 | if (slope[0] > n_cols || slope[1] > n_rows) continue; 23 | int position_x = 0, position_y = 0; 24 | int n_tree = 0; 25 | while (position_y < n_rows) { 26 | if (map[position_y][position_x] == '#') { 27 | ++n_tree; 28 | } 29 | position_x += inc_x; 30 | position_x %= n_cols; 31 | position_y += inc_y; 32 | } 33 | product *= n_tree; 34 | } 35 | std::cout << product << '\n'; 36 | return product; 37 | } 38 | -------------------------------------------------------------------------------- /2020/cpp/day_04a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main() { 8 | std::ifstream file; 9 | file.open("../input/day_04_input"); 10 | std::string text; 11 | int count = 0; 12 | int fields = 0; 13 | std::unordered_set key_fields{"byr", "iyr", "eyr", "hgt", 14 | "hcl", "ecl", "pid"}; 15 | while (std::getline(file, text)) { 16 | text.erase(std::remove_if(std::begin(text), std::end(text), 17 | [](char c) { return !std::isprint(c); }), 18 | std::end(text)); 19 | if (text.empty()) { 20 | if (fields == 7) { 21 | ++count; 22 | } 23 | fields = 0; 24 | continue; 25 | } 26 | const std::string delimiter = " :"; 27 | size_t start = 0; 28 | size_t end = text.find_first_of(delimiter); 29 | while (end != std::string::npos) { 30 | const std::string substr = text.substr(start, end - start); 31 | if (key_fields.find(substr) != key_fields.end()) { 32 | ++fields; 33 | } 34 | start = end + 1; 35 | end = text.find_first_of(delimiter, start); 36 | } 37 | } 38 | if (fields == 7) { 39 | ++count; 40 | } 41 | std::cout << count << '\n'; 42 | return count; 43 | } 44 | -------------------------------------------------------------------------------- /2020/cpp/day_06a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main() { 8 | std::ifstream file; 9 | file.open("../input/day_06_input"); 10 | 11 | int count = 0; 12 | std::string line; 13 | std::unordered_set group_ans; 14 | 15 | while (std::getline(file, line)) { 16 | line.erase(std::remove_if(std::begin(line), std::end(line), 17 | [](auto c) { return !isprint(c); }), 18 | std::end(line)); 19 | if (line.empty()) { 20 | count += group_ans.size(); 21 | group_ans.clear(); 22 | } else { 23 | for (const char c : line) { 24 | group_ans.insert(c); 25 | } 26 | } 27 | } 28 | count += group_ans.size(); 29 | group_ans.clear(); 30 | 31 | std::cout << count << '\n'; 32 | return count; 33 | } 34 | -------------------------------------------------------------------------------- /2020/cpp/day_06b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main() { 8 | std::ifstream file; 9 | file.open("../input/day_06_input"); 10 | 11 | const std::string full_string = "abcdefghijklmnopqrstuvwxyz"; 12 | int count = 0; 13 | std::string line; 14 | std::string intersection = full_string; 15 | while (std::getline(file, line)) { 16 | line.erase(std::remove_if(std::begin(line), std::end(line), 17 | [](auto c) { return !isprint(c); }), 18 | std::end(line)); 19 | if (line.empty()) { 20 | count += intersection.size(); 21 | intersection = full_string; 22 | } else { 23 | std::sort(std::begin(line), std::end(line)); 24 | std::string temp_intersection = ""; 25 | std::set_intersection(std::begin(line), std::end(line), 26 | std::begin(intersection), std::end(intersection), 27 | std::back_inserter(temp_intersection)); 28 | intersection = temp_intersection; 29 | } 30 | } 31 | count += intersection.size(); 32 | 33 | std::cout << count << '\n'; 34 | return count; 35 | } 36 | -------------------------------------------------------------------------------- /2020/cpp/day_08a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main() { 9 | std::ifstream file{"../input/day_08_input"}; 10 | std::vector code_lines; 11 | std::string line; 12 | while (std::getline(file, line)) { 13 | code_lines.emplace_back(line); 14 | } 15 | std::vector executed(code_lines.size(), false); 16 | 17 | int line_n = 0; 18 | int acc = 0; 19 | while (true) { 20 | if (executed[line_n]) break; 21 | const std::string_view inst = code_lines[line_n].substr(0, 3); 22 | executed[line_n] = true; 23 | if (inst == "nop") { 24 | ++line_n; 25 | } else if (inst == "acc") { 26 | acc += stoi(code_lines[line_n].substr(4, code_lines[line_n].size() - 4)); 27 | ++line_n; 28 | } else if (inst == "jmp") { 29 | line_n += 30 | stoi(code_lines[line_n].substr(4, code_lines[line_n].size() - 4)); 31 | } 32 | } 33 | 34 | std::cout << acc << '\n'; 35 | return acc; 36 | } 37 | -------------------------------------------------------------------------------- /2020/cpp/day_09a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | constexpr int n_preamble = 25; 8 | 9 | int main() { 10 | std::ifstream file{"../input/day_09_input"}; 11 | int number; 12 | std::vector preamble_v; 13 | std::queue preamble_q; 14 | preamble_v.reserve(n_preamble); 15 | 16 | // Create preamble 17 | while (n_preamble > preamble_v.size() && file >> number) { 18 | preamble_v.push_back(number); 19 | preamble_q.push(number); 20 | } 21 | 22 | while (file >> number) { 23 | int begin = 0; 24 | int end = preamble_v.size() - 1; 25 | std::sort(std::begin(preamble_v), std::end(preamble_v)); 26 | bool found = false; 27 | while (begin < end) { 28 | const int sum = preamble_v[begin] + preamble_v[end]; 29 | if (sum == number && preamble_v[begin] != preamble_v[end]) { 30 | const auto element_to_remove = preamble_q.front(); 31 | preamble_q.pop(); 32 | preamble_q.push(number); 33 | *std::find(std::begin(preamble_v), std::end(preamble_v), 34 | element_to_remove) = number; 35 | found = true; 36 | break; 37 | } else if (sum > number) { 38 | end--; 39 | } else if (sum < number) { 40 | begin++; 41 | } 42 | } 43 | if (!found) { 44 | std::cout << number << '\n'; 45 | return number; 46 | } 47 | } 48 | return -1; 49 | } 50 | -------------------------------------------------------------------------------- /2020/cpp/day_10a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | std::ifstream file{"../input/day_10_input"}; 8 | std::vector adapter_joltages; 9 | int adapter_joltage; 10 | while (file >> adapter_joltage) { 11 | adapter_joltages.push_back(adapter_joltage); 12 | } 13 | std::sort(std::begin(adapter_joltages), std::end(adapter_joltages)); 14 | 15 | int n_del_1 = 0; 16 | int n_del_2 = 0; 17 | int n_del_3 = 0; 18 | for (int i = 0; i < adapter_joltages.size() - 1; ++i) { 19 | const int del = adapter_joltages[i + 1] - adapter_joltages[i]; 20 | if (del == 1) { 21 | ++n_del_1; 22 | } else if (del == 2) { 23 | ++n_del_2; 24 | } else if (del == 3) { 25 | ++n_del_3; 26 | } 27 | } 28 | 29 | // Difference between lowest adapter and port 30 | if (adapter_joltages[0] == 1) { 31 | ++n_del_1; 32 | } else if (adapter_joltages[0] == 2) { 33 | ++n_del_2; 34 | } else if (adapter_joltages[0] == 3) { 35 | ++n_del_3; 36 | } 37 | 38 | // Difference between last adapter and device 39 | ++n_del_3; 40 | std::cout << n_del_1 * n_del_3 << '\n'; 41 | return n_del_1 * n_del_3; 42 | } 43 | -------------------------------------------------------------------------------- /2020/cpp/day_12a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | std::ifstream file{"../input/day_12_input"}; 7 | std::string com_inst; 8 | int dir = 0; 9 | int pos_x = 0; 10 | int pos_y = 0; 11 | while (std::getline(file, com_inst)) { 12 | char inst = com_inst[0]; 13 | const int mag = std::stoi(com_inst.substr(1, com_inst.size() - 1)); 14 | if (inst == 'F') { 15 | if (dir == 0) 16 | inst = 'E'; 17 | else if (dir == 1) 18 | inst = 'N'; 19 | else if (dir == 2) 20 | inst = 'W'; 21 | else if (dir == 3) 22 | inst = 'S'; 23 | else { 24 | std::cout << dir << " This should not happen" << '\n'; 25 | } 26 | } 27 | 28 | if (inst == 'N') { 29 | pos_y += mag; 30 | } else if (inst == 'S') { 31 | pos_y -= mag; 32 | } else if (inst == 'E') { 33 | pos_x += mag; 34 | } else if (inst == 'W') { 35 | pos_x -= mag; 36 | } else if (inst == 'L') { 37 | dir += mag / 90; 38 | dir %= 4; 39 | } else if (inst == 'R') { 40 | dir -= mag / 90; 41 | dir += 4; 42 | dir %= 4; 43 | } else { 44 | std::cout << "This should also not happen" << '\n'; 45 | } 46 | } 47 | std::cout << std::abs(pos_x) + std::abs(pos_y) << '\n'; 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /2020/cpp/day_13a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | std::ifstream file{"../input/day_13_input"}; 8 | 9 | int arrive_abs; // attive at bus stop 10 | file >> arrive_abs; 11 | 12 | std::string all_bus_f; // all buses frequencies 13 | file >> all_bus_f; 14 | 15 | int earliest_bus; // To be found 16 | int extra_time = arrive_abs; // Ensures > arrive_abs % all_bus_f 17 | int begin = 0; 18 | int end = all_bus_f.find(",", begin); 19 | while (end != std::string::npos) { 20 | const std::string bus_f = all_bus_f.substr(begin, end - begin); 21 | if (bus_f.find_first_not_of("1234567890") == std::string::npos) { 22 | const int temp = std::abs((arrive_abs % stoi(bus_f)) - stoi(bus_f)); 23 | if (temp < extra_time) { 24 | extra_time = temp; 25 | earliest_bus = stoi(bus_f); 26 | } 27 | } 28 | begin = end + 1; 29 | end = all_bus_f.find(",", begin); 30 | } 31 | const std::string bus_f = all_bus_f.substr(begin, end - begin); 32 | if (bus_f.find_first_not_of("1234567890") == std::string::npos) { 33 | const int temp = std::abs((arrive_abs % stoi(bus_f)) - stoi(bus_f)); 34 | if (temp < extra_time) { 35 | extra_time = temp; 36 | earliest_bus = stoi(bus_f); 37 | } 38 | } 39 | std::cout << earliest_bus * extra_time << '\n'; 40 | return earliest_bus * extra_time; 41 | } 42 | -------------------------------------------------------------------------------- /2020/cpp/day_15a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | std::fstream file{"../input/day_15_input"}; 7 | std::string line; 8 | std::getline(file, line); 9 | const std::string delimiter = ","; 10 | size_t start = 0; 11 | std::size_t end = line.find(delimiter); 12 | std::unordered_map spoken_numbers; 13 | while (end != std::string::npos) { 14 | spoken_numbers.insert( 15 | {std::stoi(line.substr(start, end - start)), spoken_numbers.size()}); 16 | start = end + delimiter.size(); 17 | end = line.find(delimiter, start); 18 | } 19 | // spoken_numbers.insert({std::stoi(line.substr(start, end - start)), 20 | // spoken_numbers.size()}); std::cout << std::stoi(line.substr(start, end - 21 | // start)) << '\n'; 22 | long long new_number = std::stoi(line.substr(start, end - start)); 23 | size_t count = spoken_numbers.size(); 24 | while (count < 2019) { 25 | if (auto it = spoken_numbers.find(new_number); it != spoken_numbers.end()) { 26 | new_number = count - spoken_numbers[new_number]; 27 | it->second = count; 28 | } else { 29 | spoken_numbers.insert({new_number, count}); 30 | new_number = 0; 31 | } 32 | count++; 33 | } 34 | std::cout << new_number << '\n'; 35 | return new_number; 36 | } 37 | -------------------------------------------------------------------------------- /2020/cpp/day_15b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | std::fstream file{"../input/day_15_input"}; 7 | std::string line; 8 | std::getline(file, line); 9 | const std::string delimiter = ","; 10 | size_t start = 0; 11 | std::size_t end = line.find(delimiter); 12 | std::unordered_map spoken_numbers; 13 | while (end != std::string::npos) { 14 | spoken_numbers.insert( 15 | {std::stoi(line.substr(start, end - start)), spoken_numbers.size()}); 16 | start = end + delimiter.size(); 17 | end = line.find(delimiter, start); 18 | } 19 | // spoken_numbers.insert({std::stoi(line.substr(start, end - start)), 20 | // spoken_numbers.size()}); std::cout << std::stoi(line.substr(start, end - 21 | // start)) << '\n'; 22 | long long new_number = std::stoi(line.substr(start, end - start)); 23 | size_t count = spoken_numbers.size(); 24 | while (count < 29999999) { 25 | if (auto it = spoken_numbers.find(new_number); it != spoken_numbers.end()) { 26 | new_number = count - spoken_numbers[new_number]; 27 | it->second = count; 28 | } else { 29 | spoken_numbers.insert({new_number, count}); 30 | new_number = 0; 31 | } 32 | count++; 33 | } 34 | std::cout << new_number << '\n'; 35 | return new_number; 36 | } 37 | -------------------------------------------------------------------------------- /2020/python/day_01a.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | 4 | def main(): 5 | total = 2020 6 | f = open("../input/day_01_input") 7 | numbers = set() 8 | for line in f: 9 | line = line.strip().replace("\n", "").replace("\r", "") 10 | num = int(line) 11 | diff = total - num 12 | if diff in numbers: 13 | print(diff * num) 14 | return diff * num 15 | else: 16 | numbers.add(num) 17 | return 0 18 | 19 | 20 | if __name__ == "__main__": 21 | main() 22 | -------------------------------------------------------------------------------- /2020/python/day_01b.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | 4 | def main(): 5 | total = 2020 6 | f = open("../input/day_01_input") 7 | numbers = list() 8 | for line in f: 9 | line = line.strip().replace("\n", "").replace("\r", "") 10 | numbers.append(int(line)) 11 | numbers.sort() 12 | for start in range(0, len(numbers)): 13 | mid = start + 1 14 | end = len(numbers) - 1 15 | while mid < end: 16 | rem = total - numbers[start] - numbers[mid] - numbers[end] 17 | if rem == 0: 18 | print(numbers[start] * numbers[mid] * numbers[end]) 19 | return numbers[start] * numbers[mid] * numbers[end] 20 | elif rem > 0: 21 | mid += 1 22 | elif rem < 0: 23 | end -= 1 24 | else: 25 | print("WTH") 26 | return 0 27 | 28 | 29 | if __name__ == "__main__": 30 | main() 31 | -------------------------------------------------------------------------------- /2020/python/day_02a.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import re 4 | 5 | 6 | def main(): 7 | f = open("../input/day_02_input") 8 | match_pattern = re.compile(r"(\d+)-(\d+) ([a-z]): (.*)\n") 9 | count = 0 10 | for line in f: 11 | low, high, letter, pwd = re.match(match_pattern, line).groups() 12 | n = pwd.count(letter) 13 | if n >= int(low) and n <= int(high): 14 | count += 1 15 | print(count) 16 | return count 17 | 18 | 19 | if __name__ == "__main__": 20 | main() 21 | -------------------------------------------------------------------------------- /2020/python/day_02b.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import re 4 | 5 | 6 | def main(): 7 | f = open("../input/day_02_input") 8 | pattern = re.compile(r"(\d+)-(\d+) ([a-z]): (.*)\n") 9 | count = 0 10 | for line in f: 11 | low, high, letter, pwd = re.match(pattern, line).groups() 12 | if (pwd[int(low) - 1] == letter) ^ (pwd[int(high) - 1] == letter): 13 | count += 1 14 | print(count) 15 | return count 16 | 17 | 18 | if __name__ == "__main__": 19 | main() 20 | -------------------------------------------------------------------------------- /2020/python/day_03a.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | def countTreesInPath(forest, step_x, step_y): 3 | tree = "#" 4 | n_rows = len(forest) 5 | x = 0 6 | y = 0 7 | count = 0 8 | n_cols = len(forest[0]) 9 | while y < n_rows: 10 | if forest[y][x] == "#": 11 | count += 1 12 | x += step_x 13 | x %= n_cols 14 | y += step_y 15 | return count 16 | 17 | 18 | def main(): 19 | f = open("../input/day_03_input") 20 | forest = [line.strip() for line in f.readlines()] 21 | print(countTreesInPath(forest, 3, 1)) 22 | 23 | 24 | if __name__ == "__main__": 25 | main() 26 | -------------------------------------------------------------------------------- /2020/python/day_03b.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | def countTreesInPath(forest, step_x, step_y): 3 | tree = "#" 4 | n_rows = len(forest) 5 | x = 0 6 | y = 0 7 | count = 0 8 | n_cols = len(forest[0]) 9 | while y < n_rows: 10 | if forest[y][x] == "#": 11 | count += 1 12 | x += step_x 13 | x %= n_cols 14 | y += step_y 15 | return count 16 | 17 | 18 | def main(): 19 | f = open("../input/day_03_input") 20 | forest = [line.strip() for line in f.readlines()] 21 | print( 22 | countTreesInPath(forest, 1, 1) 23 | * countTreesInPath(forest, 3, 1) 24 | * countTreesInPath(forest, 5, 1) 25 | * countTreesInPath(forest, 7, 1) 26 | * countTreesInPath(forest, 1, 2) 27 | ) 28 | 29 | 30 | if __name__ == "__main__": 31 | main() 32 | -------------------------------------------------------------------------------- /2020/python/day_04a.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | 4 | def main(): 5 | f = open("../input/day_04_input") 6 | key_fields = {"byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid"} 7 | n_valid = 0 8 | n_fields = 0 9 | n_lines = 0 10 | for line in f: 11 | line = line.strip().replace("\n", "").replace("\r", "") 12 | if len(line) == 0: 13 | if n_fields == len(key_fields): 14 | n_valid += 1 15 | n_fields = 0 16 | continue 17 | fields = line.split() 18 | for field in fields: 19 | split_field = field.split(":") 20 | if split_field[0].strip() in key_fields: 21 | n_fields += 1 22 | if n_fields == len(key_fields): 23 | n_valid += 1 24 | print(n_valid) 25 | return n_valid 26 | 27 | 28 | if __name__ == "__main__": 29 | main() 30 | -------------------------------------------------------------------------------- /2020/python/day_05a.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | 4 | def main(): 5 | f = open("../input/day_05_input") 6 | max_seat_id = 0 7 | for line in f: 8 | min_row = 0 9 | max_row = 128 10 | min_col = 0 11 | max_col = 8 12 | for letter in line[0:7]: 13 | if letter == "F": 14 | max_row = (max_row + min_row) / 2 15 | else: 16 | min_row = (max_row + min_row) / 2 17 | for letter in line[7:10]: 18 | if letter == "L": 19 | max_col = (max_col + min_col) / 2 20 | else: 21 | min_col = (max_col + min_col) / 2 22 | max_seat_id = max(max_seat_id, 8 * (max_row - 1) + max_col - 1) 23 | print(max_seat_id) 24 | return max_seat_id 25 | 26 | 27 | if __name__ == "__main__": 28 | main() 29 | -------------------------------------------------------------------------------- /2020/python/day_05b.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | 4 | def main(): 5 | f = open("../input/day_05_input") 6 | seat_id = 0 7 | seats = set() 8 | for line in f: 9 | min_row = 0 10 | max_row = 128 11 | min_col = 0 12 | max_col = 8 13 | for letter in line[0:7]: 14 | if letter == "F": 15 | max_row = (max_row + min_row) / 2 16 | else: 17 | min_row = (max_row + min_row) / 2 18 | for letter in line[7:10]: 19 | if letter == "L": 20 | max_col = (max_col + min_col) / 2 21 | else: 22 | min_col = (max_col + min_col) / 2 23 | seat_id = 8 * (max_row - 1) + max_col - 1 24 | seats.add(seat_id) 25 | for seat in range(0, 1016): 26 | if seat not in seats and (seat + 1) in seats and (seat - 1) in seats: 27 | print(seat) 28 | return seat 29 | return 0 30 | 31 | 32 | if __name__ == "__main__": 33 | main() 34 | -------------------------------------------------------------------------------- /2020/python/day_06a.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | 4 | def main(): 5 | f = open("../input/day_06_input") 6 | count = 0 7 | answers = set() 8 | for line in f: 9 | line = line.strip().replace("\r", "").replace("\n", "") 10 | if line == "": 11 | count += len(answers) 12 | answers = set() 13 | else: 14 | for letter in line: 15 | answers.add(letter) 16 | count += len(answers) 17 | print(count) 18 | return count 19 | 20 | 21 | if __name__ == "__main__": 22 | main() 23 | -------------------------------------------------------------------------------- /2020/python/day_06b.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | 4 | def createSet(): 5 | myset = set() 6 | for val in range(ord("a"), ord("z") + 1): 7 | myset.add(chr(val)) 8 | # print(len(myset)) 9 | # print(myset) 10 | return myset 11 | 12 | 13 | def main(): 14 | f = open("../input/day_06_input") 15 | count = 0 16 | answers = createSet() 17 | for line in f: 18 | line = line.strip().replace("\r", "").replace("\n", "") 19 | if line == "": 20 | count += len(answers) 21 | answers = createSet() 22 | else: 23 | answers = {letter for letter in answers if letter in line} 24 | count += len(answers) 25 | print(count) 26 | return count 27 | 28 | 29 | if __name__ == "__main__": 30 | main() 31 | -------------------------------------------------------------------------------- /2020/python/day_07b.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | 4 | def normalizeData(line): 5 | return line.replace("bags", "").replace("bag", "").replace(".", "").strip() 6 | 7 | 8 | def getNumberAndColour(line): 9 | data = line.split(" ") 10 | number = int(data[0]) 11 | colour = (" ".join(data[1:])).strip() 12 | return number, colour 13 | 14 | 15 | def n_inner_bags(contains, colour): 16 | if colour not in contains.keys(): 17 | return 1 18 | else: 19 | count = 0 20 | for bag in contains[colour]: 21 | count += bag[0] * n_inner_bags(contains, bag[1]) 22 | return count + 1 23 | 24 | 25 | def main(): 26 | f = open("../input/day_07_input") 27 | contains = dict() 28 | for line in f: 29 | line = line.strip().replace("\n", "").replace("\r", "") 30 | line = normalizeData(line) 31 | outer_bag, bags_contained = line.split("contain") 32 | bags_contained = bags_contained.strip() 33 | outer_bag = normalizeData(outer_bag) 34 | if "no other" in bags_contained: 35 | continue 36 | inner_bags = [getNumberAndColour(bag) for bag in bags_contained.split(", ")] 37 | contains.update({outer_bag: inner_bags}) 38 | count = n_inner_bags(contains, "shiny gold") - 1 # -1 to remove the shiny gold bag 39 | print(count) 40 | return count 41 | 42 | 43 | if __name__ == "__main__": 44 | main() 45 | -------------------------------------------------------------------------------- /2020/python/day_08a.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | 4 | def main(): 5 | f = open("../input/day_08_input") 6 | lines = [line.strip().replace("\n", "").replace("\r", "") for line in f] 7 | n_lines = len(lines) 8 | execed_list = [False] * n_lines 9 | line = 0 10 | acc = 0 11 | while line < n_lines: 12 | if execed_list[line]: 13 | print(acc) 14 | return acc 15 | else: 16 | execed_list[line] = True 17 | if lines[line][0:3] == "nop": 18 | line = line + 1 19 | elif lines[line][0:3] == "jmp": 20 | line = line + int(lines[line][3:]) 21 | elif lines[line][0:3] == "acc": 22 | acc += int(lines[line][3:]) 23 | line = line + 1 24 | else: 25 | print("WTH") 26 | return 0 27 | 28 | 29 | if __name__ == "__main__": 30 | main() 31 | -------------------------------------------------------------------------------- /2020/python/day_09a.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | 4 | def main(): 5 | list_size = 25 6 | f = open("../input/day_09_input") 7 | values = list() 8 | for i in range(0, list_size): 9 | line = f.readline().strip().replace("\n", "").replace("\r", "") 10 | values.append(int(line)) 11 | for line in f: 12 | new_number = int(line) 13 | allowed = False 14 | # TODO(vss): Optimize 15 | for i in range(0, list_size): 16 | if not allowed: 17 | for j in range(i, list_size): 18 | if (values[i] + values[j]) == new_number: 19 | allowed = True 20 | break 21 | if allowed: 22 | values.append(new_number) 23 | values.pop(0) 24 | else: 25 | print(new_number) 26 | return new_number 27 | return 0 28 | 29 | 30 | if __name__ == "__main__": 31 | main() 32 | -------------------------------------------------------------------------------- /2020/python/day_10a.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | 4 | def main(): 5 | f = open("../input/day_10_input") 6 | jolts = list() 7 | for line in f: 8 | line = line.strip().replace("\n", "").replace("\r", "") 9 | jolts.append(int(line)) 10 | jolts.sort() 11 | diff_1 = 0 12 | diff_2 = 0 13 | diff_3 = 0 14 | for i in range(1, len(jolts)): 15 | diff = jolts[i] - jolts[i - 1] 16 | if diff == 1: 17 | diff_1 += 1 18 | elif diff == 2: 19 | diff_2 += 1 20 | elif diff == 3: 21 | diff_3 += 1 22 | else: 23 | print("WTH") 24 | diff_1 += 1 # from outlet to first 25 | diff_3 += 1 # to built in adapter 26 | print(diff_1 * diff_3) 27 | return diff_1 * diff_3 28 | 29 | 30 | if __name__ == "__main__": 31 | main() 32 | -------------------------------------------------------------------------------- /2020/python/day_10b.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | lower_delta = 1 4 | upper_delta = 3 5 | 6 | 7 | def NArrangements(index, jolts, n_arr): 8 | if jolts[index] in n_arr.keys(): 9 | return n_arr[jolts[index]] 10 | count = 0 11 | for i in range(lower_delta, upper_delta + 1): 12 | if index - i >= 0 and jolts[index] - jolts[index - i] <= 3: 13 | count += NArrangements(index - i, jolts, n_arr) 14 | n_arr[jolts[index]] = count 15 | return count 16 | 17 | 18 | def main(): 19 | f = open("../input/day_10_input") 20 | jolts = list() 21 | for line in f: 22 | line = line.strip().replace("\n", "").replace("\r", "") 23 | jolts.append(int(line)) 24 | jolts.append(0) 25 | jolts.sort() 26 | n_arr = dict() 27 | n_arr[0] = 1 28 | count = NArrangements(len(jolts) - 1, jolts, n_arr) 29 | print(count) 30 | return count 31 | 32 | 33 | if __name__ == "__main__": 34 | main() 35 | -------------------------------------------------------------------------------- /2020/python/day_12a.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | 4 | def main(): 5 | f = open("../input/day_12_input") 6 | position = [0, 0] 7 | dir = 0 8 | for line in f: 9 | line = line.strip().replace("\r", "").replace("\n", "") 10 | if line[0] == "N": 11 | position[1] += int(line[1:]) 12 | elif line[0] == "E": 13 | position[0] += int(line[1:]) 14 | elif line[0] == "S": 15 | position[1] -= int(line[1:]) 16 | elif line[0] == "W": 17 | position[0] -= int(line[1:]) 18 | elif line[0] == "F": 19 | if dir == 0: 20 | position[0] += int(line[1:]) 21 | elif dir == 1: 22 | position[1] += int(line[1:]) 23 | elif dir == 2: 24 | position[0] -= int(line[1:]) 25 | elif dir == 3: 26 | position[1] -= int(line[1:]) 27 | elif line[0] == "R": 28 | dir -= 1 * (int(line[1:]) / 90) 29 | dir %= 4 30 | elif line[0] == "L": 31 | dir += 1 * (int(line[1:]) / 90) 32 | while dir < 0: 33 | dir += 4 34 | dir %= 4 35 | else: 36 | print("WTH") 37 | print(abs(position[0]) + abs(position[1])) 38 | return abs(position[0]) + abs(position[1]) 39 | 40 | 41 | if __name__ == "__main__": 42 | main() 43 | -------------------------------------------------------------------------------- /2020/python/day_12b.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | 4 | def main(): 5 | f = open("../input/day_12_input") 6 | wp_pos = [10, 1] 7 | ferry_pos = [0, 0] 8 | for line in f: 9 | line = line.strip().replace("\r", "").replace("\n", "") 10 | if line[0] == "N": 11 | wp_pos[1] += int(line[1:]) 12 | elif line[0] == "E": 13 | wp_pos[0] += int(line[1:]) 14 | elif line[0] == "S": 15 | wp_pos[1] -= int(line[1:]) 16 | elif line[0] == "W": 17 | wp_pos[0] -= int(line[1:]) 18 | elif line[0] == "F": 19 | ferry_pos[0] += wp_pos[0] * int(line[1:]) 20 | ferry_pos[1] += wp_pos[1] * int(line[1:]) 21 | elif line[0] == "R": 22 | for i in range(0, int(int(line[1:]) / 90)): 23 | temp = wp_pos[0] 24 | wp_pos[0] = wp_pos[1] 25 | wp_pos[1] = -temp 26 | elif line[0] == "L": 27 | for i in range(0, int(int(line[1:]) / 90)): 28 | temp = wp_pos[0] 29 | wp_pos[0] = -wp_pos[1] 30 | wp_pos[1] = temp 31 | else: 32 | print("WTH") 33 | print(abs(ferry_pos[0]) + abs(ferry_pos[1])) 34 | return abs(ferry_pos[0]) + abs(ferry_pos[1]) 35 | 36 | 37 | if __name__ == "__main__": 38 | main() 39 | -------------------------------------------------------------------------------- /2020/python/day_13a.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | 4 | def main(): 5 | f = open("../input/day_13_input") 6 | time = int(f.readline().strip().replace("\n", "").replace("\r", "")) 7 | buses = [ 8 | int(bus) 9 | for bus in f.readline() 10 | .strip() 11 | .replace("\n", "") 12 | .replace("\r", "") 13 | .replace("x,", "") 14 | .split(",") 15 | ] 16 | rem = [min(buses), buses.index(min(buses))] 17 | for bus in buses: 18 | c_rem = bus - (time % bus) 19 | if c_rem < rem[0]: 20 | rem[0] = c_rem 21 | rem[1] = bus 22 | print(rem[0] * rem[1]) 23 | return rem[0] * rem[1] 24 | 25 | 26 | if __name__ == "__main__": 27 | main() 28 | -------------------------------------------------------------------------------- /2020/python/day_13b.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | 4 | def extendedGCD(a, b): 5 | if a == 0: 6 | return b, 0, 1 7 | gcd, prev_x, prev_y = extendedGCD(b % a, a) 8 | return gcd, prev_y - (int(b / a) * prev_x), prev_x 9 | 10 | 11 | def ChineseRemainderTheorem(drs): 12 | prod = 1 13 | for dr in drs: 14 | prod *= dr[0] 15 | result = 0 16 | for div, rem in drs: 17 | prodbyd = int(prod / div) 18 | gcd, x, y = extendedGCD(prodbyd, div) 19 | result = (prod + result + (rem * prodbyd * x)) % prod 20 | return result 21 | 22 | 23 | def main(): 24 | f = open("../input/day_13_input") 25 | time = int(f.readline().strip().replace("\n", "").replace("\r", "")) 26 | buses = [ 27 | [int(bus), int(bus) - i] 28 | for i, bus in enumerate( 29 | f.readline().strip().replace("\n", "").replace("\r", "").split(",") 30 | ) 31 | if bus.isdigit() 32 | ] 33 | result = ChineseRemainderTheorem(buses) 34 | print(result) 35 | return result 36 | 37 | 38 | if __name__ == "__main__": 39 | main() 40 | -------------------------------------------------------------------------------- /2020/python/day_14a.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import re 4 | 5 | 6 | def main(): 7 | f = open("../input/day_14_input") 8 | mem_pattern = re.compile(r"mem\[(\d+)\] = (\d+)(.*?)") 9 | mem = dict() 10 | for line in f: 11 | line = line.strip().replace("\n", "").replace("\r", "") 12 | if line[0:4] == "mask": 13 | mask = line.split()[-1] 14 | clear_mask = [1 if char == "X" else 0 for char in mask] 15 | set_mask = [1 if char == "1" else 0 for char in mask] 16 | else: 17 | address, value, __ = mem_pattern.match(line).groups() 18 | value_list = format(int(value), "#038b") 19 | num = list() 20 | for i in range(0, 36): 21 | num.append((int(value_list[i + 2]) & clear_mask[i]) | set_mask[i]) 22 | mem[address] = num 23 | total = 0 24 | for ele in mem.values(): 25 | res = 0 26 | for e in ele: 27 | res = (res << 1) | e 28 | total += res 29 | print(total) 30 | return total 31 | 32 | 33 | if __name__ == "__main__": 34 | main() 35 | -------------------------------------------------------------------------------- /2020/python/day_15a.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import copy 3 | 4 | 5 | def main(): 6 | f = open("../input/day_15_input") 7 | inputs = f.readline().strip().replace("\r", "").replace("\n", "").split(",") 8 | numbers = dict() 9 | count = 0 10 | for input in inputs: 11 | numbers[int(input)] = count 12 | count += 1 13 | cur = 0 14 | while count < 2019: 15 | if cur in numbers.keys(): 16 | temp = copy.deepcopy(cur) 17 | cur = count - numbers[cur] 18 | numbers[temp] = count 19 | else: 20 | numbers[cur] = count 21 | cur = 0 22 | count += 1 23 | print(cur) 24 | return cur 25 | 26 | 27 | if __name__ == "__main__": 28 | main() 29 | -------------------------------------------------------------------------------- /2020/python/day_15b.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import copy 3 | 4 | 5 | def main(): 6 | f = open("../input/day_15_input") 7 | inputs = f.readline().strip().replace("\r", "").replace("\n", "").split(",") 8 | numbers = dict() 9 | count = 0 10 | for input in inputs: 11 | numbers[int(input)] = count 12 | count += 1 13 | cur = 0 14 | while count < 29999999: 15 | if cur in numbers.keys(): 16 | temp = copy.deepcopy(cur) 17 | cur = count - numbers[cur] 18 | numbers[temp] = count 19 | else: 20 | numbers[cur] = count 21 | cur = 0 22 | count += 1 23 | print(cur) 24 | return cur 25 | 26 | 27 | if __name__ == "__main__": 28 | main() 29 | -------------------------------------------------------------------------------- /2020/python/day_24a.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | 4 | def getCooordinatesFromPath(path): 5 | i = 0 6 | x = 0 7 | y = 0 8 | while i < len(path): 9 | if path[i] == "e": 10 | x = x + 2 11 | i = i + 1 12 | elif path[i] == "w": 13 | x = x - 2 14 | i = i + 1 15 | elif path[i : i + 2] == "nw": 16 | x = x - 1 17 | y = y + 1 18 | i = i + 2 19 | elif path[i : i + 2] == "ne": 20 | x = x + 1 21 | y = y + 1 22 | i = i + 2 23 | elif path[i : i + 2] == "sw": 24 | x = x - 1 25 | y = y - 1 26 | i = i + 2 27 | elif path[i : i + 2] == "se": 28 | x = x + 1 29 | y = y - 1 30 | i = i + 2 31 | return x, y 32 | 33 | 34 | def main(): 35 | f = open("../input/day_24_input") 36 | isWhiteUp = dict() 37 | for path in f: 38 | path = path.strip("\n") 39 | x, y = getCooordinatesFromPath(path) 40 | coord = (x, y) 41 | if coord in isWhiteUp: 42 | isWhiteUp[coord] = not isWhiteUp[coord] 43 | else: 44 | isWhiteUp[coord] = False 45 | count = 0 46 | for key in isWhiteUp: 47 | if not isWhiteUp[key]: 48 | count = count + 1 49 | print(count) 50 | return count 51 | 52 | 53 | if __name__ == "__main__": 54 | main() 55 | -------------------------------------------------------------------------------- /2020/python/day_25.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | 4 | def FindLoopSize(public_key, subject_number): 5 | count = 0 6 | value = 1 7 | while True: 8 | count = count + 1 9 | value = value * subject_number 10 | value = value % 20201227 11 | if value == public_key: 12 | break 13 | return count 14 | 15 | 16 | def GenerateEncrytionKey(subject_number, loop_size): 17 | value = 1 18 | for i in range(0, loop_size): 19 | value = value * subject_number 20 | value = value % 20201227 21 | return value 22 | 23 | 24 | def main(): 25 | file = open("../input/day_25_input") 26 | line = file.readline() 27 | line = line.strip("\n") 28 | card_public_key = int(line) 29 | card_subject_number = 7 30 | card_loop_size = FindLoopSize(card_public_key, card_subject_number) 31 | 32 | line = file.readline() 33 | line = line.strip("\n") 34 | door_public_key = int(line) 35 | door_subject_number = 7 36 | door_loop_size = FindLoopSize(door_public_key, door_subject_number) 37 | 38 | encryption_key = GenerateEncrytionKey(card_public_key, door_loop_size) 39 | print(encryption_key) 40 | return encryption_key 41 | 42 | 43 | if __name__ == "__main__": 44 | main() 45 | -------------------------------------------------------------------------------- /2020/sample_input/day_01_sample_input: -------------------------------------------------------------------------------- 1 | 1721 2 | 979 3 | 366 4 | 299 5 | 675 6 | 1456 7 | -------------------------------------------------------------------------------- /2020/sample_input/day_02_sample_input: -------------------------------------------------------------------------------- 1 | 1-3 a: abcde 2 | 1-3 b: cdefg 3 | 2-9 c: ccccccccc 4 | -------------------------------------------------------------------------------- /2020/sample_input/day_03_sample_input: -------------------------------------------------------------------------------- 1 | ..##....... 2 | #...#...#.. 3 | .#....#..#. 4 | ..#.#...#.# 5 | .#...##..#. 6 | ..#.##..... 7 | .#.#.#....# 8 | .#........# 9 | #.##...#... 10 | #...##....# 11 | .#..#...#.# 12 | -------------------------------------------------------------------------------- /2020/sample_input/day_04_sample_input: -------------------------------------------------------------------------------- 1 | ecl:gry pid:860033327 eyr:2020 hcl:#fffffd 2 | byr:1937 iyr:2017 cid:147 hgt:183cm 3 | 4 | iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884 5 | hcl:#cfa07d byr:1929 6 | 7 | hcl:#ae17e1 iyr:2013 8 | eyr:2024 9 | ecl:brn pid:760753108 byr:1931 10 | hgt:179cm 11 | 12 | hcl:#cfa07d eyr:2025 pid:166559648 13 | iyr:2011 ecl:brn hgt:59in 14 | -------------------------------------------------------------------------------- /2020/sample_input/day_05_sample_input: -------------------------------------------------------------------------------- 1 | FBFBBFFRLR 2 | FBFBBFFRLR 3 | BFFFBBFRRR 4 | FFFBBBFRRR 5 | BBFFBBFRLL 6 | -------------------------------------------------------------------------------- /2020/sample_input/day_06_sample_input: -------------------------------------------------------------------------------- 1 | abc 2 | 3 | a 4 | b 5 | c 6 | 7 | ab 8 | ac 9 | 10 | a 11 | a 12 | a 13 | a 14 | 15 | b 16 | -------------------------------------------------------------------------------- /2020/sample_input/day_07_sample_input: -------------------------------------------------------------------------------- 1 | light red bags contain 1 bright white bag, 2 muted yellow bags. 2 | dark orange bags contain 3 bright white bags, 4 muted yellow bags. 3 | bright white bags contain 1 shiny gold bag. 4 | muted yellow bags contain 2 shiny gold bags, 9 faded blue bags. 5 | shiny gold bags contain 1 dark olive bag, 2 vibrant plum bags. 6 | dark olive bags contain 3 faded blue bags, 4 dotted black bags. 7 | vibrant plum bags contain 5 faded blue bags, 6 dotted black bags. 8 | faded blue bags contain no other bags. 9 | dotted black bags contain no other bags. 10 | -------------------------------------------------------------------------------- /2020/sample_input/day_08_sample_input: -------------------------------------------------------------------------------- 1 | nop +0 2 | acc +1 3 | jmp +4 4 | acc +3 5 | jmp -3 6 | acc -99 7 | acc +1 8 | jmp -4 9 | acc +6 10 | -------------------------------------------------------------------------------- /2020/sample_input/day_09_sample_input: -------------------------------------------------------------------------------- 1 | 35 2 | 20 3 | 15 4 | 25 5 | 47 6 | 40 7 | 62 8 | 55 9 | 65 10 | 95 11 | 102 12 | 117 13 | 150 14 | 182 15 | 127 16 | 219 17 | 299 18 | 277 19 | 309 20 | 576 21 | -------------------------------------------------------------------------------- /2020/sample_input/day_10_sample_input: -------------------------------------------------------------------------------- 1 | 16 2 | 10 3 | 15 4 | 5 5 | 1 6 | 11 7 | 7 8 | 19 9 | 6 10 | 12 11 | 4 12 | -------------------------------------------------------------------------------- /2020/sample_input/day_11_sample_input: -------------------------------------------------------------------------------- 1 | L.LL.LL.LL 2 | LLLLLLL.LL 3 | L.L.L..L.. 4 | LLLL.LL.LL 5 | L.LL.LL.LL 6 | L.LLLLL.LL 7 | ..L.L..... 8 | LLLLLLLLLL 9 | L.LLLLLL.L 10 | L.LLLLL.LL 11 | -------------------------------------------------------------------------------- /2020/sample_input/day_12_sample_input: -------------------------------------------------------------------------------- 1 | F10 2 | N3 3 | F7 4 | R90 5 | F11 6 | -------------------------------------------------------------------------------- /2020/sample_input/day_13_sample_input: -------------------------------------------------------------------------------- 1 | 939 2 | 7,13,x,x,59,x,31,19 3 | -------------------------------------------------------------------------------- /2020/sample_input/day_14_sample_input: -------------------------------------------------------------------------------- 1 | mask = XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X 2 | mem[8] = 11 3 | mem[7] = 101 4 | mem[8] = 0 5 | 6 | --- 7 | 8 | mask = 000000000000000000000000000000X1001X 9 | mem[42] = 100 10 | mask = 00000000000000000000000000000000X0XX 11 | mem[26] = 1 12 | -------------------------------------------------------------------------------- /2020/sample_input/day_15_sample_input: -------------------------------------------------------------------------------- 1 | 0,3,6 2 | 1,3,2 3 | 2,1,3 4 | 1,2,3 5 | 2,3,1 6 | 3,2,1 7 | 3,1,2 8 | -------------------------------------------------------------------------------- /2020/sample_input/day_16_sample_input: -------------------------------------------------------------------------------- 1 | class: 1-3 or 5-7 2 | row: 6-11 or 33-44 3 | seat: 13-40 or 45-50 4 | 5 | your ticket: 6 | 7,1,14 7 | 8 | nearby tickets: 9 | 7,3,47 10 | 40,4,50 11 | 55,2,20 12 | 38,6,12 13 | 14 | --- 15 | 16 | class: 0-1 or 4-19 17 | row: 0-5 or 8-19 18 | seat: 0-13 or 16-19 19 | 20 | your ticket: 21 | 11,12,13 22 | 23 | nearby tickets: 24 | 3,9,18 25 | 15,1,5 26 | 5,14,9 27 | -------------------------------------------------------------------------------- /2020/sample_input/day_17_sample_input: -------------------------------------------------------------------------------- 1 | .#. 2 | ..# 3 | ### 4 | -------------------------------------------------------------------------------- /2020/sample_input/day_18_sample_input: -------------------------------------------------------------------------------- 1 | 1 + 2 * 3 + 4 * 5 + 6 2 | 1 + (2 * 3) + (4 * (5 + 6)) 3 | 2 * 3 + (4 * 5) 4 | 5 + (8 * 3 + 9 + 3 * 4 * 3) 5 | 5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4)) 6 | ((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2 7 | -------------------------------------------------------------------------------- /2020/sample_input/day_19_sample_input: -------------------------------------------------------------------------------- 1 | 0: 4 1 5 2 | 1: 2 3 | 3 2 3 | 2: 4 4 | 5 5 4 | 3: 4 5 | 5 4 5 | 4: "a" 6 | 5: "b" 7 | 8 | ababbb 9 | bababa 10 | abbbab 11 | aaabbb 12 | aaaabbb 13 | -------------------------------------------------------------------------------- /2020/sample_input/day_21_sample_input: -------------------------------------------------------------------------------- 1 | mxmxvkd kfcds sqjhc nhms (contains dairy, fish) 2 | trh fvjkl sbzzf mxmxvkd (contains dairy) 3 | sqjhc fvjkl (contains soy) 4 | sqjhc mxmxvkd sbzzf (contains fish) 5 | -------------------------------------------------------------------------------- /2020/sample_input/day_22_sample_input: -------------------------------------------------------------------------------- 1 | Player 1: 2 | 9 3 | 2 4 | 6 5 | 3 6 | 1 7 | 8 | Player 2: 9 | 5 10 | 8 11 | 4 12 | 7 13 | 10 14 | -------------------------------------------------------------------------------- /2020/sample_input/day_23_sample_input: -------------------------------------------------------------------------------- 1 | 389125467 2 | -------------------------------------------------------------------------------- /2020/sample_input/day_24_sample_input: -------------------------------------------------------------------------------- 1 | sesenwnenenewseeswwswswwnenewsewsw 2 | neeenesenwnwwswnenewnwwsewnenwseswesw 3 | seswneswswsenwwnwse 4 | nwnwneseeswswnenewneswwnewseswneseene 5 | swweswneswnenwsewnwneneseenw 6 | eesenwseswswnenwswnwnwsewwnwsene 7 | sewnenenenesenwsewnenwwwse 8 | wenwwweseeeweswwwnwwe 9 | wsweesenenewnwwnwsenewsenwwsesesenwne 10 | neeswseenwwswnwswswnw 11 | nenwswwsewswnenenewsenwsenwnesesenew 12 | enewnwewneswsewnwswenweswnenwsenwsw 13 | sweneswneswneneenwnewenewwneswswnese 14 | swwesenesewenwneswnwwneseswwne 15 | enesenwswwswneneswsenwnewswseenwsese 16 | wnwnesenesenenwwnenwsewesewsesesew 17 | nenewswnwewswnenesenwnesewesw 18 | eneswnwswnwsenenwnwnwwseeswneewsenese 19 | neswnwewnwnwseenwseesewsenwsweewe 20 | wseweeenwnesenwwwswnew 21 | -------------------------------------------------------------------------------- /2020/sample_input/day_25_sample_input: -------------------------------------------------------------------------------- 1 | 5764801 2 | 17807724 3 | -------------------------------------------------------------------------------- /2021/cpp/day_01a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char * argv[]) { 6 | std::string input = "../input/day_01_input"; 7 | if (argc > 1) { 8 | input = argv[1]; 9 | } 10 | 11 | std::string line; 12 | std::fstream file(input); 13 | std::getline(file, line); 14 | int cur = std::stoi(line); 15 | int prev = cur; 16 | int count = 0; 17 | while(std::getline(file, line)) { 18 | prev = cur; 19 | cur = std::stoi(line); 20 | if (cur > prev) { 21 | count++; 22 | } 23 | } 24 | std::cout << count << '\n'; 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /2021/cpp/day_01b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char * argv[]) { 7 | std::string input = "../input/day_01_input"; 8 | if (argc > 1) { 9 | input = argv[1]; 10 | } 11 | 12 | std::string line; 13 | std::fstream file(input); 14 | std::queue window; 15 | constexpr int n = 3; 16 | int cur = 0; 17 | for (int i = 0; i < n; i++) { 18 | std::getline(file, line); 19 | const int temp = std::stoi(line); 20 | window.push(temp); 21 | cur += temp; 22 | } 23 | int prev = cur; 24 | int count = 0; 25 | while(std::getline(file, line)) { 26 | prev = cur; 27 | cur -= window.front(); 28 | window.pop(); 29 | const int temp = std::stoi(line); 30 | cur += temp; 31 | window.push(temp); 32 | if (cur > prev) { 33 | count++; 34 | } 35 | } 36 | std::cout << count << '\n'; 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /2021/cpp/day_02a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char * argv[]) { 6 | std::string input = "../input/day_02_input"; 7 | if (argc > 1) { 8 | input = argv[1]; 9 | } 10 | 11 | std::string line; 12 | std::fstream file(input); 13 | int x = 0; 14 | int d = 0; 15 | while(std::getline(file, line)) { 16 | if (line[0] == 'f') { 17 | x += std::stoi(line.substr(7, line.size() - 7)); 18 | } else if (line[0] == 'd'){ 19 | d += std::stoi(line.substr(4, line.size() - 4)); 20 | } else if (line[0] == 'u') { 21 | d -= std::stoi(line.substr(2, line.size() - 2)); 22 | } 23 | } 24 | std::cout << x * d << '\n'; 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /2021/cpp/day_02b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char * argv[]) { 6 | std::string input = "../input/day_02_input"; 7 | if (argc > 1) { 8 | input = argv[1]; 9 | } 10 | 11 | std::string line; 12 | std::fstream file(input); 13 | int x = 0; 14 | int d = 0; 15 | int aim = 0; 16 | while(std::getline(file, line)) { 17 | if (line[0] == 'f') { 18 | const int X = std::stoi(line.substr(7, line.size() - 7)); 19 | x += X; 20 | d += aim * X; 21 | } else if (line[0] == 'd'){ 22 | aim += std::stoi(line.substr(4, line.size() - 4)); 23 | } else if (line[0] == 'u') { 24 | aim -= std::stoi(line.substr(2, line.size() - 2)); 25 | } 26 | } 27 | std::cout << x * d << '\n'; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /2021/cpp/day_03a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | inline int convert_to_binary(const std::vector& bin_vec) { 8 | const int s = bin_vec.size(); 9 | int bin_val = 0; 10 | for (int i = 0; i < s; i++) { 11 | bin_val += (bin_vec[s - i - 1]) << i; 12 | } 13 | return bin_val; 14 | } 15 | 16 | int main(int argc, char * argv[]) { 17 | std::string input = "../input/day_03_input"; 18 | if (argc > 1) { 19 | input = argv[1]; 20 | } 21 | 22 | std::string line; 23 | std::fstream file(input); 24 | 25 | int n = 0; 26 | std::getline(file, line); 27 | n++; 28 | const size_t s = line.size(); 29 | std::vector digits(s); 30 | for (int i = 0; i < line.size(); i++) { 31 | digits[i] = line[i] - '0'; 32 | } 33 | while(std::getline(file, line)) { 34 | n++; 35 | for (int i = 0; i < s; i++) { 36 | digits[i] += line[i] - '0'; 37 | } 38 | } 39 | 40 | for (auto& ele : digits) { 41 | ele = (ele * 2) / n; 42 | } 43 | 44 | const int gamma = convert_to_binary(digits); 45 | for (auto& digit : digits) { 46 | digit = std::abs(1 - digit); 47 | } 48 | const int eps = convert_to_binary(digits); 49 | 50 | std::cout << gamma * eps << '\n'; 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /2021/cpp/day_06a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void print(const std::vector& v) { 7 | for (const auto ele : v) { 8 | std::cout << ele << ','; 9 | } 10 | std::cout << '\n'; 11 | } 12 | 13 | int main(int argc, char * argv[]) { 14 | std::string input = "../input/day_06_input"; 15 | if (argc > 1) { 16 | input = argv[1]; 17 | } 18 | 19 | std::string line; 20 | std::fstream file(input); 21 | std::getline(file, line); 22 | std::vector fish; 23 | std::size_t start = 0; 24 | std::size_t end = line.find(',', start); 25 | while (end != std::string::npos) { 26 | fish.emplace_back(std::stoi(line.substr(start, end - start))); 27 | start = end + 1; 28 | end = line.find(',', start); 29 | } 30 | fish.emplace_back(std::stoi(line.substr(start, line.size() - start))); 31 | // print(fish); 32 | for (int day = 0; day < 80; day++) { 33 | int to_add = 0; 34 | for (auto& f : fish) { 35 | if (f == 0) { 36 | to_add++; 37 | f = 7; 38 | } 39 | f--; 40 | } 41 | for (int i = 0; i < to_add; i++) { 42 | fish.emplace_back(8); 43 | } 44 | // print(fish); 45 | } 46 | std::cout << fish.size() << '\n'; 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /2021/cpp/day_07b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | long long total_fuel_spent (const std::vector& positions, const long long final_position) { 10 | long long sum = 0; 11 | for (const auto& ele : positions) { 12 | sum += (std::abs(ele - final_position) * (std::abs(ele - final_position) + 1)) / 2; 13 | } 14 | return sum; 15 | } 16 | 17 | int main(int argc, char * argv[]) { 18 | std::string input = "../input/day_07_input"; 19 | if (argc > 1) { 20 | input = argv[1]; 21 | } 22 | 23 | std::string line; 24 | std::fstream file(input); 25 | std::getline(file, line); 26 | std::vector crab_positions; 27 | 28 | std::size_t start = 0; 29 | std::size_t end = line.find(',', start); 30 | long long average_pos = 0; 31 | while (end != std::string::npos) { 32 | const long long position = std::stoll(line.substr(start, end - start)); 33 | crab_positions.emplace_back(position); 34 | average_pos += position; 35 | start = end + 1; 36 | end = line.find(',', start); 37 | } 38 | const long long position = std::stoll(line.substr(start, line.size() - start)); 39 | crab_positions.emplace_back(position); 40 | average_pos += position; 41 | average_pos /= crab_positions.size(); 42 | 43 | std::cout << std::min(total_fuel_spent(crab_positions, average_pos), total_fuel_spent(crab_positions, average_pos + 1)) << '\n'; 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /2021/cpp/day_21a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char * argv[]) { 6 | 7 | std::string input = "../input/day_21_input"; 8 | if (argc > 1) { 9 | input = argv[1]; 10 | } 11 | 12 | std::string line; 13 | std::fstream file(input); 14 | std::getline(file, line); 15 | int p1 = line[28] - '0'; 16 | std::getline(file, line); 17 | int p2 = line[28] - '0'; 18 | 19 | int score1 = 0; 20 | int score2 = 0; 21 | int n_move = 6; 22 | int count = 0; 23 | int rolls = 0; 24 | while (true) { 25 | p1 += n_move; 26 | p1 = p1 % 10; // let 10 be position 0; 27 | score1 += (p1 == 0 ? 10 : p1); // ensure points added with 10 28 | rolls += 3; 29 | if (score1 >= 1000) { 30 | std::cout << rolls * score2 << '\n'; 31 | return 0; 32 | } 33 | n_move += 9; 34 | 35 | p2 += n_move; 36 | p2 = p2 % 10; // let 10 be position 0; 37 | score2 += (p2 == 0 ? 10 : p2); // ensure points added with 10 38 | rolls += 3; 39 | if (score2 >= 1000) { 40 | std::cout << rolls * score1 << '\n'; 41 | return 0; 42 | } 43 | n_move += 9; 44 | } 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /2021/sample_input/day_01_sample_input: -------------------------------------------------------------------------------- 1 | 199 2 | 200 3 | 208 4 | 210 5 | 200 6 | 207 7 | 240 8 | 269 9 | 260 10 | 263 11 | -------------------------------------------------------------------------------- /2021/sample_input/day_02_sample_input: -------------------------------------------------------------------------------- 1 | forward 5 2 | down 5 3 | forward 8 4 | up 3 5 | down 8 6 | forward 2 7 | -------------------------------------------------------------------------------- /2021/sample_input/day_03_sample_input: -------------------------------------------------------------------------------- 1 | 00100 2 | 11110 3 | 10110 4 | 10111 5 | 10101 6 | 01111 7 | 00111 8 | 11100 9 | 10000 10 | 11001 11 | 00010 12 | 01010 13 | -------------------------------------------------------------------------------- /2021/sample_input/day_04_sample_input: -------------------------------------------------------------------------------- 1 | 7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1 2 | 3 | 22 13 17 11 0 4 | 8 2 23 4 24 5 | 21 9 14 16 7 6 | 6 10 3 18 5 7 | 1 12 20 15 19 8 | 9 | 3 15 0 2 22 10 | 9 18 13 17 5 11 | 19 8 7 25 23 12 | 20 11 10 24 4 13 | 14 21 16 12 6 14 | 15 | 14 21 17 24 4 16 | 10 16 15 9 19 17 | 18 8 23 26 20 18 | 22 11 13 6 5 19 | 2 0 12 3 7 20 | -------------------------------------------------------------------------------- /2021/sample_input/day_05_sample_input: -------------------------------------------------------------------------------- 1 | 0,9 -> 5,9 2 | 8,0 -> 0,8 3 | 9,4 -> 3,4 4 | 2,2 -> 2,1 5 | 7,0 -> 7,4 6 | 6,4 -> 2,0 7 | 0,9 -> 2,9 8 | 3,4 -> 1,4 9 | 0,0 -> 8,8 10 | 5,5 -> 8,2 11 | -------------------------------------------------------------------------------- /2021/sample_input/day_06_sample_input: -------------------------------------------------------------------------------- 1 | 3,4,3,1,2 2 | -------------------------------------------------------------------------------- /2021/sample_input/day_07_sample_input: -------------------------------------------------------------------------------- 1 | 16,1,2,0,4,2,7,1,2,14 2 | -------------------------------------------------------------------------------- /2021/sample_input/day_08_sample_input: -------------------------------------------------------------------------------- 1 | be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | fdgacbe cefdb cefbgd gcbe 2 | edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec | fcgedb cgb dgebacf gc 3 | fgaebd cg bdaec gdafb agbcfd gdcbef bgcad gfac gcb cdgabef | cg cg fdcagb cbg 4 | fbegcd cbd adcefb dageb afcb bc aefdc ecdab fgdeca fcdbega | efabcd cedba gadfec cb 5 | aecbfdg fbg gf bafeg dbefa fcge gcbea fcaegb dgceab fcbdga | gecf egdcabf bgf bfgea 6 | fgeab ca afcebg bdacfeg cfaedg gcfdb baec bfadeg bafgc acf | gebdcfa ecba ca fadegcb 7 | dbcfg fgd bdegcaf fgec aegbdf ecdfab fbedc dacgb gdcebf gf | cefg dcbef fcge gbcadfe 8 | bdfegc cbegaf gecbf dfcage bdacg ed bedf ced adcbefg gebcd | ed bcgafe cdgba cbgef 9 | egadfb cdbfeg cegd fecab cgb gbdefca cg fgcdab egfdb bfceg | gbdfcae bgc cg cgb 10 | gcafb gcf dcaebfg ecagb gf abcdeg gaef cafbge fdbac fegbdc | fgae cfgab fg bagce 11 | -------------------------------------------------------------------------------- /2021/sample_input/day_09_sample_input: -------------------------------------------------------------------------------- 1 | 2199943210 2 | 3987894921 3 | 9856789892 4 | 8767896789 5 | 9899965678 6 | -------------------------------------------------------------------------------- /2021/sample_input/day_10_sample_input: -------------------------------------------------------------------------------- 1 | [({(<(())[]>[[{[]{<()<>> 2 | [(()[<>])]({[<{<<[]>>( 3 | {([(<{}[<>[]}>{[]{[(<()> 4 | (((({<>}<{<{<>}{[]{[]{} 5 | [[<[([]))<([[{}[[()]]] 6 | [{[{({}]{}}([{[{{{}}([] 7 | {<[[]]>}<{[{[{[]{()[[[] 8 | [<(<(<(<{}))><([]([]() 9 | <{([([[(<>()){}]>(<<{{ 10 | <{([{{}}[<[[[<>{}]]]>[]] 11 | -------------------------------------------------------------------------------- /2021/sample_input/day_11_sample_input: -------------------------------------------------------------------------------- 1 | 5483143223 2 | 2745854711 3 | 5264556173 4 | 6141336146 5 | 6357385478 6 | 4167524645 7 | 2176841721 8 | 6882881134 9 | 4846848554 10 | 5283751526 11 | -------------------------------------------------------------------------------- /2021/sample_input/day_12_sample_input: -------------------------------------------------------------------------------- 1 | start-A 2 | start-b 3 | A-c 4 | A-b 5 | b-d 6 | A-end 7 | b-end 8 | 9 | dc-end 10 | HN-start 11 | start-kj 12 | dc-start 13 | dc-HN 14 | LN-dc 15 | HN-end 16 | kj-sa 17 | kj-HN 18 | kj-dc 19 | 20 | start,HN,dc,HN,end 21 | start,HN,dc,HN,kj,HN,end 22 | start,HN,dc,end 23 | start,HN,dc,kj,HN,end 24 | start,HN,end 25 | start,HN,kj,HN,dc,HN,end 26 | start,HN,kj,HN,dc,end 27 | start,HN,kj,HN,end 28 | start,HN,kj,dc,HN,end 29 | start,HN,kj,dc,end 30 | start,dc,HN,end 31 | start,dc,HN,kj,HN,end 32 | start,dc,end 33 | start,dc,kj,HN,end 34 | start,kj,HN,dc,HN,end 35 | start,kj,HN,dc,end 36 | start,kj,HN,end 37 | start,kj,dc,HN,end 38 | start,kj,dc,end 39 | 40 | fs-end 41 | he-DX 42 | fs-he 43 | start-DX 44 | pj-DX 45 | end-zg 46 | zg-sl 47 | zg-pj 48 | pj-he 49 | RW-he 50 | fs-DX 51 | pj-RW 52 | zg-RW 53 | start-pj 54 | he-WI 55 | zg-he 56 | pj-fs 57 | start-RW 58 | -------------------------------------------------------------------------------- /2021/sample_input/day_13_sample_input: -------------------------------------------------------------------------------- 1 | 6,10 2 | 0,14 3 | 9,10 4 | 0,3 5 | 10,4 6 | 4,11 7 | 6,0 8 | 6,12 9 | 4,1 10 | 0,13 11 | 10,12 12 | 3,4 13 | 3,0 14 | 8,4 15 | 1,10 16 | 2,14 17 | 8,10 18 | 9,0 19 | 20 | fold along y=7 21 | fold along x=5 22 | -------------------------------------------------------------------------------- /2021/sample_input/day_14_sample_input: -------------------------------------------------------------------------------- 1 | NNCB 2 | 3 | CH -> B 4 | HH -> N 5 | CB -> H 6 | NH -> C 7 | HB -> C 8 | HC -> B 9 | HN -> C 10 | NN -> C 11 | BH -> H 12 | NC -> B 13 | NB -> B 14 | BN -> B 15 | BB -> N 16 | BC -> B 17 | CC -> N 18 | CN -> C 19 | -------------------------------------------------------------------------------- /2021/sample_input/day_15_sample_input: -------------------------------------------------------------------------------- 1 | 1163751742 2 | 1381373672 3 | 2136511328 4 | 3694931569 5 | 7463417111 6 | 1319128137 7 | 1359912421 8 | 3125421639 9 | 1293138521 10 | 2311944581 11 | -------------------------------------------------------------------------------- /2021/sample_input/day_16_sample_input: -------------------------------------------------------------------------------- 1 | D2FE28 2 | 38006F45291200 3 | EE00D40C823060 4 | 8A004A801A8002F478 5 | 620080001611562C8802118E34 6 | C0015000016115A2E0802F182340 7 | A0016C880162017C3686B18A3D4780 8 | 9 | C200B40A82 10 | 04005AC33890 11 | 880086C3E88112 12 | CE00C43D881120 13 | D8005AC2A8F0 14 | F600BC2D8F 15 | 9C005AC2F8F0 16 | 9C0141080250320F1802104A08 17 | -------------------------------------------------------------------------------- /2021/sample_input/day_17_sample_input: -------------------------------------------------------------------------------- 1 | target area: x=20..30, y=-10..-5 2 | -------------------------------------------------------------------------------- /2021/sample_input/day_18_sample_input: -------------------------------------------------------------------------------- 1 | [[[0,[5,8]],[[1,7],[9,6]]],[[4,[1,2]],[[1,4],2]]] 2 | [[[5,[2,8]],4],[5,[[9,9],0]]] 3 | [6,[[[6,2],[5,6]],[[7,6],[4,7]]]] 4 | [[[6,[0,7]],[0,9]],[4,[9,[9,0]]]] 5 | [[[7,[6,4]],[3,[1,3]]],[[[5,5],1],9]] 6 | [[6,[[7,3],[3,2]]],[[[3,8],[5,7]],4]] 7 | [[[[5,4],[7,7]],8],[[8,3],8]] 8 | [[9,3],[[9,9],[6,[4,9]]]] 9 | [[2,[[7,7],7]],[[5,8],[[9,3],[0,2]]]] 10 | [[[[5,2],5],[8,[3,7]]],[[5,[7,5]],[4,4]]] 11 | -------------------------------------------------------------------------------- /2021/sample_input/day_20_sample_input: -------------------------------------------------------------------------------- 1 | ..#.#..#####.#.#.#.###.##.....###.##.#..###.####..#####..#....#..#..##..###..######.###...####..#..#####..##..#.#####...##.#.#..#.##..#.#......#.###.######.###.####...#.##.##..#..#..#####.....#.#....###..#.##......#.....#..#..#..##..#...##.######.####.####.#.#...#.......#..#.#.#...####.##.#......#..#...##.#.##..#...##.#.##..###.#......#.#.......#.#.#.####.###.##...#.....####.#..#..#.##.#....##..#.####....##...##..#...#......#.#.......#.......##..####..#...#.#.#...##..#.#..###..#####........#..####......#..# 2 | 3 | #..#. 4 | #.... 5 | ##..# 6 | ..#.. 7 | ..### 8 | -------------------------------------------------------------------------------- /2021/sample_input/day_21_sample_input: -------------------------------------------------------------------------------- 1 | Player 1 starting position: 4 2 | Player 2 starting position: 8 3 | -------------------------------------------------------------------------------- /2021/sample_input/day_23_sample_input: -------------------------------------------------------------------------------- 1 | ############# 2 | #...........# 3 | ###B#C#B#D### 4 | #A#D#C#A# 5 | ######### 6 | -------------------------------------------------------------------------------- /2021/sample_input/day_24_sample_input: -------------------------------------------------------------------------------- 1 | inp z 2 | inp x 3 | mul z 3 4 | eql z x 5 | -------------------------------------------------------------------------------- /2021/sample_input/day_25_sample_input: -------------------------------------------------------------------------------- 1 | v...>>.vv> 2 | .vv>>.vv.. 3 | >>.>v>...v 4 | >>v>>.>.v. 5 | v>v.vv.v.. 6 | >.>>..v... 7 | .vv..>.>v. 8 | v.v..>>v.v 9 | ....v..v.> 10 | -------------------------------------------------------------------------------- /2022/cpp/day_01a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char * argv[]) { 7 | std::string input = "../input/day_01_input"; 8 | if (argc > 1) { 9 | input = argv[1]; 10 | } 11 | 12 | std::string line; 13 | std::fstream file(input); 14 | int max = 0; 15 | int total = 0; 16 | while(std::getline(file, line)) { 17 | // Account for CRLF if required 18 | // line.erase(std::remove_if(std::begin(line), std::end(line), [](auto c) { return !isprint(c); }), std::end(line)); 19 | if (line.size() == 0) { 20 | max = std::max(max, total); 21 | total = 0; 22 | } else { 23 | total += std::stoi(line); 24 | } 25 | } 26 | max = std::max(max, total); 27 | std::cout << max << '\n'; 28 | return max; 29 | } 30 | -------------------------------------------------------------------------------- /2022/cpp/day_01b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char * argv[]) { 8 | std::string input = "../input/day_01_input"; 9 | if (argc > 1) { 10 | input = argv[1]; 11 | } 12 | 13 | std::string line; 14 | std::fstream file(input); 15 | 16 | std::vector totals(1, 0); 17 | while(std::getline(file, line)) { 18 | // Account for CRLF if required 19 | // line.erase(std::remove_if(std::begin(line), std::end(line), [](auto c) { return !isprint(c); }), std::end(line)); 20 | if (line.size() == 0) { 21 | totals.emplace_back(0); 22 | } else { 23 | totals.back() += std::stoi(line); 24 | } 25 | } 26 | 27 | // Can use sort, or partial-sort as well, 28 | // but since first 3 largest numbers in any order, nth_element works 29 | std::nth_element(std::begin(totals), std::begin(totals) + 3, std::end(totals), std::greater()); 30 | const auto sum = totals[0] + totals[1] + totals[2]; 31 | std::cout << sum << '\n'; 32 | return sum; 33 | } 34 | -------------------------------------------------------------------------------- /2022/cpp/day_02a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char * argv[]) { 8 | std::string input = "../input/day_02_input"; 9 | if (argc > 1) { 10 | input = argv[1]; 11 | } 12 | 13 | std::string line; 14 | std::fstream file(input); 15 | 16 | int score = 0; 17 | while(std::getline(file, line)) { 18 | // Account for CRLF if required 19 | // line.erase(std::remove_if(std::begin(line), std::end(line), [](auto c) { return !isprint(c); }), std::end(line)); 20 | score += line[2] - 'X' + 1; 21 | if (const auto delta = (line[2] - line[0] - 23 + 3) % 3; delta == 1) { 22 | score += 6; 23 | } else if (delta == 0) { 24 | score += 3; 25 | } 26 | } 27 | std::cout << score << '\n'; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /2022/cpp/day_02b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char * argv[]) { 8 | std::string input = "../input/day_02_input"; 9 | if (argc > 1) { 10 | input = argv[1]; 11 | } 12 | 13 | std::string line; 14 | std::fstream file(input); 15 | 16 | int score = 0; 17 | while(std::getline(file, line)) { 18 | // Account for CRLF if required 19 | // line.erase(std::remove_if(std::begin(line), std::end(line), [](auto c) { return !isprint(c); }), std::end(line)); 20 | if (line[2] == 'X') { 21 | score += (line[0] - 'A' - 1 + 3) % 3 + 1; 22 | } else if (line[2] == 'Y') { 23 | score += 3 + line[0] - 'A' + 1; 24 | } else { 25 | score += 6 + (line[0] - 'A' + 1) % 3 + 1; 26 | } 27 | } 28 | std::cout << score << '\n'; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /2022/cpp/day_03b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | // Can use the same method as 3a, but with an & for the 2nd comparison instead of | 8 | 9 | int main(int argc, char * argv[]) { 10 | std::string input = "../input/day_03_input"; 11 | if (argc > 1) { 12 | input = argv[1]; 13 | } 14 | 15 | std::string line; 16 | std::fstream file(input); 17 | 18 | int sum = 0; 19 | std::array counter; 20 | std::fill(std::begin(counter), std::end(counter), 0); 21 | while(std::getline(file, line)) { 22 | // Account for CRLF if required 23 | // line.erase(std::remove_if(std::begin(line), std::end(line), [](auto c) { return !isprint(c); }), std::end(line)); 24 | std::sort(std::begin(line), std::end(line)); 25 | line.erase(std::unique(std::begin(line), std::end(line)), std::end(line)); 26 | for (const auto c : line) { 27 | counter[c - 'A'] += 1; 28 | if (counter[c - 'A'] == 3) { 29 | if (c >= 'a') { 30 | sum += c - 'a' + 1; 31 | } else { 32 | sum += c - 'A' + 1 + 26; 33 | } 34 | std::fill(std::begin(counter), std::end(counter), 0); 35 | break; 36 | } 37 | } 38 | } 39 | std::cout << sum << '\n'; 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /2022/cpp/day_04a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | std::tuple split(const std::string& str, const char delim) { 7 | const auto delim_i = str.find(delim); 8 | const auto s1 = str.substr(0, delim_i); 9 | const auto s2 = str.substr(delim_i + 1, str.size() - delim_i); 10 | return {s1, s2}; 11 | } 12 | 13 | std::tuple split_with_int(const std::string& str, const char delim) { 14 | const auto [s1, s2] = split(str, delim); 15 | return {std::stoi(s1), std::stoi(s2)}; 16 | } 17 | 18 | int main(int argc, char * argv[]) { 19 | std::string input = "../input/day_04_input"; 20 | if (argc > 1) { 21 | input = argv[1]; 22 | } 23 | 24 | std::string line; 25 | std::fstream file(input); 26 | int total = 0; 27 | while(std::getline(file, line)) { 28 | // Account for CRLF if required 29 | // line.erase(std::remove_if(std::begin(line), std::end(line), [](auto c) { return !isprint(c); }), std::end(line)); 30 | const auto [e1, e2] = split(line, ','); 31 | const auto [min_1, max_1] = split_with_int(e1, '-'); 32 | const auto [min_2, max_2] = split_with_int(e2, '-'); 33 | if ((min_1 >= min_2 && max_1 <= max_2) || 34 | (min_1 <= min_2 && max_1 >= max_2)) { 35 | total += 1; 36 | } 37 | } 38 | std::cout << total << '\n'; 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /2022/cpp/day_04b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | std::tuple split(const std::string& str, const char delim) { 7 | const auto delim_i = str.find(delim); 8 | const auto s1 = str.substr(0, delim_i); 9 | const auto s2 = str.substr(delim_i + 1, str.size() - delim_i); 10 | return {s1, s2}; 11 | } 12 | 13 | std::tuple split_with_int(const std::string& str, const char delim) { 14 | const auto [s1, s2] = split(str, delim); 15 | return {std::stoi(s1), std::stoi(s2)}; 16 | } 17 | 18 | int main(int argc, char * argv[]) { 19 | std::string input = "../input/day_04_input"; 20 | if (argc > 1) { 21 | input = argv[1]; 22 | } 23 | 24 | std::string line; 25 | std::fstream file(input); 26 | int total = 0; 27 | while(std::getline(file, line)) { 28 | // Account for CRLF if required 29 | // line.erase(std::remove_if(std::begin(line), std::end(line), [](auto c) { return !isprint(c); }), std::end(line)); 30 | const auto [e1, e2] = split(line, ','); 31 | const auto [min_1, max_1] = split_with_int(e1, '-'); 32 | const auto [min_2, max_2] = split_with_int(e2, '-'); 33 | if ((min_1 >= min_2 && min_1 <= max_2) || 34 | (min_1 <= min_2 && max_1 >= min_2)) { 35 | total += 1; 36 | } 37 | } 38 | std::cout << total << '\n'; 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /2022/cpp/day_06a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char * argv[]) { 7 | std::string input = "../input/day_06_input"; 8 | if (argc > 1) { 9 | input = argv[1]; 10 | } 11 | 12 | std::string line; 13 | std::fstream file(input); 14 | std::getline(file, line); 15 | 16 | constexpr int n = 4; 17 | int count = 0; 18 | std::array counter = {}; 19 | // ALWAYS initialize std::array. 20 | 21 | for (int i = 0; i < n - 1; i++) { 22 | if (counter[line[i] - 'a'] == 0) count++; 23 | counter[line[i] - 'a'] += 1; 24 | } 25 | for (int i = n - 1; i < line.size(); i++) { 26 | if (counter[line[i] - 'a'] == 0) count++; 27 | counter[line[i] - 'a'] += 1; 28 | if (count == n) { 29 | std::cout << i + 1 << '\n'; 30 | break; 31 | } 32 | counter[line[i- n + 1] - 'a'] -= 1; 33 | if (counter[line[i- n + 1] - 'a'] == 0) { 34 | count--; 35 | } 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /2022/cpp/day_06b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char * argv[]) { 7 | std::string input = "../input/day_06_input"; 8 | if (argc > 1) { 9 | input = argv[1]; 10 | } 11 | 12 | std::string line; 13 | std::fstream file(input); 14 | std::getline(file, line); 15 | 16 | constexpr int n = 14; 17 | int count = 0; 18 | std::array counter = {}; 19 | // ALWAYS initialize std::array. 20 | 21 | for (int i = 0; i < n - 1; i++) { 22 | if (counter[line[i] - 'a'] == 0) count++; 23 | counter[line[i] - 'a'] += 1; 24 | } 25 | for (int i = n - 1; i < line.size(); i++) { 26 | if (counter[line[i] - 'a'] == 0) count++; 27 | counter[line[i] - 'a'] += 1; 28 | if (count == n) { 29 | std::cout << i + 1 << '\n'; 30 | break; 31 | } 32 | counter[line[i- n + 1] - 'a'] -= 1; 33 | if (counter[line[i- n + 1] - 'a'] == 0) { 34 | count--; 35 | } 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /2022/cpp/day_10a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | class CommSystem { 6 | public: 7 | void noop() { 8 | tick(); 9 | }; 10 | 11 | void addx(const int val) { 12 | tick(); 13 | tick(); 14 | X += val; 15 | } 16 | 17 | long long get_signal_strength() { 18 | return signal_strength; 19 | } 20 | 21 | private: 22 | 23 | void tick() { 24 | cycle_count++; 25 | if ((cycle_count - 20) % 40 == 0) { 26 | signal_strength += cycle_count * X; 27 | } 28 | } 29 | 30 | long long X = 1; 31 | long long cycle_count = 0; 32 | long long signal_strength = 0; 33 | }; 34 | 35 | 36 | int main(int argc, char * argv[]) { 37 | std::string input = "../input/day_10_input"; 38 | if (argc > 1) { 39 | input = argv[1]; 40 | } 41 | 42 | std::string line; 43 | std::fstream file(input); 44 | 45 | CommSystem cs; 46 | 47 | while(std::getline(file, line)) { 48 | // std::cout << line << '\n'; 49 | const auto space = line.find(' '); 50 | const auto instr = line.substr(0, space); 51 | if (instr == "noop") { 52 | cs.noop(); 53 | } else if (instr == "addx") { 54 | cs.addx(std::stoi(line.substr(space + 1, line.size() - space - 1))); 55 | } 56 | } 57 | 58 | std::cout << cs.get_signal_strength() << '\n'; 59 | 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /2022/sample_input/day_01_sample_input: -------------------------------------------------------------------------------- 1 | 1000 2 | 2000 3 | 3000 4 | 5 | 4000 6 | 7 | 5000 8 | 6000 9 | 10 | 7000 11 | 8000 12 | 9000 13 | 14 | 10000 15 | -------------------------------------------------------------------------------- /2022/sample_input/day_02_sample_input: -------------------------------------------------------------------------------- 1 | A Y 2 | B X 3 | C Z 4 | -------------------------------------------------------------------------------- /2022/sample_input/day_03_sample_input: -------------------------------------------------------------------------------- 1 | vJrwpWtwJgWrhcsFMMfFFhFp 2 | jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL 3 | PmmdzqPrVvPwwTWBwg 4 | wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn 5 | ttgJtRGJQctTZtZT 6 | CrZsJsPPZsGzwwsLwLmpwMDw 7 | -------------------------------------------------------------------------------- /2022/sample_input/day_04_sample_input: -------------------------------------------------------------------------------- 1 | 2-4,6-8 2 | 2-3,4-5 3 | 5-7,7-9 4 | 2-8,3-7 5 | 6-6,4-6 6 | 2-6,4-8 7 | -------------------------------------------------------------------------------- /2022/sample_input/day_05_sample_input: -------------------------------------------------------------------------------- 1 | [D] 2 | [N] [C] 3 | [Z] [M] [P] 4 | 1 2 3 5 | 6 | move 1 from 2 to 1 7 | move 3 from 1 to 3 8 | move 2 from 2 to 1 9 | move 1 from 1 to 2 10 | -------------------------------------------------------------------------------- /2022/sample_input/day_06_sample_input: -------------------------------------------------------------------------------- 1 | mjqjpqmgbljsphdztnvjfqwrcgsmlb 2 | bvwbjplbgvbhsrlpgdmjqwftvncz 3 | nppdvjthqldpwncqszvftbrmjlhg 4 | nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg 5 | zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw 6 | -------------------------------------------------------------------------------- /2022/sample_input/day_07_sample_input: -------------------------------------------------------------------------------- 1 | $ cd / 2 | $ ls 3 | dir a 4 | 14848514 b.txt 5 | 8504156 c.dat 6 | dir d 7 | $ cd a 8 | $ ls 9 | dir e 10 | 29116 f 11 | 2557 g 12 | 62596 h.lst 13 | $ cd e 14 | $ ls 15 | 584 i 16 | $ cd .. 17 | $ cd .. 18 | $ cd d 19 | $ ls 20 | 4060174 j 21 | 8033020 d.log 22 | 5626152 d.ext 23 | 7214296 k 24 | -------------------------------------------------------------------------------- /2022/sample_input/day_08_sample_input: -------------------------------------------------------------------------------- 1 | 30373 2 | 25512 3 | 65332 4 | 33549 5 | 35390 6 | -------------------------------------------------------------------------------- /2022/sample_input/day_09_sample_input: -------------------------------------------------------------------------------- 1 | R 4 2 | U 4 3 | L 3 4 | D 1 5 | R 4 6 | D 1 7 | L 5 8 | R 2 9 | 10 | R 5 11 | U 8 12 | L 8 13 | D 3 14 | R 17 15 | D 10 16 | L 25 17 | U 20 18 | -------------------------------------------------------------------------------- /2022/sample_input/day_11_sample_input: -------------------------------------------------------------------------------- 1 | Monkey 0: 2 | Starting items: 79, 98 3 | Operation: new = old * 19 4 | Test: divisible by 23 5 | If true: throw to monkey 2 6 | If false: throw to monkey 3 7 | 8 | Monkey 1: 9 | Starting items: 54, 65, 75, 74 10 | Operation: new = old + 6 11 | Test: divisible by 19 12 | If true: throw to monkey 2 13 | If false: throw to monkey 0 14 | 15 | Monkey 2: 16 | Starting items: 79, 60, 97 17 | Operation: new = old * old 18 | Test: divisible by 13 19 | If true: throw to monkey 1 20 | If false: throw to monkey 3 21 | 22 | Monkey 3: 23 | Starting items: 74 24 | Operation: new = old + 3 25 | Test: divisible by 17 26 | If true: throw to monkey 0 27 | If false: throw to monkey 1 28 | -------------------------------------------------------------------------------- /2022/sample_input/day_12_sample_input: -------------------------------------------------------------------------------- 1 | Sabqponm 2 | abcryxxl 3 | accszExk 4 | acctuvwj 5 | abdefghi 6 | -------------------------------------------------------------------------------- /2022/sample_input/day_13_sample_input: -------------------------------------------------------------------------------- 1 | [1,1,3,1,1] 2 | [1,1,5,1,1] 3 | 4 | [[1],[2,3,4]] 5 | [[1],4] 6 | 7 | [9] 8 | [[8,7,6]] 9 | 10 | [[4,4],4,4] 11 | [[4,4],4,4,4] 12 | 13 | [7,7,7,7] 14 | [7,7,7] 15 | 16 | [] 17 | [3] 18 | 19 | [[[]]] 20 | [[]] 21 | 22 | [1,[2,[3,[4,[5,6,7]]]],8,9] 23 | [1,[2,[3,[4,[5,6,0]]]],8,9] 24 | -------------------------------------------------------------------------------- /2022/sample_input/day_14_sample_input: -------------------------------------------------------------------------------- 1 | 498,4 -> 498,6 -> 496,6 2 | 503,4 -> 502,4 -> 502,9 -> 494,9 3 | -------------------------------------------------------------------------------- /2022/sample_input/day_15_sample_input: -------------------------------------------------------------------------------- 1 | Sensor at x=2, y=18: closest beacon is at x=-2, y=15 2 | Sensor at x=9, y=16: closest beacon is at x=10, y=16 3 | Sensor at x=13, y=2: closest beacon is at x=15, y=3 4 | Sensor at x=12, y=14: closest beacon is at x=10, y=16 5 | Sensor at x=10, y=20: closest beacon is at x=10, y=16 6 | Sensor at x=14, y=17: closest beacon is at x=10, y=16 7 | Sensor at x=8, y=7: closest beacon is at x=2, y=10 8 | Sensor at x=2, y=0: closest beacon is at x=2, y=10 9 | Sensor at x=0, y=11: closest beacon is at x=2, y=10 10 | Sensor at x=20, y=14: closest beacon is at x=25, y=17 11 | Sensor at x=17, y=20: closest beacon is at x=21, y=22 12 | Sensor at x=16, y=7: closest beacon is at x=15, y=3 13 | Sensor at x=14, y=3: closest beacon is at x=15, y=3 14 | Sensor at x=20, y=1: closest beacon is at x=15, y=3 15 | -------------------------------------------------------------------------------- /2022/sample_input/day_16_sample_input: -------------------------------------------------------------------------------- 1 | Valve AA has flow rate=0; tunnels lead to valves DD, II, BB 2 | Valve BB has flow rate=13; tunnels lead to valves CC, AA 3 | Valve CC has flow rate=2; tunnels lead to valves DD, BB 4 | Valve DD has flow rate=20; tunnels lead to valves CC, AA, EE 5 | Valve EE has flow rate=3; tunnels lead to valves FF, DD 6 | Valve FF has flow rate=0; tunnels lead to valves EE, GG 7 | Valve GG has flow rate=0; tunnels lead to valves FF, HH 8 | Valve HH has flow rate=22; tunnel leads to valve GG 9 | Valve II has flow rate=0; tunnels lead to valves AA, JJ 10 | Valve JJ has flow rate=21; tunnel leads to valve II 11 | -------------------------------------------------------------------------------- /2022/sample_input/day_17_sample_input: -------------------------------------------------------------------------------- 1 | >>><<><>><<<>><>>><<<>>><<<><<<>><>><<>> 2 | -------------------------------------------------------------------------------- /2022/sample_input/day_18_sample_input: -------------------------------------------------------------------------------- 1 | 2,2,2 2 | 1,2,2 3 | 3,2,2 4 | 2,1,2 5 | 2,3,2 6 | 2,2,1 7 | 2,2,3 8 | 2,2,4 9 | 2,2,6 10 | 1,2,5 11 | 3,2,5 12 | 2,1,5 13 | 2,3,5 14 | -------------------------------------------------------------------------------- /2022/sample_input/day_19_sample_input: -------------------------------------------------------------------------------- 1 | Blueprint 1: Each ore robot costs 4 ore. Each clay robot costs 2 ore. Each obsidian robot costs 3 ore and 14 clay. Each geode robot costs 2 ore and 7 obsidian. 2 | Blueprint 2: Each ore robot costs 2 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 8 clay. Each geode robot costs 3 ore and 12 obsidian. 3 | -------------------------------------------------------------------------------- /2022/sample_input/day_20_sample_input: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | -3 4 | 3 5 | -2 6 | 0 7 | 4 8 | -------------------------------------------------------------------------------- /2022/sample_input/day_21_sample_input: -------------------------------------------------------------------------------- 1 | root: pppw + sjmn 2 | dbpl: 5 3 | cczh: sllz + lgvd 4 | zczc: 2 5 | ptdq: humn - dvpt 6 | dvpt: 3 7 | lfqf: 4 8 | humn: 5 9 | ljgn: 2 10 | sjmn: drzm * dbpl 11 | sllz: 4 12 | pppw: cczh / lfqf 13 | lgvd: ljgn * ptdq 14 | drzm: hmdt - zczc 15 | hmdt: 32 16 | -------------------------------------------------------------------------------- /2022/sample_input/day_22_sample_input: -------------------------------------------------------------------------------- 1 | ...# 2 | .#.. 3 | #... 4 | .... 5 | ...#.......# 6 | ........#... 7 | ..#....#.... 8 | ..........#. 9 | ...#.... 10 | .....#.. 11 | .#...... 12 | ......#. 13 | 14 | 10R5L5R10L4R5L5 15 | -------------------------------------------------------------------------------- /2022/sample_input/day_23_sample_input: -------------------------------------------------------------------------------- 1 | .............. 2 | .............. 3 | .......#...... 4 | .....###.#.... 5 | ...#...#.#.... 6 | ....#...##.... 7 | ...#.###...... 8 | ...##.#.##.... 9 | ....#..#...... 10 | .............. 11 | .............. 12 | .............. -------------------------------------------------------------------------------- /2022/sample_input/day_24_sample_input: -------------------------------------------------------------------------------- 1 | #.###### 2 | #>>.<^<# 3 | #.<..<<# 4 | #>v.><># 5 | #<^v^^># 6 | ######.# -------------------------------------------------------------------------------- /2022/sample_input/day_25_sample_input: -------------------------------------------------------------------------------- 1 | 1=-0-2 2 | 12111 3 | 2=0= 4 | 21 5 | 2=01 6 | 111 7 | 20012 8 | 112 9 | 1=-1= 10 | 1-12 11 | 12 12 | 1= 13 | 122 -------------------------------------------------------------------------------- /2023/cpp/day_01a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char * argv[]) { 8 | std::string input = "../input/day_01_input"; 9 | if (argc > 1) { 10 | input = argv[1]; 11 | } 12 | 13 | std::string line; 14 | std::fstream file(input); 15 | 16 | std::vector calibration_values; 17 | while(std::getline(file, line)) { 18 | std::vector digits; 19 | for (int i = 0; i < line.size(); i++) { 20 | const auto c = line[i]; 21 | if (c >= '0' && c <= '9') { 22 | digits.push_back(c-'0'); 23 | } 24 | } 25 | calibration_values.push_back(digits[0] * 10 + digits.back()); 26 | } 27 | 28 | const auto sum = std::accumulate(std::begin(calibration_values), std::end(calibration_values), 0); 29 | std::cout << sum << '\n'; 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /2023/cpp/day_01b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char * argv[]) { 8 | std::string input = "../input/day_01_input"; 9 | if (argc > 1) { 10 | input = argv[1]; 11 | } 12 | 13 | std::string line; 14 | std::fstream file(input); 15 | 16 | std::vector numbers {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; 17 | 18 | std::vector calibration_values; 19 | while(std::getline(file, line)) { 20 | std::vector digits; 21 | for (int i = 0; i < line.size(); i++) { 22 | const auto c = line[i]; 23 | if (c >= '0' && c <= '9') { 24 | digits.push_back(c - '0'); 25 | } 26 | for (int j = 0; j < numbers.size(); j++) { 27 | const auto& n = numbers[j]; 28 | if (line.size() >= i + n.size()) { 29 | if (line.substr(i, n.size()) == n) { 30 | digits.push_back(j+1); 31 | } 32 | } 33 | } 34 | } 35 | calibration_values.push_back(digits[0] * 10 + digits.back()); 36 | } 37 | 38 | 39 | const auto sum = std::accumulate(std::begin(calibration_values), std::end(calibration_values), 0); 40 | std::cout << sum << '\n'; 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /2023/cpp/day_08a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int main(int argc, char * argv[]) { 10 | std::string input = "../input/day_08_input"; 11 | if (argc > 1) { 12 | input = argv[1]; 13 | } 14 | 15 | std::string line; 16 | std::fstream file(input); 17 | 18 | std::string instructions; 19 | std::getline(file, instructions); 20 | std::unordered_map> map; 21 | const std::regex mask_pattern(R"(([A-Z]+) = \(([A-Z]+), ([A-Z]+)\))"); 22 | std::smatch mask_match; 23 | while(std::getline(file, line)) { 24 | std::regex_search(line, mask_match, mask_pattern); 25 | map[mask_match[1]] = {{mask_match[2], mask_match[3]}}; 26 | } 27 | 28 | std::string current = "AAA"; 29 | int idx = 0; 30 | std::size_t n_steps = 0; 31 | while (current != "ZZZ") { 32 | if (instructions[idx] == 'L') { 33 | current = map[current][0]; 34 | } else { 35 | current = map[current][1]; 36 | } 37 | idx++; 38 | n_steps++; 39 | if (idx == instructions.size()) { 40 | idx = 0; 41 | } 42 | } 43 | std::cout << n_steps << '\n'; 44 | return 0; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /2023/cpp/day_15a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int calculate_hash(const std::string& line) { 10 | int value = 0; 11 | for (const auto c : line) { 12 | value += int(c); 13 | value *= 17; 14 | value %= 256; 15 | } 16 | return value; 17 | } 18 | 19 | std::vector parse(const std::string& s) { 20 | std::vector substrs; 21 | std::size_t start = 0; 22 | std::size_t end = s.find(',', start); 23 | while (end != std::string::npos) { 24 | substrs.push_back(s.substr(start, end - start)); 25 | start = end + 1; 26 | end = s.find(',', start); 27 | } 28 | substrs.push_back(s.substr(start, s.size() - start)); 29 | return substrs; 30 | } 31 | 32 | int main(int argc, char * argv[]) { 33 | std::string input = "../input/day_15_input"; 34 | if (argc > 1) { 35 | input = argv[1]; 36 | } 37 | 38 | std::string line; 39 | std::fstream file(input); 40 | std::getline(file, line); 41 | std::size_t total = 0; 42 | for (const auto& substr : parse(line)) { 43 | total += calculate_hash(substr); 44 | } 45 | std::cout << total << '\n'; 46 | return 0; 47 | } -------------------------------------------------------------------------------- /2023/sample_input/day_01_sample_input: -------------------------------------------------------------------------------- 1 | 1abc2 2 | pqr3stu8vwx 3 | a1b2c3d4e5f 4 | treb7uchet 5 | 6 | two1nine 7 | eightwothree 8 | abcone2threexyz 9 | xtwone3four 10 | 4nineeightseven2 11 | zoneight234 12 | 7pqrstsixteen -------------------------------------------------------------------------------- /2023/sample_input/day_02_sample_input: -------------------------------------------------------------------------------- 1 | Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green 2 | Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue 3 | Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red 4 | Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red 5 | Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green -------------------------------------------------------------------------------- /2023/sample_input/day_03_sample_input: -------------------------------------------------------------------------------- 1 | 467..114.. 2 | ...*...... 3 | ..35..633. 4 | ......#... 5 | 617*...... 6 | .....+.58. 7 | ..592..... 8 | ......755. 9 | ...$.*.... 10 | .664.598.. -------------------------------------------------------------------------------- /2023/sample_input/day_04_sample_input: -------------------------------------------------------------------------------- 1 | Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53 2 | Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19 3 | Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1 4 | Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83 5 | Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36 6 | Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11 -------------------------------------------------------------------------------- /2023/sample_input/day_05_sample_input: -------------------------------------------------------------------------------- 1 | seeds: 79 14 55 13 2 | 3 | seed-to-soil map: 4 | 50 98 2 5 | 52 50 48 6 | 7 | soil-to-fertilizer map: 8 | 0 15 37 9 | 37 52 2 10 | 39 0 15 11 | 12 | fertilizer-to-water map: 13 | 49 53 8 14 | 0 11 42 15 | 42 0 7 16 | 57 7 4 17 | 18 | water-to-light map: 19 | 88 18 7 20 | 18 25 70 21 | 22 | light-to-temperature map: 23 | 45 77 23 24 | 81 45 19 25 | 68 64 13 26 | 27 | temperature-to-humidity map: 28 | 0 69 1 29 | 1 0 69 30 | 31 | humidity-to-location map: 32 | 60 56 37 33 | 56 93 4 -------------------------------------------------------------------------------- /2023/sample_input/day_06_sample_input: -------------------------------------------------------------------------------- 1 | Time: 7 15 30 2 | Distance: 9 40 200 -------------------------------------------------------------------------------- /2023/sample_input/day_07_sample_input: -------------------------------------------------------------------------------- 1 | 32T3K 765 2 | T55J5 684 3 | KK677 28 4 | KTJJT 220 5 | QQQJA 483 -------------------------------------------------------------------------------- /2023/sample_input/day_08_sample_input: -------------------------------------------------------------------------------- 1 | LR 2 | 3 | 11A = (11B, XXX) 4 | 11B = (XXX, 11Z) 5 | 11Z = (11B, XXX) 6 | 22A = (22B, XXX) 7 | 22B = (22C, 22C) 8 | 22C = (22Z, 22Z) 9 | 22Z = (22B, 22B) 10 | XXX = (XXX, XXX) 11 | -------------------------------------------------------------------------------- /2023/sample_input/day_09_sample_input: -------------------------------------------------------------------------------- 1 | 0 3 6 9 12 15 2 | 1 3 6 10 15 21 3 | 10 13 16 21 30 45 4 | -------------------------------------------------------------------------------- /2023/sample_input/day_10_sample_input: -------------------------------------------------------------------------------- 1 | ........... 2 | .S-------7. 3 | .|F-----7|. 4 | .||.....||. 5 | .||.....||. 6 | .|L-7.F-J|. 7 | .|..|.|..|. 8 | .L--J.L--J. 9 | ........... 10 | 11 | .......... 12 | .S------7. 13 | .|F----7|. 14 | .||....||. 15 | .||....||. 16 | .|L-7F-J|. 17 | .|..||..|. 18 | .L--JL--J. 19 | .......... 20 | 21 | .F----7F7F7F7F-7.... 22 | .|F--7||||||||FJ.... 23 | .||.FJ||||||||L7.... 24 | FJL7L7LJLJ||LJ.L-7.. 25 | L--J.L7...LJS7F-7L7. 26 | ....F-J..F7FJ|L7L7L7 27 | ....L7.F7||L7|.L7L7| 28 | .....|FJLJ|FJ|F7|.LJ 29 | ....FJL-7.||.||||... 30 | ....L---J.LJ.LJLJ... 31 | 32 | FF7FSF7F7F7F7F7F---7 33 | L|LJ||||||||||||F--J 34 | FL-7LJLJ||||||LJL-77 35 | F--JF--7||LJLJ7F7FJ- 36 | L---JF-JLJ.||-FJLJJ7 37 | |F|F-JF---7F7-L7L|7| 38 | |FFJF7L7F-JF7|JL---7 39 | 7-L-JL7||F7|L7F-7F7| 40 | L.L7LFJ|||||FJL7||LJ 41 | L7JLJL-JLJLJL--JLJ.L 42 | -------------------------------------------------------------------------------- /2023/sample_input/day_11_sample_input: -------------------------------------------------------------------------------- 1 | ...#...... 2 | .......#.. 3 | #......... 4 | .......... 5 | ......#... 6 | .#........ 7 | .........# 8 | .......... 9 | .......#.. 10 | #...#..... -------------------------------------------------------------------------------- /2023/sample_input/day_12_sample_input: -------------------------------------------------------------------------------- 1 | ???.### 1,1,3 2 | .??..??...?##. 1,1,3 3 | ?#?#?#?#?#?#?#? 1,3,1,6 4 | ????.#...#... 4,1,1 5 | ????.######..#####. 1,6,5 6 | ?###???????? 3,2,1 -------------------------------------------------------------------------------- /2023/sample_input/day_13_sample_input: -------------------------------------------------------------------------------- 1 | #.##..##. 2 | ..#.##.#. 3 | ##......# 4 | ##......# 5 | ..#.##.#. 6 | ..##..##. 7 | #.#.##.#. 8 | 9 | #...##..# 10 | #....#..# 11 | ..##..### 12 | #####.##. 13 | #####.##. 14 | ..##..### 15 | #....#..# 16 | -------------------------------------------------------------------------------- /2023/sample_input/day_14_sample_input: -------------------------------------------------------------------------------- 1 | O....#.... 2 | O.OO#....# 3 | .....##... 4 | OO.#O....O 5 | .O.....O#. 6 | O.#..O.#.# 7 | ..O..#O..O 8 | .......O.. 9 | #....###.. 10 | #OO..#.... 11 | -------------------------------------------------------------------------------- /2023/sample_input/day_15_sample_input: -------------------------------------------------------------------------------- 1 | rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7 2 | -------------------------------------------------------------------------------- /2023/sample_input/day_16_sample_input: -------------------------------------------------------------------------------- 1 | .|...\.... 2 | |.-.\..... 3 | .....|-... 4 | ........|. 5 | .......... 6 | .........\ 7 | ..../.\\.. 8 | .-.-/..|.. 9 | .|....-|.\ 10 | ..//.|.... 11 | -------------------------------------------------------------------------------- /2023/sample_input/day_17_sample_input: -------------------------------------------------------------------------------- 1 | 2413432311323 2 | 3215453535623 3 | 3255245654254 4 | 3446585845452 5 | 4546657867536 6 | 1438598798454 7 | 4457876987766 8 | 3637877979653 9 | 4654967986887 10 | 4564679986453 11 | 1224686865563 12 | 2546548887735 13 | 4322674655533 14 | -------------------------------------------------------------------------------- /2023/sample_input/day_18_sample_input: -------------------------------------------------------------------------------- 1 | R 6 (#70c710) 2 | D 5 (#0dc571) 3 | L 2 (#5713f0) 4 | D 2 (#d2c081) 5 | R 2 (#59c680) 6 | D 2 (#411b91) 7 | L 5 (#8ceee2) 8 | U 2 (#caa173) 9 | L 1 (#1b58a2) 10 | U 2 (#caa171) 11 | R 2 (#7807d2) 12 | U 3 (#a77fa3) 13 | L 2 (#015232) 14 | U 2 (#7a21e3) -------------------------------------------------------------------------------- /2023/sample_input/day_19_sample_input: -------------------------------------------------------------------------------- 1 | px{a<2006:qkq,m>2090:A,rfg} 2 | pv{a>1716:R,A} 3 | lnx{m>1548:A,A} 4 | rfg{s<537:gd,x>2440:R,A} 5 | qs{s>3448:A,lnx} 6 | qkq{x<1416:A,crn} 7 | crn{x>2662:A,R} 8 | in{s<1351:px,qqz} 9 | qqz{s>2770:qs,m<1801:hdj,R} 10 | gd{a>3333:R,R} 11 | hdj{m>838:A,pv} 12 | 13 | {x=787,m=2655,a=1222,s=2876} 14 | {x=1679,m=44,a=2067,s=496} 15 | {x=2036,m=264,a=79,s=2244} 16 | {x=2461,m=1339,a=466,s=291} 17 | {x=2127,m=1623,a=2188,s=1013} 18 | -------------------------------------------------------------------------------- /2023/sample_input/day_20_sample_input: -------------------------------------------------------------------------------- 1 | broadcaster -> a, b, c 2 | %a -> b 3 | %b -> c 4 | %c -> inv 5 | &inv -> a -------------------------------------------------------------------------------- /2023/sample_input/day_21_sample_input: -------------------------------------------------------------------------------- 1 | ........... 2 | .....###.#. 3 | .###.##..#. 4 | ..#.#...#.. 5 | ....#.#.... 6 | .##..S####. 7 | .##..#...#. 8 | .......##.. 9 | .##.#.####. 10 | .##..##.##. 11 | ........... -------------------------------------------------------------------------------- /2023/sample_input/day_22_sample_input: -------------------------------------------------------------------------------- 1 | 1,0,1~1,2,1 2 | 0,0,2~2,0,2 3 | 0,2,3~2,2,3 4 | 0,0,4~0,2,4 5 | 2,0,5~2,2,5 6 | 0,1,6~2,1,6 7 | 1,1,8~1,1,9 8 | -------------------------------------------------------------------------------- /2023/sample_input/day_23_sample_input: -------------------------------------------------------------------------------- 1 | #.##################### 2 | #.......#########...### 3 | #######.#########.#.### 4 | ###.....#.>.>.###.#.### 5 | ###v#####.#v#.###.#.### 6 | ###.>...#.#.#.....#...# 7 | ###v###.#.#.#########.# 8 | ###...#.#.#.......#...# 9 | #####.#.#.#######.#.### 10 | #.....#.#.#.......#...# 11 | #.#####.#.#.#########v# 12 | #.#...#...#...###...>.# 13 | #.#.#v#######v###.###v# 14 | #...#.>.#...>.>.#.###.# 15 | #####v#.#.###v#.#.###.# 16 | #.....#...#...#.#.#...# 17 | #.#########.###.#.#.### 18 | #...###...#...#...#.### 19 | ###.###.#.###v#####v### 20 | #...#...#.#.>.>.#.>.### 21 | #.###.###.#.###.#.#v### 22 | #.....###...###...#...# 23 | #####################.# -------------------------------------------------------------------------------- /2023/sample_input/day_24_sample_input: -------------------------------------------------------------------------------- 1 | 19, 13, 30 @ -2, 1, -2 2 | 18, 19, 22 @ -1, -1, -2 3 | 20, 25, 34 @ -2, -2, -4 4 | 12, 31, 28 @ -1, -2, -1 5 | 20, 19, 15 @ 1, -5, -3 6 | -------------------------------------------------------------------------------- /2023/sample_input/day_25_sample_input: -------------------------------------------------------------------------------- 1 | jqt: rhn xhk nvd 2 | rsh: frs pzl lsr 3 | xhk: hfx 4 | cmg: qnr nvd lhk bvb 5 | rhn: xhk bvb hfx 6 | bvb: xhk hfx 7 | pzl: lsr hfx nvd 8 | qnr: nvd 9 | ntq: jqt hfx bvb xhk 10 | nvd: lhk 11 | lsr: lhk 12 | rzs: qnr cmg lsr rsh 13 | frs: qnr lhk lsr 14 | -------------------------------------------------------------------------------- /2024/cpp/day_01a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char* argv[]) 9 | { 10 | std::string input = "../input/day_01_input"; 11 | if (argc > 1) { 12 | input = argv[1]; 13 | } 14 | 15 | std::ifstream file(input); 16 | std::string line; 17 | std::vector l1; 18 | std::vector l2; 19 | while(std::getline(file, line)) { 20 | std::size_t space_idx = line.find(' '); 21 | l1.push_back(std::stoi(line.substr(0, space_idx))); 22 | l2.push_back(std::stoi(line.substr(space_idx + 1, line.size() - space_idx - 1))); 23 | } 24 | std::ranges::sort(l1); 25 | std::ranges::sort(l2); 26 | long long sum = 0; 27 | for (const auto& [n1, n2] : std::views::zip(l1, l2)) { 28 | sum += std::abs(n1 - n2); 29 | } 30 | std::cout << sum << '\n'; 31 | return 0; 32 | } -------------------------------------------------------------------------------- /2024/cpp/day_01b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int main(int argc, char* argv[]) 10 | { 11 | std::string input = "../input/day_01_input"; 12 | if (argc > 1) { 13 | input = argv[1]; 14 | } 15 | 16 | std::ifstream file(input); 17 | std::string line; 18 | std::vector l1; 19 | std::unordered_map l2; 20 | while(std::getline(file, line)) { 21 | std::size_t space_idx = line.find(' '); 22 | l1.push_back(std::stoi(line.substr(0, space_idx))); 23 | l2[std::stoi(line.substr(space_idx + 1, line.size() - space_idx - 1))]++; 24 | } 25 | long long sum = 0; 26 | for (const auto& n1 : l1) { 27 | sum += n1 * l2[n1]; 28 | } 29 | std::cout << sum << '\n'; 30 | return 0; 31 | } -------------------------------------------------------------------------------- /2024/cpp/day_03a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | long long check(const std::string& line, const int idx) { 7 | static constexpr std::string numbers = "0123456789"; 8 | const auto comma_idx = line.find_first_not_of(numbers, idx+1); 9 | if (comma_idx == idx+1 || comma_idx == std::string::npos || line[comma_idx] != ',') return 0; 10 | const auto idx_after_second_number = line.find_first_not_of(numbers, comma_idx+1); 11 | if (idx_after_second_number == comma_idx+1 || idx_after_second_number == std::string::npos || line[idx_after_second_number] != ')') return 0; 12 | return std::stoi(line.substr(idx+1, comma_idx-idx-1)) * std::stoi(line.substr(comma_idx+1, idx_after_second_number-comma_idx-1)); 13 | } 14 | 15 | int main(int argc, char* argv[]) { 16 | std::string input = "../input/day_03_input"; 17 | if (argc > 1) { 18 | input = argv[1]; 19 | } 20 | 21 | std::ifstream file(input); 22 | std::string line; 23 | std::getline(file, line); 24 | 25 | constexpr std::string_view mul = "mul("; 26 | 27 | long long sum = 0; 28 | const auto line_sv = std::string_view(line); 29 | for (int i = 0; i < line.size()-8; i++) { 30 | if (line_sv.substr(i, 4) == mul) { 31 | sum += check(line, i+3); 32 | } 33 | } 34 | std::cout << sum << '\n'; 35 | return 0; 36 | } -------------------------------------------------------------------------------- /2024/cpp/day_04b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int check(const std::vector& map, const int row, const int col) { 8 | int total = 0; 9 | static constexpr std::array move = {1,1}; 10 | if (map[row][col] == 'A' && 11 | ((map[row + move[0]][col + move[1]] == 'M' && map[row - move[0]][col - move[1]] == 'S') || 12 | (map[row - move[0]][col - move[1]] == 'M' && map[row + move[0]][col + move[1]] == 'S')) && 13 | ((map[row + move[0]][col - move[1]] == 'M' && map[row - move[0]][col + move[1]] == 'S') || 14 | (map[row - move[0]][col + move[1]] == 'M' && map[row + move[0]][col - move[1]] == 'S'))) { 15 | total += 1; 16 | } 17 | return total; 18 | } 19 | 20 | int main(int argc, char* argv[]) { 21 | std::string input = "../input/day_04_input"; 22 | if (argc > 1) { 23 | input = argv[1]; 24 | } 25 | 26 | std::ifstream file(input); 27 | std::string line; 28 | std::vector map; 29 | while(std::getline(file, line)) { 30 | map.push_back(line); 31 | } 32 | 33 | int total = 0; 34 | for (int i = 1; i < map.size()-1; i++) { 35 | for (int j = 1; j < map[0].size()-1; j++) { 36 | if (map[i][j] == 'A') { 37 | total += check(map, i, j); 38 | } 39 | } 40 | } 41 | std::cout << total << '\n'; 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /2024/sample_input/day_01_sample_input: -------------------------------------------------------------------------------- 1 | 3 4 2 | 4 3 3 | 2 5 4 | 1 3 5 | 3 9 6 | 3 3 -------------------------------------------------------------------------------- /2024/sample_input/day_02_sample_input: -------------------------------------------------------------------------------- 1 | 7 6 4 2 1 2 | 1 2 7 8 9 3 | 9 7 6 2 1 4 | 1 3 2 4 5 5 | 8 6 4 4 1 6 | 1 3 6 7 9 7 | -------------------------------------------------------------------------------- /2024/sample_input/day_03_sample_input: -------------------------------------------------------------------------------- 1 | xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5)) -------------------------------------------------------------------------------- /2024/sample_input/day_04_sample_input: -------------------------------------------------------------------------------- 1 | MMMSXXMASM 2 | MSAMXMSMSA 3 | AMXSXMAAMM 4 | MSAMASMSMX 5 | XMASAMXAMM 6 | XXAMMXXAMA 7 | SMSMSASXSS 8 | SAXAMASAAA 9 | MAMMMXMMMM 10 | MXMXAXMASX -------------------------------------------------------------------------------- /2024/sample_input/day_05_sample_input: -------------------------------------------------------------------------------- 1 | 47|53 2 | 97|13 3 | 97|61 4 | 97|47 5 | 75|29 6 | 61|13 7 | 75|53 8 | 29|13 9 | 97|29 10 | 53|29 11 | 61|53 12 | 97|53 13 | 61|29 14 | 47|13 15 | 75|47 16 | 97|75 17 | 47|61 18 | 75|61 19 | 47|29 20 | 75|13 21 | 53|13 22 | 23 | 75,47,61,53,29 24 | 97,61,53,29,13 25 | 75,29,13 26 | 75,97,47,61,53 27 | 61,13,29 28 | 97,13,75,29,47 -------------------------------------------------------------------------------- /2024/sample_input/day_06_sample_input: -------------------------------------------------------------------------------- 1 | ....#..... 2 | .........# 3 | .......... 4 | ..#....... 5 | .......#.. 6 | .......... 7 | .#..^..... 8 | ........#. 9 | #......... 10 | ......#... -------------------------------------------------------------------------------- /2024/sample_input/day_07_sample_input: -------------------------------------------------------------------------------- 1 | 190: 10 19 2 | 3267: 81 40 27 3 | 83: 17 5 4 | 156: 15 6 5 | 7290: 6 8 6 15 6 | 161011: 16 10 13 7 | 192: 17 8 14 8 | 21037: 9 7 18 13 9 | 292: 11 6 16 20 -------------------------------------------------------------------------------- /2024/sample_input/day_08_sample_input: -------------------------------------------------------------------------------- 1 | ............ 2 | ........0... 3 | .....0...... 4 | .......0.... 5 | ....0....... 6 | ......A..... 7 | ............ 8 | ............ 9 | ........A... 10 | .........A.. 11 | ............ 12 | ............ -------------------------------------------------------------------------------- /2024/sample_input/day_09_sample_input: -------------------------------------------------------------------------------- 1 | 2333133121414131402 -------------------------------------------------------------------------------- /2024/sample_input/day_10_sample_input: -------------------------------------------------------------------------------- 1 | 89010123 2 | 78121874 3 | 87430965 4 | 96549874 5 | 45678903 6 | 32019012 7 | 01329801 8 | 10456732 -------------------------------------------------------------------------------- /2024/sample_input/day_11_sample_input: -------------------------------------------------------------------------------- 1 | 125 17 -------------------------------------------------------------------------------- /2024/sample_input/day_12_sample_input: -------------------------------------------------------------------------------- 1 | RRRRIICCFF 2 | RRRRIICCCF 3 | VVRRRCCFFF 4 | VVRCCCJFFF 5 | VVVVCJJCFE 6 | VVIVCCJJEE 7 | VVIIICJJEE 8 | MIIIIIJJEE 9 | MIIISIJEEE 10 | MMMISSJEEE -------------------------------------------------------------------------------- /2024/sample_input/day_13_sample_input: -------------------------------------------------------------------------------- 1 | Button A: X+94, Y+34 2 | Button B: X+22, Y+67 3 | Prize: X=8400, Y=5400 4 | 5 | Button A: X+26, Y+66 6 | Button B: X+67, Y+21 7 | Prize: X=12748, Y=12176 8 | 9 | Button A: X+17, Y+86 10 | Button B: X+84, Y+37 11 | Prize: X=7870, Y=6450 12 | 13 | Button A: X+69, Y+23 14 | Button B: X+27, Y+71 15 | Prize: X=18641, Y=10279 -------------------------------------------------------------------------------- /2024/sample_input/day_14_sample_input: -------------------------------------------------------------------------------- 1 | p=0,4 v=3,-3 2 | p=6,3 v=-1,-3 3 | p=10,3 v=-1,2 4 | p=2,0 v=2,-1 5 | p=0,0 v=1,3 6 | p=3,0 v=-2,-2 7 | p=7,6 v=-1,-3 8 | p=3,0 v=-1,-2 9 | p=9,3 v=2,3 10 | p=7,3 v=-1,2 11 | p=2,4 v=2,-3 12 | p=9,5 v=-3,-3 -------------------------------------------------------------------------------- /2024/sample_input/day_15_sample_input: -------------------------------------------------------------------------------- 1 | ########## 2 | #..O..O.O# 3 | #......O.# 4 | #.OO..O.O# 5 | #..O@..O.# 6 | #O#..O...# 7 | #O..O..O.# 8 | #.OO.O.OO# 9 | #....O...# 10 | ########## 11 | 12 | ^v>^vv^v>v<>v^v<<><>>v^v^>^<<<><^ 13 | vvv<<^>^v^^><<>>><>^<<><^vv^^<>vvv<>><^^v>^>vv<>v<<<^<^^>>>^<>vv>v^v^<>><>>>><^^>vv>v<^^^>>v^v^<^^>v^^>v^<^v>v<>>v^v^v^^<^^vv< 15 | <>^^^^>>>v^<>vvv^>^^^vv^^>v<^^^^v<>^>vvvv><>>v^<<^^^^^ 16 | ^><^><>>><>^^<<^^v>>><^^>v>>>^v><>^v><<<>vvvv>^<><<>^>< 17 | ^>><>^v<><^vvv<^^<><^v<<<><<<^^<^>>^<<<^>>^v^>>^v>vv>^<<^v<>><<><<>v<^vv<<<>^^v^>^^>>><<^v>>v^v><^^>>^<>vv^ 19 | <><^^>^^^<>^vv<<^><<><<><<<^^<<<^<<>><<><^^^>^^<>^>v<> 20 | ^^>vv<^v^v^<>^^^>>>^^vvv^>vvv<>>>^<^>>>>>^<<^v>^vvv<>^<>< 21 | v^^>>><<^^<>>^v^v^<<>^<^v^v><^<<<><<^vv>>v>v^<<^ -------------------------------------------------------------------------------- /2024/sample_input/day_16_sample_input: -------------------------------------------------------------------------------- 1 | ################# 2 | #...#...#...#..E# 3 | #.#.#.#.#.#.#.#.# 4 | #.#.#.#...#...#.# 5 | #.#.#.#.###.#.#.# 6 | #...#.#.#.....#.# 7 | #.#.#.#.#.#####.# 8 | #.#...#.#.#.....# 9 | #.#.#####.#.###.# 10 | #.#.#.......#...# 11 | #.#.###.#####.### 12 | #.#.#...#.....#.# 13 | #.#.#.#####.###.# 14 | #.#.#.........#.# 15 | #.#.#.#########.# 16 | #S#.............# 17 | ################# -------------------------------------------------------------------------------- /2024/sample_input/day_17_sample_input: -------------------------------------------------------------------------------- 1 | Register A: 729 2 | Register B: 0 3 | Register C: 0 4 | 5 | Program: 0,1,5,4,3,0 -------------------------------------------------------------------------------- /2024/sample_input/day_18_sample_input: -------------------------------------------------------------------------------- 1 | 5,4 2 | 4,2 3 | 4,5 4 | 3,0 5 | 2,1 6 | 6,3 7 | 2,4 8 | 1,5 9 | 0,6 10 | 3,3 11 | 2,6 12 | 5,1 13 | 1,2 14 | 5,5 15 | 2,5 16 | 6,5 17 | 1,4 18 | 0,4 19 | 6,4 20 | 1,1 21 | 6,1 22 | 1,0 23 | 0,5 24 | 1,6 25 | 2,0 -------------------------------------------------------------------------------- /2024/sample_input/day_19_sample_input: -------------------------------------------------------------------------------- 1 | r, wr, b, g, bwu, rb, gb, br 2 | 3 | brwrr 4 | bggr 5 | gbbr 6 | rrbgbr 7 | ubwu 8 | bwurrg 9 | brgr 10 | bbrgwb -------------------------------------------------------------------------------- /2024/sample_input/day_20_sample_input: -------------------------------------------------------------------------------- 1 | ############### 2 | #...#...#.....# 3 | #.#.#.#.#.###.# 4 | #S#...#.#.#...# 5 | #######.#.#.### 6 | #######.#.#...# 7 | #######.#.###.# 8 | ###..E#...#...# 9 | ###.#######.### 10 | #...###...#...# 11 | #.#####.#.###.# 12 | #.#...#.#.#...# 13 | #.#.#.#.#.#.### 14 | #...#...#...### 15 | ############### -------------------------------------------------------------------------------- /2024/sample_input/day_21_sample_input: -------------------------------------------------------------------------------- 1 | 029A 2 | 980A 3 | 179A 4 | 456A 5 | 379A -------------------------------------------------------------------------------- /2024/sample_input/day_22_sample_input: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 2024 -------------------------------------------------------------------------------- /2024/sample_input/day_23_sample_input: -------------------------------------------------------------------------------- 1 | kh-tc 2 | qp-kh 3 | de-cg 4 | ka-co 5 | yn-aq 6 | qp-ub 7 | cg-tb 8 | vc-aq 9 | tb-ka 10 | wh-tc 11 | yn-cg 12 | kh-ub 13 | ta-co 14 | de-co 15 | tc-td 16 | tb-wq 17 | wh-td 18 | ta-ka 19 | td-qp 20 | aq-cg 21 | wq-ub 22 | ub-vc 23 | de-ta 24 | wq-aq 25 | wq-vc 26 | wh-yn 27 | ka-de 28 | kh-ta 29 | co-tc 30 | wh-qp 31 | tb-vc 32 | td-yn 33 | -------------------------------------------------------------------------------- /2024/sample_input/day_24_sample_input: -------------------------------------------------------------------------------- 1 | x00: 1 2 | x01: 0 3 | x02: 1 4 | x03: 1 5 | x04: 0 6 | y00: 1 7 | y01: 1 8 | y02: 1 9 | y03: 1 10 | y04: 1 11 | 12 | ntg XOR fgs -> mjb 13 | y02 OR x01 -> tnw 14 | kwq OR kpj -> z05 15 | x00 OR x03 -> fst 16 | tgd XOR rvg -> z01 17 | vdt OR tnw -> bfw 18 | bfw AND frj -> z10 19 | ffh OR nrd -> bqk 20 | y00 AND y03 -> djm 21 | y03 OR y00 -> psh 22 | bqk OR frj -> z08 23 | tnw OR fst -> frj 24 | gnj AND tgd -> z11 25 | bfw XOR mjb -> z00 26 | x03 OR x00 -> vdt 27 | gnj AND wpb -> z02 28 | x04 AND y00 -> kjc 29 | djm OR pbm -> qhw 30 | nrd AND vdt -> hwm 31 | kjc AND fst -> rvg 32 | y04 OR y02 -> fgs 33 | y01 AND x02 -> pbm 34 | ntg OR kjc -> kwq 35 | psh XOR fgs -> tgd 36 | qhw XOR tgd -> z09 37 | pbm OR djm -> kpj 38 | x03 XOR y03 -> ffh 39 | x00 XOR y04 -> ntg 40 | bfw OR bqk -> z06 41 | nrd XOR fgs -> wpb 42 | frj XOR qhw -> z04 43 | bqk OR frj -> z07 44 | y03 OR x01 -> nrd 45 | hwm AND bqk -> z03 46 | tgd XOR rvg -> z12 47 | tnw OR pbm -> gnj -------------------------------------------------------------------------------- /2024/sample_input/day_25_sample_input: -------------------------------------------------------------------------------- 1 | ##### 2 | .#### 3 | .#### 4 | .#### 5 | .#.#. 6 | .#... 7 | ..... 8 | 9 | ##### 10 | ##.## 11 | .#.## 12 | ...## 13 | ...#. 14 | ...#. 15 | ..... 16 | 17 | ..... 18 | #.... 19 | #.... 20 | #...# 21 | #.#.# 22 | #.### 23 | ##### 24 | 25 | ..... 26 | ..... 27 | #.#.. 28 | ###.. 29 | ###.# 30 | ###.# 31 | ##### 32 | 33 | ..... 34 | ..... 35 | ..... 36 | #.... 37 | #.#.. 38 | #.#.# 39 | ##### --------------------------------------------------------------------------------