├── 2019 ├── 01 │ └── 01.ml ├── 02 │ └── 02.ml └── 03 │ └── 03.ml ├── 2020 ├── 10 │ └── 10.rs ├── 11 │ └── 11.rs ├── 12 │ └── 12.rs ├── 13 │ └── 13.rs ├── 14 │ └── 14.rs ├── 15 │ └── 15.rs ├── 16 │ └── 16.rs ├── 17 │ └── 17.rs ├── 18 │ └── 18.rs ├── 19 │ └── 19.rs ├── 20 │ └── 20.rs ├── 21 │ └── 21.rs ├── 22 │ └── 22.rs ├── 23 │ └── 23.rs ├── 24 │ └── 24.rs ├── 25 │ └── 25.rs ├── 01 │ ├── 01.rs │ └── input.ans ├── 02 │ ├── 02.rs │ └── input.ans ├── 03 │ └── 03.rs ├── 04 │ └── 04.rs ├── 05 │ └── 05.rs ├── 06 │ └── 06.rs ├── 07 │ └── 07.rs ├── 08 │ └── 08.rs ├── 09 │ └── 09.rs ├── Cargo.lock ├── Cargo.toml └── benchmark.sh ├── 2021 ├── 10 │ ├── 10.jl │ ├── example.ans │ ├── example.in │ └── input.ans ├── 11 │ ├── 11.jl │ ├── example.ans │ ├── example.in │ └── input.ans ├── 12 │ ├── 12.jl │ ├── example.ans │ ├── example.in │ └── input.ans ├── 13 │ ├── 13.jl │ ├── example.ans │ ├── example.in │ └── input.ans ├── 14 │ ├── 14.jl │ ├── example.ans │ ├── example.in │ └── input.ans ├── 15 │ ├── 15.jl │ ├── example.ans │ ├── example.in │ └── input.ans ├── 16 │ ├── 16.jl │ ├── 16golfed.jl │ ├── example.ans │ ├── example.in │ └── input.ans ├── 17 │ ├── 17.jl │ ├── example.ans │ ├── example.in │ └── input.ans ├── 18 │ ├── 18.jl │ ├── example.ans │ ├── example.in │ └── input.ans ├── 19 │ ├── 19.jl │ ├── example.ans │ ├── example.in │ └── input.ans ├── 20 │ ├── 20.jl │ ├── example.ans │ ├── example.in │ └── input.ans ├── 21 │ ├── 21.jl │ ├── example.ans │ ├── example.in │ └── input.ans ├── 22 │ ├── 22.jl │ ├── example.ans │ ├── example.in │ └── input.ans ├── 23 │ ├── 23.jl │ ├── example.ans │ ├── example.in │ └── input.ans ├── 24 │ ├── 24.cpp │ ├── 24.jl │ └── input.ans ├── 25 │ ├── 25.jl │ ├── example.ans │ ├── example.in │ └── input.ans ├── 01 │ ├── 1.apl │ ├── 1.jl │ ├── 1.py │ ├── example.ans │ ├── example.in │ └── input.ans ├── 02 │ ├── 2.jl │ ├── example.ans │ ├── example.in │ └── input.ans ├── 03 │ ├── 3.jl │ ├── example.ans │ ├── example.in │ └── input.ans ├── 04 │ ├── 4.jl │ ├── example.ans │ ├── example.in │ └── input.ans ├── 05 │ ├── 5.jl │ ├── example.ans │ ├── example.in │ └── input.ans ├── 06 │ ├── 6.jl │ ├── 6.py │ ├── example.ans │ ├── example.in │ └── input.ans ├── 07 │ ├── 7.jl │ ├── example.ans │ ├── example.in │ └── input.ans ├── 08 │ ├── 8.jl │ ├── example.ans │ ├── example.in │ └── input.ans └── 09 │ ├── 9.jl │ ├── example.ans │ ├── example.in │ └── input.ans ├── 2022 ├── 10 │ ├── 10.kt │ ├── 10.py │ ├── example.ans │ ├── example.in │ └── input.ans ├── 11 │ ├── 11.kt │ ├── 11.py │ └── input.ans ├── 12 │ ├── 12.kt │ ├── 12.py │ └── input.ans ├── 13 │ ├── 13.kt │ ├── 13.py │ ├── example.ans │ ├── example.in │ └── input.ans ├── 14 │ ├── 14.kt │ ├── 14.py │ └── input.ans ├── 15 │ ├── 15.kt │ ├── 15.py │ └── input.ans ├── 16 │ ├── 16.kt │ ├── example.ans │ ├── example.in │ └── input.ans ├── 17 │ ├── 17.kt │ ├── example.ans │ ├── example.in │ └── input.ans ├── 18 │ ├── 18.kt │ └── input.ans ├── 19 │ ├── 19.kt │ └── input.ans ├── 20 │ ├── 20.kt │ ├── example.ans │ ├── example.in │ └── input.ans ├── 21 │ ├── 21.kt │ ├── example.ans │ ├── example.in │ └── input.ans ├── 22 │ ├── 22.kt │ └── input.ans ├── 23 │ ├── 23.kt │ ├── example.ans │ ├── example.in │ └── input.ans ├── 24 │ ├── 24.kt │ ├── example.ans │ ├── example.in │ └── input.ans ├── 25 │ ├── 25.kt │ ├── example.ans │ ├── example.in │ └── input.ans ├── 01 │ ├── 01.kt │ ├── 01.py │ └── input.ans ├── 02 │ ├── 02.kt │ ├── 02.py │ ├── example.ans │ ├── example.in │ └── input.ans ├── 03 │ ├── 03.kt │ ├── 03.py │ ├── example.ans │ ├── example.in │ └── input.ans ├── 04 │ ├── 04.kt │ ├── 04.py │ ├── example.ans │ ├── example.in │ └── input.ans ├── 05 │ ├── 05.kt │ ├── 05.py │ └── input.ans ├── 06 │ ├── 06.kt │ ├── 06.py │ └── input.ans ├── 07 │ ├── 07.kt │ ├── 07.py │ └── input.ans ├── 08 │ ├── 08.kt │ ├── 08.py │ └── input.ans └── 09 │ ├── 09.kt │ ├── 09.py │ └── input.ans ├── 2023 ├── 10 │ ├── 10.py │ └── 10.rs ├── 11 │ └── 11.py ├── 12 │ └── 12.py ├── 13 │ └── 13.py ├── 14 │ └── 14.py ├── 15 │ └── 15.py ├── 16 │ └── 16.py ├── 17 │ └── 17.py ├── 18 │ ├── 18.py │ ├── 18_non-complex.py │ └── 18scanline.py ├── 19 │ └── 19.py ├── 20 │ └── 20.py ├── 21 │ └── 21.py ├── 22 │ └── 22.py ├── 23 │ └── 23.py ├── 24 │ └── 24.py ├── 25 │ └── 25.py ├── 01 │ ├── 01.py │ ├── 01.rs │ └── input.ans ├── 02 │ ├── 02.py │ ├── 02.rs │ └── input.ans ├── 03 │ ├── 03.py │ └── 03.rs ├── 04 │ └── 04.py ├── 05 │ └── 05.py ├── 06 │ └── 06.py ├── 07 │ └── 07.py ├── 08 │ └── 08.py ├── 09 │ ├── 09.py │ └── 09.rs ├── Cargo.lock └── Cargo.toml ├── 2024 ├── 10 │ └── 10.py ├── 11 │ └── 11.py ├── 12 │ └── 12.py ├── 13 │ └── 13.py ├── 14 │ └── 14.py ├── 15 │ └── 15.py ├── 16 │ └── 16.py ├── 17 │ └── 17.py ├── 18 │ └── 18.py ├── 19 │ └── 19.py ├── 20 │ └── 20.py ├── 21 │ └── 21.py ├── 22 │ └── 22.py ├── 23 │ └── 23.py ├── 24 │ └── 24.py ├── 25 │ └── 25.py ├── 01 │ └── 01.py ├── 02 │ └── 02.py ├── 03 │ └── 03.py ├── 04 │ └── 04.py ├── 05 │ └── 05.py ├── 06 │ └── 06.py ├── 07 │ └── 07.py ├── 08 │ └── 08.py └── 09 │ └── 09.py ├── .aoc_tiles └── tiles │ ├── 2019 │ ├── 01.png │ ├── 02.png │ ├── 03.png │ ├── 04.png │ └── 05.png │ ├── 2020 │ ├── 01.png │ ├── 02.png │ ├── 03.png │ ├── 04.png │ ├── 05.png │ ├── 06.png │ ├── 07.png │ ├── 08.png │ ├── 09.png │ ├── 10.png │ ├── 11.png │ ├── 12.png │ ├── 13.png │ ├── 14.png │ ├── 15.png │ ├── 16.png │ ├── 17.png │ ├── 18.png │ ├── 19.png │ ├── 20.png │ ├── 21.png │ ├── 22.png │ ├── 23.png │ ├── 24.png │ └── 25.png │ ├── 2021 │ ├── 01.png │ ├── 02.png │ ├── 03.png │ ├── 04.png │ ├── 05.png │ ├── 06.png │ ├── 07.png │ ├── 08.png │ ├── 09.png │ ├── 10.png │ ├── 11.png │ ├── 12.png │ ├── 13.png │ ├── 14.png │ ├── 15.png │ ├── 16.png │ ├── 17.png │ ├── 18.png │ ├── 19.png │ ├── 20.png │ ├── 21.png │ ├── 22.png │ ├── 23.png │ ├── 24.png │ └── 25.png │ ├── 2022 │ ├── 01.png │ ├── 02.png │ ├── 03.png │ ├── 04.png │ ├── 05.png │ ├── 06.png │ ├── 07.png │ ├── 08.png │ ├── 09.png │ ├── 10.png │ ├── 11.png │ ├── 12.png │ ├── 13.png │ ├── 14.png │ ├── 15.png │ ├── 16.png │ ├── 17.png │ ├── 18.png │ ├── 19.png │ ├── 20.png │ ├── 21.png │ ├── 22.png │ ├── 23.png │ ├── 24.png │ └── 25.png │ ├── 2023 │ ├── 01.png │ ├── 02.png │ ├── 03.png │ ├── 04.png │ ├── 05.png │ ├── 06.png │ ├── 07.png │ ├── 08.png │ ├── 09.png │ ├── 10.png │ ├── 11.png │ ├── 12.png │ ├── 13.png │ ├── 14.png │ ├── 15.png │ ├── 16.png │ ├── 17.png │ ├── 18.png │ ├── 19.png │ ├── 20.png │ ├── 21.png │ ├── 22.png │ ├── 23.png │ ├── 24.png │ └── 25.png │ └── 2024 │ ├── 01.png │ ├── 02.png │ ├── 03.png │ ├── 04.png │ ├── 05.png │ ├── 06.png │ ├── 07.png │ ├── 08.png │ ├── 09.png │ ├── 10.png │ ├── 11.png │ ├── 12.png │ ├── 13.png │ ├── 14.png │ ├── 15.png │ ├── 16.png │ ├── 17.png │ ├── 18.png │ ├── 19.png │ ├── 20.png │ ├── 21.png │ ├── 22.png │ ├── 23.png │ ├── 24.png │ └── 25.png ├── .gitignore ├── .pre-commit-config.yaml ├── AoCTiles └── README.md ├── LICENSE ├── Media ├── 2020 │ ├── 01.png │ ├── 02.png │ ├── 03.png │ ├── 04.png │ ├── 05.png │ ├── 06.png │ ├── 07.png │ └── 08.png ├── 2021 │ ├── 01.png │ ├── 02.png │ ├── 03.png │ ├── 04.png │ ├── 05.png │ ├── 06.png │ ├── 07.png │ ├── 08.png │ ├── 09.png │ ├── 10.png │ ├── 11.png │ ├── 12.png │ ├── 13.png │ ├── 14.png │ ├── 15.png │ ├── 16.png │ ├── 17.png │ ├── 18.png │ ├── 19.png │ ├── 20.png │ ├── 21.png │ ├── 22.png │ ├── 23.png │ ├── 24.png │ └── 25.png ├── 2022 │ ├── 01.png │ ├── 02.png │ ├── 03.png │ ├── 04.png │ ├── 05.png │ ├── 06.png │ ├── 07.png │ ├── 08.png │ ├── 09.png │ ├── 10.png │ ├── 11.png │ ├── 12.png │ ├── 13.png │ ├── 14.png │ ├── 15.png │ ├── 16.png │ ├── 17.png │ ├── 18.png │ ├── 19.png │ ├── 20.png │ ├── 21.png │ ├── 22.png │ ├── 23.png │ ├── 24.png │ └── 25.png ├── 2023 │ └── 01.png ├── 2021loc.png └── loc-plot.py ├── README.md └── init-day.sh /.aoc_tiles/tiles/2019/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2019/01.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2019/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2019/02.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2019/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2019/03.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2019/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2019/04.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2019/05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2019/05.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/01.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/02.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/03.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/04.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/05.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/06.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/07.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/08.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/09.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/10.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/11.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/12.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/13.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/14.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/15.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/16.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/17.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/18.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/19.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/20.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/21.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/22.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/23.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/24.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2020/25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2020/25.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/01.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/02.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/03.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/04.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/05.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/06.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/07.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/08.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/09.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/10.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/11.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/12.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/13.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/14.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/15.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/16.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/17.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/18.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/19.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/20.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/21.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/22.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/23.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/24.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2021/25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2021/25.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/01.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/02.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/03.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/04.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/05.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/06.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/07.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/08.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/09.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/10.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/11.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/12.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/13.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/14.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/15.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/16.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/17.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/18.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/19.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/20.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/21.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/22.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/23.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/24.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2022/25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2022/25.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/01.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/02.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/03.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/04.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/05.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/06.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/07.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/08.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/09.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/10.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/11.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/12.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/13.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/14.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/15.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/16.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/17.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/18.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/19.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/20.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/21.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/22.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/23.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/24.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2023/25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2023/25.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/01.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/02.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/03.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/04.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/05.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/06.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/07.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/08.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/09.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/10.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/11.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/12.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/13.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/14.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/15.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/16.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/17.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/18.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/19.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/20.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/21.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/22.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/23.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/24.png -------------------------------------------------------------------------------- /.aoc_tiles/tiles/2024/25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/.aoc_tiles/tiles/2024/25.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2021/3/3golfed.py 2 | *run 3 | .apl.history 4 | .idea 5 | AoCTiles/.aoc_tiles_cache 6 | *.class 7 | META-INF 8 | *.jar 9 | target 10 | session.cookie 11 | 12 | *.in 13 | *.ans 14 | 15 | .aoc_tiles/* 16 | !.aoc_tiles/tiles/ 17 | 18 | 19 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/LiquidFun/aoc_tiles 3 | rev: 0.6.3 4 | hooks: 5 | - id: aoc-tiles 6 | args: 7 | - --language-sorting=jl,kt,py,rs 8 | - --exclude-patterns=2021/*/*.apl,2021/*/*.py,2021/*/*.cpp,2023/*/*.rs 9 | - --auto-add-tiles-to-git=amend 10 | - --count-as-solved-when=on_leaderboard 11 | 12 | -------------------------------------------------------------------------------- /2019/01/01.ml: -------------------------------------------------------------------------------- 1 | let fuel x = x / 3 - 2;; 2 | let rec fuel_of_fuel x = if x < 0 then 0 else x + (x |> fuel |> fuel_of_fuel);; 3 | 4 | let rec collect_nums acc = 5 | try 6 | let line = input_line stdin in 7 | collect_nums ((line |> int_of_string |> fuel) :: acc) 8 | with End_of_file -> 9 | List.rev acc 10 | 11 | let () = 12 | let lines = collect_nums [] in 13 | List.fold_left ( + ) 0 lines |> Printf.printf "%d\n"; 14 | List.fold_left ( + ) 0 (List.map fuel_of_fuel lines) |> print_int -------------------------------------------------------------------------------- /2019/02/02.ml: -------------------------------------------------------------------------------- 1 | let rec process nums i = 2 | match nums.(i) with 3 | | 1 -> nums.(nums.(i+3)) <- nums.(nums.(i+1)) + nums.(nums.(i+2)); process nums (i+4) 4 | | 2 -> nums.(nums.(i+3)) <- nums.(nums.(i+1)) * nums.(nums.(i+2)); process nums (i+4) 5 | | _ -> nums.(0) 6 | 7 | let with_a_b nums n = 8 | let memory = Array.copy nums in 9 | memory.(1) <- n / 100; 10 | memory.(2) <- n mod 100; 11 | process memory 0 12 | 13 | let find_part2 nums = 14 | List.init 10000 Fun.id |> List.find (fun x -> (with_a_b nums x) == 19690720) 15 | 16 | let () = 17 | let nums = input_line stdin |> String.split_on_char ',' |> List.map int_of_string |> Array.of_list in 18 | with_a_b nums 1202 |> Printf.printf "%d\n"; 19 | find_part2 nums |> print_int -------------------------------------------------------------------------------- /2019/03/03.ml: -------------------------------------------------------------------------------- 1 | module TupleSet = Set.Make(struct 2 | type t = int * int 3 | let compare = compare 4 | end) 5 | 6 | let to_tup dir = let num = String.sub dir 1 (String.length dir - 1) |> int_of_string in 7 | let xy = match String.get dir 0 with 8 | | 'U' -> (0, 1) 9 | | 'D' -> (0, -1) 10 | | 'R' -> (1, 0) 11 | | _ -> (-1, 0) in 12 | List.init num (fun _ -> xy) 13 | 14 | 15 | let rec scan sx sy = function 16 | | [] -> [] 17 | | (x, y) :: rest -> (sx+x, sy+y) :: scan (sx+x) (sy+y) rest 18 | 19 | 20 | let read_line stdin = 21 | input_line stdin |> String.split_on_char ',' |> List.concat_map to_tup |> scan 0 0 |> TupleSet.of_list 22 | 23 | 24 | (* List.iter (fun (a, b) -> Printf.printf("%d,%d -> ") a b) dirs *) 25 | 26 | let () = 27 | let d1 = read_line stdin in 28 | let d2 = read_line stdin in 29 | (* TupleSet.inter d1 d2 |> TupleSet.iter (fun (a,b) -> Printf.printf "%d,%d -> " a b); *) 30 | (* TupleSet.inter d1 d2 |> TupleSet.to_list |> List.map (fun (a,b) -> abs(a) + abs(b)) |> List.iter (fun b -> Printf.printf "%d -> " b); *) 31 | TupleSet.inter d1 d2 |> TupleSet.to_list |> List.map (fun (a,b) -> abs(a) + abs(b)) |> List.fold_left min max_int |> Printf.printf "%d\n"; 32 | (* Printf.printf "\n%d\n" (TupleSet.to_list d1 |> List.length); *) 33 | (* Printf.printf "\n%d\n" (TupleSet.to_list d2 |> List.length); *) 34 | (* List.iter (fun (a, b) -> Printf.printf("%d,%d -> ") a b) d1; *) 35 | (* let shared = List.filter (fun x -> List.exists (fun a -> a == x) d1) d2 in *) 36 | (* let num = List.map (fun (a, b) -> a+b) shared |> List.fold_left max min_int in *) 37 | (* Printf.printf "%d " num; *) 38 | -------------------------------------------------------------------------------- /2020/01/01.rs: -------------------------------------------------------------------------------- 1 | use std::io::stdin; 2 | use itertools::iproduct; 3 | 4 | fn main() { 5 | let nums: Vec = stdin().lines().map(|a| a.unwrap().parse().unwrap()).collect(); 6 | iproduct!(&nums, &nums) 7 | .find(|(&a, &b)| a+b == 2020) 8 | .map(|(&a, &b)| println!("{}", a*b)); 9 | iproduct!(&nums, &nums, &nums) 10 | .find(|(&a, &b, &c)| a+b+c == 2020) 11 | .map(|(&a, &b, &c)| println!("{}", a*b*c)); 12 | } -------------------------------------------------------------------------------- /2020/01/input.ans: -------------------------------------------------------------------------------- 1 | 964875 2 | 158661360 3 | -------------------------------------------------------------------------------- /2020/02/02.rs: -------------------------------------------------------------------------------- 1 | use itertools::Itertools; 2 | use std::io::stdin; 3 | 4 | struct PasswordPhilosophy { 5 | range: std::ops::RangeInclusive, 6 | letter: char, 7 | string: String, 8 | } 9 | 10 | fn parse_password_philosophies() -> Vec { 11 | let lines = stdin().lines().filter_map(Result::ok).collect_vec(); 12 | lines.iter() 13 | .map(|line| line.split(|c| "- :".contains(c)).next_tuple().unwrap()) 14 | .map(|(a, b, letter, _, string)| { 15 | PasswordPhilosophy { 16 | range: a.parse().unwrap()..=b.parse().unwrap(), 17 | letter: letter.chars().next().unwrap(), 18 | string: string.to_owned(), 19 | } 20 | }) 21 | .collect() 22 | } 23 | 24 | fn main() { 25 | let philosophies = parse_password_philosophies(); 26 | println!("{}", philosophies.iter().filter(|p| p.range.contains(&p.string.matches(p.letter).count())).count()); 27 | 28 | let sum2 = philosophies 29 | .iter() 30 | .filter(|p| { 31 | let is_first = p.string.chars().nth((p.range.start() - 1) as usize).unwrap() == p.letter; 32 | let is_second = p.string.chars().nth((p.range.end() - 1) as usize).unwrap() == p.letter; 33 | is_first != is_second 34 | }) 35 | .count(); 36 | 37 | println!("{}", sum2); 38 | } -------------------------------------------------------------------------------- /2020/02/input.ans: -------------------------------------------------------------------------------- 1 | 666 2 | 670 -------------------------------------------------------------------------------- /2020/03/03.rs: -------------------------------------------------------------------------------- 1 | use std::io::stdin; 2 | 3 | fn solve(map: &Vec, dy: usize, dx: usize) -> usize { 4 | let mut x = 0; 5 | let mut count = 0; 6 | for y in (0..map.len()).step_by(dy) { 7 | count += (map[y].get(x..=x).unwrap() == "#") as usize; 8 | x = (x+dx) % map[0].len(); 9 | } 10 | count 11 | } 12 | 13 | fn main() { 14 | let map = stdin().lines().filter_map(Result::ok).collect(); 15 | println!("{}", solve(&map, 1, 3)); 16 | let ans2: usize = [(1, 1), (1, 3), (1, 5), (1, 7), (2, 1)].iter() 17 | .map(|(y, x)| solve(&map, *y, *x)) 18 | .product(); 19 | println!("{}", ans2); 20 | } -------------------------------------------------------------------------------- /2020/04/04.rs: -------------------------------------------------------------------------------- 1 | use std::{io::stdin, collections::HashMap}; 2 | 3 | use itertools::Itertools; 4 | use regex::Regex; 5 | 6 | fn valid_p1(map: &HashMap<&str, &str>) -> bool { 7 | "byr iyr eyr hgt hcl ecl pid".split(" ").all(|req| map.contains_key(&req)) 8 | } 9 | 10 | fn valid_p2(map: &HashMap<&str, &str>) -> bool { 11 | valid_p1(map) 12 | && (1920..=2002).contains(&map["byr"].parse().unwrap()) 13 | && (2010..=2020).contains(&map["iyr"].parse().unwrap()) 14 | && (2020..=2030).contains(&map["eyr"].parse().unwrap()) 15 | && Regex::new(r"^((1[5-8]\d|19[0123])cm|(59|6\d|7[0-6])in)$").unwrap().is_match(map["hgt"]) 16 | && Regex::new(r"^#[0-9a-f]{6}$").unwrap().is_match(map["hcl"]) 17 | && Regex::new(r"^\d{9}$").unwrap().is_match(map["pid"]) 18 | && "amb blu brn gry grn hzl oth".split(" ").contains(&map["ecl"]) 19 | } 20 | 21 | fn main() { 22 | let input = stdin().lines().filter_map(Result::ok).join(" "); 23 | let passports: Vec> = input 24 | .split(" ") 25 | .map(|line| line.split(" ").map(|e| e.split_once(":").unwrap()).collect()) 26 | .collect(); 27 | println!("{}", passports.iter().filter(|h| valid_p1(h)).count()); 28 | println!("{}", passports.iter().filter(|h| valid_p2(h)).count()); 29 | } -------------------------------------------------------------------------------- /2020/05/05.rs: -------------------------------------------------------------------------------- 1 | use std::io::stdin; 2 | 3 | use itertools::Itertools; 4 | 5 | fn as_binary(s: &str) -> i32 { 6 | s.char_indices().fold(0, |acc, (i, c)| acc + (1<<(9-i)) * ("BR".contains(c) as i32)) 7 | } 8 | 9 | fn main() { 10 | let nums: Vec = stdin().lines().map(|l| as_binary(&l.unwrap())).collect(); 11 | println!("{:?}", nums.iter().max().unwrap()); 12 | nums.iter() 13 | .sorted() 14 | .tuple_windows() 15 | .find(|(&a, &b)| b-a == 2) 16 | .map(|(&a, _)| println!("{}", a+1)); 17 | } 18 | -------------------------------------------------------------------------------- /2020/06/06.rs: -------------------------------------------------------------------------------- 1 | use std::{io::stdin, collections::HashSet}; 2 | 3 | fn main() { 4 | let sets = stdin().lines() 5 | .map(|l| l.unwrap().chars().collect::>()) 6 | .collect::>(); 7 | let groups = sets 8 | .split(|set| set.is_empty()) 9 | .collect::>(); 10 | 11 | let p1: usize = groups.iter() 12 | .map(|s| s.iter().fold(s[0].clone(), |acc, curr| acc.union(curr).cloned().collect())) 13 | .fold(0, |acc, l| acc+l.len()); 14 | let p2: usize = groups.iter() 15 | .map(|s| s.iter().fold(s[0].clone(), |acc, curr| acc.intersection(curr).cloned().collect())) 16 | .fold(0, |acc, l| acc+l.len()); 17 | 18 | println!("{}\n{}", p1, p2); 19 | } -------------------------------------------------------------------------------- /2020/07/07.rs: -------------------------------------------------------------------------------- 1 | use std::{io::stdin, collections::HashMap}; 2 | use regex::Regex; 3 | 4 | fn contains_shiny_gold(map: &HashMap<&str, Vec<[&str; 2]>>, key: &str) -> bool { 5 | if key == "shiny gold" { return true } 6 | map[key].iter().any(|[_, name]| contains_shiny_gold(map, name)) 7 | } 8 | 9 | fn count_bags(map: &HashMap<&str, Vec<[&str; 2]>>, key: &str) -> usize { 10 | map[key].iter() 11 | .map(|[num, name]| num.parse::().unwrap()*count_bags(map, name)) 12 | .sum::() + 1 13 | } 14 | 15 | fn main() { 16 | let pat = Regex::new(r"(^|\d) ?(\w+ \w+)").unwrap(); 17 | let lines = stdin().lines().filter_map(Result::ok).collect::>(); 18 | let map = lines.iter() 19 | .map(|s| pat.captures_iter(&s).map(|c| c.extract::<2>()).collect::>()) 20 | .map(|m| (m[0].0, m.iter().skip(1).map(|s| s.1).collect::>())) 21 | .collect::>(); 22 | 23 | let p1 = map.iter().filter(|(key, _)| contains_shiny_gold(&map, key)).count(); 24 | let p2: usize = count_bags(&map, "shiny gold"); 25 | println!("{}\n{}", p1-1, p2-1); 26 | } -------------------------------------------------------------------------------- /2020/08/08.rs: -------------------------------------------------------------------------------- 1 | use std::{io::stdin, collections::HashSet}; 2 | 3 | fn terminates(inst: &Vec<(&str, i32)>) -> Result { 4 | let mut visited = HashSet::new(); 5 | let mut i: i32 = 0; 6 | let mut acc = 0; 7 | loop { 8 | let (op, num) = inst[i as usize]; 9 | match op { 10 | "acc" => { acc += num; i += 1 }, 11 | "nop" => i += 1, 12 | "jmp" => i += num, 13 | _ => panic!(), 14 | } 15 | if visited.contains(&i) { 16 | return Err(acc); 17 | } 18 | if !(0..inst.len() as i32).contains(&i) { 19 | return Ok(acc); 20 | } 21 | visited.insert(i); 22 | } 23 | } 24 | 25 | fn swap(op: &str) -> &str { 26 | match op { 27 | "nop" => "jmp", 28 | "jmp" => "nop", 29 | o => o, 30 | } 31 | } 32 | 33 | fn main() { 34 | let lines = stdin().lines().filter_map(Result::ok).collect::>(); 35 | let mut inst = lines.iter() 36 | .map(|line| line.split_once(" ").unwrap()) 37 | .map(|(op, num)| (op, num.parse::().unwrap())) 38 | .collect::>(); 39 | println!("{:?}", terminates(&inst).unwrap_err()); 40 | for i in 0..inst.len() { 41 | inst[i].0 = swap(inst[i].0); 42 | if let Ok(res) = terminates(&inst) { 43 | println!("{:?}", res); 44 | } 45 | inst[i].0 = swap(inst[i].0); 46 | } 47 | } -------------------------------------------------------------------------------- /2020/09/09.rs: -------------------------------------------------------------------------------- 1 | use std::io::stdin; 2 | 3 | fn main() { 4 | let nums: Vec = stdin().lines().map(|line| line.unwrap().parse().unwrap()).collect(); 5 | let target_num = nums 6 | .windows(26) 7 | .find(|vec| !vec.iter().take(25).any(|n| vec.contains(&(vec[25]-n)))) 8 | .unwrap()[25]; 9 | 10 | let mut max = (0, 0); 11 | for i in 0..nums.len() { 12 | let mut sum = 0; 13 | for j in i..nums.len() { 14 | sum += nums[j]; 15 | if sum == target_num && j-i > max.0 { 16 | max = (j-i, nums[i..=j].iter().min().unwrap() + nums[i..=j].iter().max().unwrap()); 17 | } 18 | } 19 | } 20 | println!("{}\n{}", target_num, max.1); 21 | } -------------------------------------------------------------------------------- /2020/10/10.rs: -------------------------------------------------------------------------------- 1 | use std::io::stdin; 2 | use itertools::Itertools; 3 | 4 | fn main() { 5 | let mut nums: Vec = stdin().lines().map(|line| line.unwrap().parse().unwrap()).collect(); 6 | nums.extend([0, *nums.iter().max().unwrap()+3]); 7 | let diffs: Vec<_> = nums.iter().sorted().tuple_windows().map(|(a,b)|b-a).collect(); 8 | let counts = diffs.iter().counts(); 9 | let lookup = [1, 1, 2, 4, 7]; 10 | let p2: i64 = diffs .split(|&n| n == 3) .map(|vec| lookup[vec.len()]) .product(); 11 | println!("{}\n{}", counts[&1]*counts[&3], p2); 12 | } -------------------------------------------------------------------------------- /2020/11/11.rs: -------------------------------------------------------------------------------- 1 | use std::{io::stdin, collections::HashSet}; 2 | use itertools::{iproduct, Itertools}; 3 | 4 | const DIRS: [(i32, i32); 8] = [(0, 1), (1, 0), (-1, 0), (0, -1), (-1, -1), (-1, 1), (1, -1), (1, 1)]; 5 | 6 | fn solve(lines: &Vec>, is_part2: bool) { 7 | 8 | let seats: Vec<_> = iproduct!(0..lines.len(), 0..lines[0].len()) 9 | .filter(|(y, x)| lines[*y][*x] == 'L') 10 | .map(|(y, x)| (y as i32, x as i32)) 11 | .collect(); 12 | 13 | // let is_seat = |y, x| seats.contains(x) 14 | 15 | let mut taken = HashSet::new(); 16 | let s = lines.len() as i32; 17 | loop { 18 | let mut new_taken = HashSet::new(); 19 | for seat in &seats { 20 | let mut adj = DIRS.iter() 21 | .filter(|&(y, x)| taken.contains(&(seat.0+y, seat.1+x))) 22 | .count(); 23 | if is_part2 { 24 | adj = DIRS.iter() 25 | .map(|&(y, x)| (y, x, (1..s).find(|m| seats.contains(&(seat.0+y*m, seat.1+x*m))).unwrap_or(1))) 26 | .filter(|&(y, x, m)| taken.contains(&(seat.0+y*m, seat.1+x*m))) 27 | .count(); 28 | } 29 | match adj { 30 | 0 => new_taken.insert(seat), 31 | 4 if !is_part2 => false, 32 | 5..=8 => false, 33 | _ if taken.contains(seat) => new_taken.insert(seat), 34 | _ => false, 35 | }; 36 | } 37 | if taken.len() == new_taken.len() { 38 | break 39 | } 40 | taken = new_taken; 41 | } 42 | println!("{:?}", taken.len()); 43 | } 44 | 45 | fn main() { 46 | let lines: Vec> = stdin().lines() 47 | .map(|line| line.unwrap().trim().chars().collect_vec()) 48 | .collect(); 49 | solve(&lines, false); 50 | solve(&lines, true); 51 | } -------------------------------------------------------------------------------- /2020/12/12.rs: -------------------------------------------------------------------------------- 1 | use std::io::stdin; 2 | 3 | const DIRS: [(i32, i32); 4] = [(0, 1), (1, 0), (0, -1), (-1, 0)]; 4 | 5 | fn part1(actions: &Vec<(String, i32)>) -> i32 { 6 | let (mut y, mut x, mut dir) = (0, 0, 0); 7 | for (action, num) in actions { 8 | match action.as_str() { 9 | "N" => y -= num, 10 | "S" => y += num, 11 | "W" => x -= num, 12 | "E" => x += num, 13 | "F" => {y += DIRS[dir as usize].0 * num; x += DIRS[dir as usize].1 * num }, 14 | "R" => dir = (dir + num / 90 + 4) % 4, 15 | "L" => dir = (dir - num / 90 + 4) % 4, 16 | _ => panic!(), 17 | } 18 | } 19 | y.abs() + x.abs() 20 | } 21 | 22 | fn part2(actions: &Vec<(String, i32)>) -> i32 { 23 | let (mut y, mut x) = (0, 0); 24 | let (mut wpy, mut wpx) = (-1, 10); 25 | for (action, num) in actions { 26 | match (action.as_str(), num) { 27 | ("N", _) => wpy -= num, 28 | ("S", _) => wpy += num, 29 | ("W", _) => wpx -= num, 30 | ("E", _) => wpx += num, 31 | ("F", _) => {y += wpy * num; x += wpx * num }, 32 | ("R", 90) | ("L", 270) => {(wpy, wpx) = (wpx, -wpy)}, 33 | ("R", 270) | ("L", 90) => {(wpy, wpx) = (-wpx, wpy)}, 34 | ("R", 180) | ("L", 180) => {(wpy, wpx) = (-wpy, -wpx)}, 35 | _ => panic!(), 36 | } 37 | } 38 | y.abs() + x.abs() 39 | } 40 | 41 | fn main() { 42 | let actions: Vec<(String, i32)> = stdin().lines() 43 | .filter_map(Result::ok) 44 | .map(|l| (l[0..1].to_owned(), l[1..l.len()].parse().unwrap())) 45 | .collect(); 46 | println!("{}\n{}", part1(&actions), part2(&actions)); 47 | } -------------------------------------------------------------------------------- /2020/13/13.rs: -------------------------------------------------------------------------------- 1 | use std::io::stdin; 2 | 3 | fn mod_inv(a: i64, module: i64) -> i64 { 4 | let mut mn = (module, a); 5 | let mut xy = (0, 1); 6 | 7 | while mn.1 != 0 { 8 | xy = (xy.1, xy.0 - (mn.0 / mn.1) * xy.1); 9 | mn = (mn.1, mn.0 % mn.1); 10 | } 11 | while xy.0 < 0 { 12 | xy.0 += module; 13 | } 14 | xy.0 15 | } 16 | 17 | fn chinese_remainder_theorem(pairs: &Vec<(i64, i64)>) -> i64 { 18 | let prod: i64 = pairs.iter().map(|t| t.1).product(); 19 | let mut sum = 0; 20 | for (s, x) in pairs { 21 | let p = prod / x; 22 | let residue = (x - s) % x; 23 | sum += residue * mod_inv(p, *x) * p; 24 | } 25 | sum % prod 26 | } 27 | 28 | fn main() { 29 | let lines = stdin().lines().filter_map(Result::ok).collect::>(); 30 | 31 | let time: i32 = lines.first().unwrap().parse().unwrap(); 32 | lines[1].split(",") 33 | .filter_map(|s| s.parse().ok()) 34 | .map(|t: i32| (t - time % t, t)) 35 | .min() 36 | .map(|(b, t)| println!("{}", b*t)); 37 | 38 | let pairs = lines[1].split(",") 39 | .enumerate() 40 | .filter_map(|(i, s)| s.parse().ok().map(|n| (i as i64, n))) 41 | .collect::>(); 42 | println!("{:?}", chinese_remainder_theorem(&pairs)); 43 | } -------------------------------------------------------------------------------- /2020/15/15.rs: -------------------------------------------------------------------------------- 1 | use std::{io::stdin, collections::HashMap}; 2 | 3 | fn main() { 4 | let line = stdin().lines().last().unwrap().unwrap(); 5 | let mut lookup: HashMap<_, _> = line.split(",").map(|n| n.parse().unwrap()).zip(1..).collect(); 6 | let mut last = 0; 7 | for i in lookup.len()+1..30_000_000 { 8 | last = i - lookup.insert(last, i).unwrap_or(i); 9 | if i == 2019 { println!("{}", last); } 10 | } 11 | println!("{}", last); 12 | } 13 | -------------------------------------------------------------------------------- /2020/18/18.rs: -------------------------------------------------------------------------------- 1 | use std::io::stdin; 2 | 3 | fn eval(line: &str, plus_precedence: i32) -> i64 { 4 | let mut nums = Vec::new(); 5 | let mut operators = Vec::new(); 6 | let precedence = |c| match c { '+' => plus_precedence, '*' => 1, _ => 0 }; 7 | 8 | for c in line.chars().chain(")".chars()) { 9 | match c { 10 | '0'..='9' => nums.push(c.to_digit(10).unwrap() as i64), 11 | '(' | '+' | '*' | ')' => { 12 | while !operators.is_empty() && c != '(' { 13 | let op = operators.pop().unwrap(); 14 | if op == '(' && c == ')' { break } 15 | if precedence(op) < precedence(c) { 16 | operators.push(op); 17 | break; 18 | } 19 | let func = match op { '*' => |(a, b)| a * b, _ => |(a, b)| a + b }; 20 | let value = nums.pop().zip(nums.pop()).map(func).unwrap(); 21 | nums.push(value); 22 | } 23 | if c != ')' { operators.push(c); } 24 | }, 25 | _ => continue, 26 | } 27 | } 28 | *nums.get(0).unwrap() 29 | } 30 | 31 | fn main() { 32 | let lines: Vec = stdin() .lines().filter_map(Result::ok).collect(); 33 | println!("{}", lines.iter().map(|l| eval(&l, 1)).sum::()); 34 | println!("{}", lines.iter().map(|l| eval(&l, 2)).sum::()); 35 | } -------------------------------------------------------------------------------- /2020/21/21.rs: -------------------------------------------------------------------------------- 1 | use std::{collections::{HashMap, HashSet}, io::stdin}; 2 | use itertools::Itertools; 3 | 4 | fn main() { 5 | let lines = stdin().lines().filter_map(Result::ok).collect_vec(); 6 | 7 | let mut all: Vec<&str> = Vec::new(); 8 | let mut possible = HashMap::new(); 9 | 10 | for line in &lines { 11 | let (left, right) = line.split_once(" (contains ").unwrap(); 12 | let ingredients: HashSet<&str> = left.split(" ").collect(); 13 | let allergens = right.trim_matches(')').split(", ").collect_vec(); 14 | all.extend(&ingredients); 15 | 16 | for allergen in allergens { 17 | possible.entry(allergen) 18 | .or_insert(ingredients.clone()) 19 | .retain(|k| ingredients.contains(k)) 20 | } 21 | } 22 | println!("{}", all.iter().filter(|k| !possible.values().flatten().contains(k)).count()); 23 | 24 | let mut pairings: HashMap<&str, &str> = HashMap::new(); 25 | while possible.len() != pairings.len() { 26 | possible.iter() 27 | .filter(|(_, v)| v.len() == 1) 28 | .for_each(|(k, v)| { pairings.insert(k, v.iter().next().unwrap()); }); 29 | possible.values_mut() 30 | .for_each(|v| v.retain(|a| !pairings.values().contains(a))) 31 | } 32 | println!("{}", pairings.iter().sorted().map(|(_, b)| b).join(",")); 33 | } -------------------------------------------------------------------------------- /2020/22/22.rs: -------------------------------------------------------------------------------- 1 | use std::{collections::{HashSet, VecDeque}, io::stdin}; 2 | 3 | fn solve(mut player1: VecDeque, mut player2: VecDeque, part2: bool) -> bool { 4 | let is_first = player1.len() == player2.len(); 5 | let mut cache = HashSet::new(); 6 | while !player1.is_empty() && !player2.is_empty() { 7 | if !cache.insert((player1.clone(), player2.clone())) { return true; } 8 | let p1 = player1.pop_front().unwrap(); 9 | let p2 = player2.pop_front().unwrap(); 10 | let mut p1wins = p1 > p2; 11 | if part2 && player1.len() >= p1 && player2.len() >= p2 { 12 | p1wins = solve(player1.iter().take(p1).copied().collect(), player2.iter().take(p2).copied().collect(), true) 13 | } 14 | if p1wins { 15 | player1.extend([p1, p2]) 16 | } else { 17 | player2.extend([p2, p1]) 18 | } 19 | } 20 | if is_first { 21 | println!("{:?}", player1.iter().chain(player2.iter()).rev().zip(1..).fold(0, |acc, (i, v)| acc+i*v)); 22 | } 23 | player2.is_empty() 24 | } 25 | 26 | fn main() { 27 | let mut player1: VecDeque = stdin().lines().map(|l| l.unwrap().parse()).filter_map(Result::ok).collect(); 28 | let player2 = player1.split_off(player1.len() / 2); 29 | solve(player1.clone(), player2.clone(), false); 30 | solve(player1, player2, true); 31 | } -------------------------------------------------------------------------------- /2020/23/23.rs: -------------------------------------------------------------------------------- 1 | use std::io::stdin; 2 | 3 | use itertools::Itertools; 4 | 5 | fn solve(initial: Vec, steps: i32) -> Vec { 6 | let mut cups = initial.iter().zip(initial.iter().cycle().skip(1)).sorted().map(|a| a.1).copied().collect_vec(); 7 | cups.insert(0, 0); 8 | let mut curr = initial[0]; 9 | let max = initial.len(); 10 | 11 | for _ in 0..steps { 12 | let first = cups[curr]; 13 | let second = cups[first]; 14 | let third = cups[second]; 15 | 16 | let mut dest = curr; 17 | while [curr, first, second, third].contains(&dest) { dest = (dest + max - 2) % max + 1 } 18 | 19 | cups[curr] = cups[third]; 20 | cups[third] = cups[dest]; 21 | cups[dest] = first; 22 | 23 | curr = cups[curr]; 24 | } 25 | 26 | let mut sorted = Vec::new(); 27 | curr = 1; 28 | for _ in 0..max { 29 | sorted.push(curr); 30 | curr = cups[curr]; 31 | } 32 | sorted 33 | } 34 | 35 | fn main() { 36 | let cups = stdin().lines().next().unwrap().unwrap().chars().map(|c| c.to_digit(10).unwrap() as usize).collect_vec(); 37 | println!("{}", solve(cups.clone(), 100).iter().skip(1).join("")); 38 | 39 | let p2 = cups.into_iter().chain(10..=1_000_000).collect(); 40 | println!("{}", solve(p2, 10_000_000).into_iter().skip(1).take(2).reduce(|acc, a| acc * a).unwrap()); 41 | } -------------------------------------------------------------------------------- /2020/24/24.rs: -------------------------------------------------------------------------------- 1 | use std::{collections::HashSet, io::stdin}; 2 | 3 | use regex::Regex; 4 | 5 | fn adjacent((x, y): &(i32, i32)) -> impl Iterator { 6 | [(x-2, *y), (x+2, *y), (x+1, y+1), (x+1, y-1), (x-1, y-1), (x-1, y+1)].into_iter() 7 | } 8 | 9 | fn main() { 10 | let pat = Regex::new("e|ne|nw|w|sw|se").unwrap(); 11 | let mut tiles = HashSet::new(); 12 | 13 | for line in stdin().lines().filter_map(Result::ok) { 14 | let (mut x, mut y) = (0, 0); 15 | for dir in pat.find_iter(&line).map(|m| m.as_str()) { 16 | x += (dir.contains('e') as i32 * 4 - 2) / dir.len() as i32; 17 | y += dir.contains('n') as i32 - dir.contains('s') as i32; 18 | } 19 | if !tiles.remove(&(x, y)) { 20 | tiles.insert((x, y)); 21 | } 22 | } 23 | println!("{}", tiles.len()); 24 | 25 | for _ in 0..100 { 26 | tiles = tiles.iter() 27 | .flat_map(adjacent) 28 | .filter(|t| (1 + !tiles.contains(t) as usize..=2) 29 | .contains(&adjacent(t).filter(|a| tiles.contains(a)).count())) 30 | .collect(); 31 | } 32 | println!("{}", tiles.len()); 33 | } 34 | -------------------------------------------------------------------------------- /2020/25/25.rs: -------------------------------------------------------------------------------- 1 | use std::io::stdin; 2 | use itertools::Itertools; 3 | 4 | fn main() { 5 | let (card, door) = stdin().lines().map(|n| n.unwrap().parse()).filter_map(Result::ok).next_tuple().unwrap(); 6 | let mut value: usize = 1; 7 | let card_loop = (0..).map(|_| { value = value * 7 % 20201227; value }).take_while(|v| *v != card).count() + 1; 8 | println!("{}", (0..card_loop).fold(1, |acc, _| acc * door % 20201227)); 9 | } -------------------------------------------------------------------------------- /2020/benchmark.sh: -------------------------------------------------------------------------------- 1 | for dir in {0,1,2}*; do cargo build --release --bin $dir; done 2 | for dir in {0,1,2}*; do hyperfine -N --min-runs 1 --warmup 3 --input $dir/input.in ./target/release/$dir; done 3 | -------------------------------------------------------------------------------- /2021/01/1.apl: -------------------------------------------------------------------------------- 1 | solve ← {+/0>-/⍉↑⍵(1↓⍵)} 2 | solvePartTwo ← {solve 2↓⌽{+/⍉↑⍵(1↓⍵)(2↓⍵)}⌽⍵} 3 | 4 | input ← 199 200 208 210 200 207 240 269 260 263 5 | 6 | solve input 7 | 8 | solvePartTwo input 9 | -------------------------------------------------------------------------------- /2021/01/1.jl: -------------------------------------------------------------------------------- 1 | nums = (x -> parse(Int, x)).(readlines()) 2 | solve(dist) = sum(a < b for (a, b) in zip(nums, nums[dist:end])) 3 | println(solve(2)) 4 | println(solve(4)) 5 | -------------------------------------------------------------------------------- /2021/01/1.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | nums = [*map(int, sys.stdin.readlines())] 4 | 5 | def solve(distance): 6 | return sum(a < b for a, b in zip(nums, nums[distance:])) 7 | 8 | print(solve(1)) 9 | print(solve(3)) 10 | 11 | 12 | -------------------------------------------------------------------------------- /2021/01/example.ans: -------------------------------------------------------------------------------- 1 | 7 2 | 5 3 | -------------------------------------------------------------------------------- /2021/01/example.in: -------------------------------------------------------------------------------- 1 | 199 2 | 200 3 | 208 4 | 210 5 | 200 6 | 207 7 | 240 8 | 269 9 | 260 10 | 263 11 | -------------------------------------------------------------------------------- /2021/01/input.ans: -------------------------------------------------------------------------------- 1 | 1709 2 | 1761 3 | -------------------------------------------------------------------------------- /2021/02/2.jl: -------------------------------------------------------------------------------- 1 | lines = readlines() 2 | 3 | function solve(use_aim=false) 4 | depth, position, aim = 0, 0, 0 5 | for line in lines 6 | word, num = split(line) 7 | num = parse(Int, num) 8 | if word == "forward" 9 | position += num 10 | depth += use_aim ? aim * num : 0 11 | else 12 | if use_aim 13 | aim += word == "down" ? num : -num 14 | else 15 | depth += word == "down" ? num : -num 16 | end 17 | end 18 | end 19 | return depth * position 20 | end 21 | println(solve(false)) 22 | println(solve(true)) 23 | -------------------------------------------------------------------------------- /2021/02/example.ans: -------------------------------------------------------------------------------- 1 | 150 2 | 900 3 | -------------------------------------------------------------------------------- /2021/02/example.in: -------------------------------------------------------------------------------- 1 | forward 5 2 | down 5 3 | forward 8 4 | up 3 5 | down 8 6 | forward 2 7 | -------------------------------------------------------------------------------- /2021/02/input.ans: -------------------------------------------------------------------------------- 1 | 1451208 2 | 1620141160 3 | -------------------------------------------------------------------------------- /2021/03/3.jl: -------------------------------------------------------------------------------- 1 | function solve1(numbers, counts) 2 | gamma = 0 3 | for i in counts 4 | gamma = gamma*2 + (i > length(numbers)/2) 5 | end 6 | epsilon = (2^length(counts) - 1) ⊻ gamma 7 | return gamma * epsilon 8 | end 9 | 10 | function solve2(nums, pow) 11 | function descend_tree(numbers, power, inverse=false) 12 | if length(numbers) == 1 13 | return numbers[1] 14 | end 15 | matching = 2^power .& numbers 16 | sort!(matching) 17 | sort!(numbers, by=(x) -> x & (2^power)) 18 | 19 | index = length(numbers) ÷ 2 + 1 20 | mid = matching[index] 21 | if (mid == 0) != inverse 22 | func = x -> (x & 2^power) == 0 23 | else 24 | func = x -> !((x & 2^power) == 0) 25 | end 26 | filter!(func, numbers) 27 | return descend_tree(numbers, power-1, inverse) 28 | end 29 | return descend_tree(copy(nums), pow, false) * descend_tree(copy(nums), pow, true) 30 | end 31 | 32 | function setup() 33 | counts, numbers = [], [] 34 | for line in readlines() 35 | for i in eachindex(line) 36 | if length(counts) < i 37 | push!(counts, 0) 38 | end 39 | counts[i] += '1' == line[i] 40 | end 41 | push!(numbers, parse(Int, line, base=2)) 42 | end 43 | println(solve1(numbers, counts)) 44 | println(solve2(numbers, length(counts) - 1)) 45 | end 46 | 47 | setup() 48 | -------------------------------------------------------------------------------- /2021/03/example.ans: -------------------------------------------------------------------------------- 1 | 198 2 | 230 3 | -------------------------------------------------------------------------------- /2021/03/example.in: -------------------------------------------------------------------------------- 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/03/input.ans: -------------------------------------------------------------------------------- 1 | 2724524 2 | 2775870 3 | -------------------------------------------------------------------------------- /2021/04/4.jl: -------------------------------------------------------------------------------- 1 | bingos = [] 2 | 3 | scores = [] 4 | deleteBingos = [] 5 | 6 | function removeValue(val) 7 | for bingo in bingos 8 | for i in eachindex(bingo) 9 | if bingo[i] == val 10 | bingo[i] = 0 11 | end 12 | end 13 | end 14 | end 15 | 16 | function checkComplete(num) 17 | rows = [0 0 0 0 0] 18 | cols = [0 0 0 0 0] 19 | for (i, bingo) in enumerate(bingos) 20 | if any(x -> x == 0, [sum(bingo, dims=1)..., sum(bingo, dims=2)...]) 21 | s = sum(bingo) - sum((x -> x != 0).(bingo)) 22 | push!(scores, s * (num - 1)) 23 | push!(deleteBingos, i) 24 | end 25 | end 26 | return -1 27 | end 28 | 29 | function main() 30 | toInt(x) = parse(Int, x) 31 | lines = readlines() 32 | drawn = toInt.(split(lines[1], ",")) .+ 1 33 | y = 1 34 | for line in lines[2:end] 35 | ints = toInt.(split(line)) .+ 1 36 | if line == "" 37 | push!(bingos, zeros(Int, (5, 5))) 38 | y = 1 39 | continue 40 | end 41 | for i in eachindex(ints) 42 | bingos[end][y, i] = ints[i] 43 | end 44 | y += 1 45 | end 46 | for num in drawn 47 | removeValue(num) 48 | checkComplete(num) 49 | for i in reverse(deleteBingos) 50 | deleteat!(bingos, i) 51 | end 52 | empty!(deleteBingos) 53 | end 54 | println(scores[1]) 55 | println(scores[end]) 56 | end 57 | 58 | main() 59 | -------------------------------------------------------------------------------- /2021/04/example.ans: -------------------------------------------------------------------------------- 1 | 4512 2 | 1924 3 | -------------------------------------------------------------------------------- /2021/04/example.in: -------------------------------------------------------------------------------- 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/04/input.ans: -------------------------------------------------------------------------------- 1 | 33348 2 | 8112 3 | -------------------------------------------------------------------------------- /2021/05/5.jl: -------------------------------------------------------------------------------- 1 | function solve(lines, allow_diagonals) 2 | map = zeros(Int, (1001, 1001)) 3 | for line in lines 4 | from, to = split(line, " -> ") 5 | toCoords(x) = (a -> parse(Int, a)).(split(x, ",")) 6 | from = toCoords(from) .+ 1 # Shift all by one, so that Julia indices would work 7 | to = toCoords(to) .+ 1 8 | if any(from .== to) || allow_diagonals 9 | while from != to 10 | map[from[2], from[1]] += 1 11 | from += (to .> from) - (to .< from) 12 | end 13 | map[from[2], from[1]] += 1 14 | end 15 | end 16 | return sum(map .>= 2) 17 | end 18 | 19 | function main() 20 | lines = readlines() 21 | println(solve(lines, false)) 22 | println(solve(lines, true)) 23 | end 24 | 25 | main() 26 | -------------------------------------------------------------------------------- /2021/05/example.ans: -------------------------------------------------------------------------------- 1 | 5 2 | 12 3 | -------------------------------------------------------------------------------- /2021/05/example.in: -------------------------------------------------------------------------------- 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/05/input.ans: -------------------------------------------------------------------------------- 1 | 7468 2 | 22364 3 | -------------------------------------------------------------------------------- /2021/06/6.jl: -------------------------------------------------------------------------------- 1 | function solve(days, counts) 2 | for day in 1:days 3 | first = popfirst!(counts) 4 | push!(counts, 0) 5 | counts[7] += first 6 | counts[9] += first 7 | end 8 | return sum(counts) 9 | end 10 | 11 | nums = (x -> parse(Int, x)).(split(readline(), ',')) 12 | counts = [sum(nums .== i) for i in 0:9] 13 | 14 | println(solve(80, copy(counts))) 15 | println(solve(256, copy(counts))) 16 | 17 | -------------------------------------------------------------------------------- /2021/06/6.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | def solve(days, counter): 4 | for day in range(days): 5 | first, *rest = counter 6 | counter = rest + [0] 7 | counter[6] += first 8 | counter[8] += first 9 | return sum(counter) 10 | 11 | inp = Counter(map(int, input().split(','))) 12 | counts = [inp.get(i, 0) for i in range(10)] 13 | 14 | print(solve(80, counts[:])) 15 | print(solve(256, counts[:])) 16 | 17 | -------------------------------------------------------------------------------- /2021/06/example.ans: -------------------------------------------------------------------------------- 1 | 5934 2 | 26984457539 3 | -------------------------------------------------------------------------------- /2021/06/example.in: -------------------------------------------------------------------------------- 1 | 3,4,3,1,2 2 | -------------------------------------------------------------------------------- /2021/06/input.ans: -------------------------------------------------------------------------------- 1 | 379414 2 | 1705008653296 3 | -------------------------------------------------------------------------------- /2021/07/7.jl: -------------------------------------------------------------------------------- 1 | function solve(nums, use_growing=false) 2 | counter = zeros(Int, maximum(nums) + 1) 3 | grow = copy(counter) 4 | for num in nums 5 | counter[num + 1] += 1 6 | end 7 | s = 0 8 | while length(counter) > 1 9 | front, back = counter[1] + grow[1], counter[end] + grow[end] 10 | if front < back 11 | counter[2] += counter[1] 12 | popfirst!(counter) 13 | if use_growing 14 | popfirst!(grow) 15 | grow[1] = front 16 | end 17 | s += front 18 | else 19 | counter[end-1] += counter[end] 20 | pop!(counter) 21 | if use_growing 22 | pop!(grow) 23 | grow[end] = back 24 | end 25 | s += back 26 | end 27 | end 28 | return s 29 | end 30 | 31 | function main() 32 | nums = (x -> parse(Int, x)).(split(readlines()[1], ',')) 33 | println(solve(nums, false)) 34 | println(solve(nums, true)) 35 | end 36 | 37 | main() 38 | -------------------------------------------------------------------------------- /2021/07/example.ans: -------------------------------------------------------------------------------- 1 | 37 2 | 168 3 | -------------------------------------------------------------------------------- /2021/07/example.in: -------------------------------------------------------------------------------- 1 | 16,1,2,0,4,2,7,1,2,14 2 | -------------------------------------------------------------------------------- /2021/07/input.ans: -------------------------------------------------------------------------------- 1 | 325528 2 | 85015836 3 | -------------------------------------------------------------------------------- /2021/08/example.ans: -------------------------------------------------------------------------------- 1 | 26 2 | 61229 3 | -------------------------------------------------------------------------------- /2021/08/example.in: -------------------------------------------------------------------------------- 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/08/input.ans: -------------------------------------------------------------------------------- 1 | 387 2 | 986034 3 | -------------------------------------------------------------------------------- /2021/09/9.jl: -------------------------------------------------------------------------------- 1 | lines = (collect).(readlines()) 2 | 3 | function is_valid(y, x) 4 | return 1 <= x <= length(lines[1]) && 1 <= y <= length(lines) 5 | end 6 | 7 | 8 | function solve_a() 9 | s = 0 10 | for y in 1:length(lines) 11 | for x in 1:length(lines[y]) 12 | good = true 13 | for (xa, ya) in ((-1, 0), (1, 0), (0, 1), (0, -1)) 14 | if is_valid(y + ya, x + xa) 15 | if lines[y + ya][x + xa] <= lines[y][x] 16 | good = false 17 | end 18 | end 19 | end 20 | if good 21 | s += parse(Int, lines[y][x]) + 1 22 | end 23 | end 24 | end 25 | return s 26 | end 27 | 28 | function solve_b() 29 | basins = [] 30 | for Y in 1:length(lines) 31 | for X in 1:length(lines[Y]) 32 | queue = [(Y, X)] 33 | s = 0 34 | while !isempty(queue) 35 | y, x = popfirst!(queue) 36 | if lines[y][x] != '9' 37 | lines[y][x] = '9' 38 | s += 1 39 | for (xa, ya) in ((-1, 0), (1, 0), (0, 1), (0, -1)) 40 | if is_valid(y + ya, x + xa) 41 | push!(queue, (y + ya, x + xa)) 42 | end 43 | end 44 | end 45 | end 46 | push!(basins, s) 47 | end 48 | end 49 | return prod(sort(basins)[end-2:end]) 50 | end 51 | 52 | function main() 53 | println(solve_a()) 54 | println(solve_b()) 55 | end 56 | 57 | main() 58 | -------------------------------------------------------------------------------- /2021/09/example.ans: -------------------------------------------------------------------------------- 1 | 15 2 | 1134 3 | -------------------------------------------------------------------------------- /2021/09/example.in: -------------------------------------------------------------------------------- 1 | 2199943210 2 | 3987894921 3 | 9856789892 4 | 8767896789 5 | 9899965678 6 | -------------------------------------------------------------------------------- /2021/09/input.ans: -------------------------------------------------------------------------------- 1 | 577 2 | 1069200 3 | -------------------------------------------------------------------------------- /2021/10/10.jl: -------------------------------------------------------------------------------- 1 | function main() 2 | score = Dict(')' => 3, ']' => 57, '}' => 1197, '>' => 25137) 3 | opposite = Dict(')' => '(', ']' => '[', '}' => '{', '>' => '<') 4 | points = Dict('(' => 1, '[' => 2, '{' => 3, '<' => 4) 5 | s = 0 6 | scores = Vector{Int}() 7 | for line in readlines() 8 | stack = Vector{Char}() 9 | corrupted = false 10 | for char in line 11 | if char in "([{<" 12 | push!(stack, char) 13 | else 14 | last = pop!(stack) 15 | if opposite[char] != last 16 | s += score[char] 17 | corrupted = true 18 | break 19 | end 20 | end 21 | end 22 | if !corrupted 23 | curr = 0 24 | while !isempty(stack) 25 | curr = 5curr + points[pop!(stack)] 26 | end 27 | if curr != 0 28 | push!(scores, curr) 29 | end 30 | end 31 | end 32 | println(s) 33 | sort!(scores) 34 | println(scores[(length(scores)+1)÷2]) 35 | end 36 | 37 | main() 38 | -------------------------------------------------------------------------------- /2021/10/example.ans: -------------------------------------------------------------------------------- 1 | 26397 2 | 288957 3 | -------------------------------------------------------------------------------- /2021/10/example.in: -------------------------------------------------------------------------------- 1 | [({(<(())[]>[[{[]{<()<>> 2 | [(()[<>])]({[<{<<[]>>( 3 | {([(<{}[<>[]}>{[]{[(<()> 4 | (((({<>}<{<{<>}{[]{[]{} 5 | [[<[([]))<([[{}[[()]]] 6 | [{[{({}]{}}([{[{{{}}([] 7 | {<[[]]>}<{[{[{[]{()[[[] 8 | [<(<(<(<{}))><([]([]() 9 | <{([([[(<>()){}]>(<<{{ 10 | <{([{{}}[<[[[<>{}]]]>[]] 11 | -------------------------------------------------------------------------------- /2021/10/input.ans: -------------------------------------------------------------------------------- 1 | 462693 2 | 3094671161 3 | -------------------------------------------------------------------------------- /2021/11/11.jl: -------------------------------------------------------------------------------- 1 | function main() 2 | arr = collect.(readlines()) 3 | 4 | sy, sx = length(arr), length(arr[1]) 5 | is_valid(y, x) = 1 <= y <= sy && 1 <= x <= sx 6 | 7 | flashes = 0 8 | function flash(y, x) 9 | if arr[y][x] > '9' 10 | flashes += 1 11 | arr[y][x] = '0' 12 | for (y2, x2) in [(y+a, x+b) for a=-1:1, b=-1:1] 13 | if is_valid(y2, x2) && arr[y2][x2] != '0' 14 | arr[y2][x2] += 1 15 | flash(y2, x2) 16 | end 17 | end 18 | end 19 | end 20 | 21 | total_flashes = 0 22 | for step in 1:1000 23 | flashes = 0 24 | (a -> a .+= 1).(arr) 25 | for y in 1:sy, x in 1:sx 26 | flash(y, x) 27 | end 28 | total_flashes += flashes 29 | step == 100 && println(total_flashes) 30 | flashes == sy * sx && return println(step) 31 | end 32 | end 33 | 34 | main() 35 | -------------------------------------------------------------------------------- /2021/11/example.ans: -------------------------------------------------------------------------------- 1 | 1656 2 | 195 3 | -------------------------------------------------------------------------------- /2021/11/example.in: -------------------------------------------------------------------------------- 1 | 5483143223 2 | 2745854711 3 | 5264556173 4 | 6141336146 5 | 6357385478 6 | 4167524645 7 | 2176841721 8 | 6882881134 9 | 4846848554 10 | 5283751526 11 | -------------------------------------------------------------------------------- /2021/11/input.ans: -------------------------------------------------------------------------------- 1 | 1594 2 | 437 3 | -------------------------------------------------------------------------------- /2021/12/12.jl: -------------------------------------------------------------------------------- 1 | function solve(connections, use_twice=false) 2 | 3 | paths = Vector() 4 | visited = Set() 5 | function dfs(curr, can_still_use_twice=false, path=Vector()) 6 | key = curr * (curr in visited ? "2" : "") 7 | push!(path, curr) 8 | if lowercase(curr) == curr 9 | push!(visited, key) 10 | end 11 | if curr == "end" 12 | push!(paths, join(path, ',')) 13 | else 14 | for connection in connections[curr] 15 | if connection ∉ visited 16 | dfs(connection, can_still_use_twice, copy(path)) 17 | elseif can_still_use_twice && connection ∉ ["start", "end"] 18 | dfs(connection, false, copy(path)) 19 | end 20 | end 21 | end 22 | delete!(visited, key) 23 | end 24 | 25 | dfs("start", use_twice) 26 | return length(paths) 27 | end 28 | 29 | function main() 30 | connections = Dict() 31 | for line in readlines() 32 | from, to = split(line, '-') 33 | push!(get!(connections, from, Vector()), to) 34 | push!(get!(connections, to, Vector()), from) 35 | end 36 | println(solve(connections)) 37 | println(solve(connections, true)) 38 | end 39 | 40 | main() 41 | -------------------------------------------------------------------------------- /2021/12/example.ans: -------------------------------------------------------------------------------- 1 | 10 2 | 36 3 | -------------------------------------------------------------------------------- /2021/12/example.in: -------------------------------------------------------------------------------- 1 | start-A 2 | start-b 3 | A-c 4 | A-b 5 | b-d 6 | A-end 7 | b-end 8 | -------------------------------------------------------------------------------- /2021/12/input.ans: -------------------------------------------------------------------------------- 1 | 3369 2 | 85883 3 | -------------------------------------------------------------------------------- /2021/13/13.jl: -------------------------------------------------------------------------------- 1 | function main() 2 | coords = Set() 3 | first_fold = true 4 | for line in readlines() 5 | if ',' in line 6 | x, y = split(line, ',') .|> x -> parse(Int, x) 7 | push!(coords, (y, x)) 8 | elseif '=' in line 9 | fold_is_x = occursin("x=", line) 10 | fold_val = parse(Int, split(line, '=')[2]) 11 | new_coords = Set() 12 | for (y, x) in coords 13 | fold_x = fold_is_x ? min(0, fold_val - x) * 2 : 0 14 | fold_y = fold_is_x ? 0 : min(0, fold_val - y) * 2 15 | push!(new_coords, (y + fold_y, x + fold_x)) 16 | end 17 | coords = new_coords 18 | first_fold && length(coords) |> println 19 | first_fold = false 20 | end 21 | end 22 | y_max, x_max = maximum(coords) .+ 1 23 | field = [collect(" " ^ x_max) for _ in 1:y_max] 24 | for (y, x) in coords 25 | field[y + 1][x + 1] = '#' 26 | end 27 | field .|> join .|> println 28 | end 29 | 30 | main() 31 | -------------------------------------------------------------------------------- /2021/13/example.ans: -------------------------------------------------------------------------------- 1 | 17 2 | ##### 3 | # # 4 | # # 5 | # # 6 | ##### 7 | -------------------------------------------------------------------------------- /2021/13/example.in: -------------------------------------------------------------------------------- 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/13/input.ans: -------------------------------------------------------------------------------- 1 | 765 2 | ### #### # # #### # ### ## # # 3 | # # # # # # # # # # # # # 4 | # # # ## # # # # # #### 5 | ### # # # # # ### # ## # # 6 | # # # # # # # # # # # # 7 | # # #### # # #### #### # ### # # 8 | -------------------------------------------------------------------------------- /2021/14/14.jl: -------------------------------------------------------------------------------- 1 | dp, lookup = Dict(), Dict() 2 | function search_dp(key) 3 | key in keys(dp) && return dp[key] 4 | return dp[key] = sum(search_dp((key[1] - 1, letters)) for letters in lookup[key[2]]) 5 | end 6 | template = readline(); readline() 7 | for (from, to) in readlines() .|> line -> split(line, " -> ") 8 | dp[(1, from)] = [count(==(c), from[1] * to) for c in 'A':'Z'] 9 | lookup[from] = (from[1] * to, to * from[2]) 10 | end 11 | function solve(for_step) 12 | occ = sum(search_dp((for_step, a * b)) for (a, b) in zip(template, template[2:end])) 13 | occ[template[end] - 'A' + 1] += 1 14 | return maximum(occ) - minimum(filter(!=(0), occ)) 15 | end 16 | println(solve(10)) 17 | println(solve(40)) 18 | -------------------------------------------------------------------------------- /2021/14/example.ans: -------------------------------------------------------------------------------- 1 | 1588 2 | 2188189693529 3 | -------------------------------------------------------------------------------- /2021/14/example.in: -------------------------------------------------------------------------------- 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/14/input.ans: -------------------------------------------------------------------------------- 1 | 2891 2 | 4607749009683 3 | -------------------------------------------------------------------------------- /2021/15/15.jl: -------------------------------------------------------------------------------- 1 | using DataStructures 2 | lines = readlines() .|> collect 3 | small = [parse(Int, lines[y][x]) for y=1:length(lines), x=1:length(lines[1])] 4 | large = reduce(hcat, [(small .- 1 .+ i) .% 9 .+ 1 for i=0:4]) 5 | large = reduce(vcat, [(large .- 1 .+ i) .% 9 .+ 1 for i=0:4]) 6 | 7 | function solve(field) 8 | sy, sx = size(field) 9 | queue = PriorityQueue((1, 1) => 0) 10 | cost = Dict((1, 1) => 0) 11 | while !isempty(queue) 12 | (y, x), prio = dequeue_pair!(queue) 13 | cost[(y, x)] = prio 14 | y == sy && x == sx && return prio 15 | for (y2, x2) in eachrow([-1 0; 1 0; 0 -1; 0 1] .+ [y x]) 16 | if 1 <= y2 <= sy && 1 <= x2 <= sx && (y2, x2) ∉ keys(cost) 17 | newval, currval = (prio + field[y2, x2]), get(queue, (y2, x2), typemax(Int)) 18 | newval < currval && (queue[(y2, x2)] = newval) 19 | end 20 | end 21 | end 22 | end 23 | 24 | println(solve(small)) 25 | println(solve(large)) 26 | -------------------------------------------------------------------------------- /2021/15/example.ans: -------------------------------------------------------------------------------- 1 | 40 2 | 315 3 | -------------------------------------------------------------------------------- /2021/15/example.in: -------------------------------------------------------------------------------- 1 | 1163751742 2 | 1381373672 3 | 2136511328 4 | 3694931569 5 | 7463417111 6 | 1319128137 7 | 1359912421 8 | 3125421639 9 | 1293138521 10 | 2311944581 11 | -------------------------------------------------------------------------------- /2021/15/input.ans: -------------------------------------------------------------------------------- 1 | 472 2 | 2851 3 | -------------------------------------------------------------------------------- /2021/16/16.jl: -------------------------------------------------------------------------------- 1 | version_sum, bits = 0, join(reverse(digits(parse(BigInt, "1"*readline(), base=16), base=2))[2:end]) 2 | function parse_packet(index) # index is the current index in `bits` string, list of single integer 3 | take_int(count) = parse(Int, bits[index[1]:((index[1]+=count)-1)], base=2) 4 | global version_sum += take_int(3) 5 | id, c = take_int(3), true 6 | id == 4 && return reduce((a,b)->16a+b, [take_int(4) for _=1:99 if c == 1 && (c = take_int(1)) < 2]) 7 | apply_op(values) = reduce([+, *, min, max, id, >, <, ==][id + 1], values) 8 | if take_int(1) == 0 && (target_index = take_int(15) + index[1]) != 0 9 | return [parse_packet(index) for _=1:99 if index[1] < target_index] |> apply_op 10 | else 11 | return [parse_packet(index) for _=1:take_int(11)] |> apply_op 12 | end 13 | end 14 | parse_packet([1]) |> val -> println("$version_sum\n$val") # |> so that sum can be printed before val 15 | -------------------------------------------------------------------------------- /2021/16/16golfed.jl: -------------------------------------------------------------------------------- 1 | q=parse;r=reduce;v,b=0,join(reverse(digits(q(BigInt,"1"*readline(),base=16),base=2))[2:end]);function p(i);t(c)=q(Int,b[i[1]:((i[1]+=c)-1)],base=2);global v+=t(3);d,c=t(3),1;d==4&&return r((a,b)->16a+b,[t(4) for _=1:99 if c==1&&(c=t(1))<2]);a(v)=r([+,*,min,max,i,>,<,==][d+1],v);(t(1)==0&&(g=t(15)+i[1])!=0) ? (return[p(i) for _=1:99 if i[1]a) : return[p(i) for _=1:t(11)]|>a;end;p([1])|>b->println("$v\n$b") 2 | -------------------------------------------------------------------------------- /2021/16/example.ans: -------------------------------------------------------------------------------- 1 | 6 2 | 2021 3 | -------------------------------------------------------------------------------- /2021/16/example.in: -------------------------------------------------------------------------------- 1 | D2FE28 2 | -------------------------------------------------------------------------------- /2021/16/input.ans: -------------------------------------------------------------------------------- 1 | 936 2 | 6802496672062 3 | -------------------------------------------------------------------------------- /2021/17/17.jl: -------------------------------------------------------------------------------- 1 | x1, x2, y1, y2 = [parse(Int, m.match) for m in eachmatch(r"-?\d+", readline())] 2 | count = 0 3 | function simulate(yspeed, xspeed) 4 | x, y, maxy = 0, 0, 0 5 | while x <= x2 && y >= y1 6 | y, x = y + (yspeed -= 1), x + (xspeed -= xspeed > 0) 7 | maxy = max(y, maxy) 8 | x ∈ x1:x2 && y ∈ y1:y2 && (global count += 1) > 0 && return maxy 9 | end 10 | return 0 11 | end 12 | maximum(simulate(ys, xs) for ys=y1:200, xs=1:x2+1) |> m -> println("$m\n$count") 13 | -------------------------------------------------------------------------------- /2021/17/example.ans: -------------------------------------------------------------------------------- 1 | 45 2 | 112 3 | -------------------------------------------------------------------------------- /2021/17/example.in: -------------------------------------------------------------------------------- 1 | target area: x=20..30, y=-10..-5 2 | -------------------------------------------------------------------------------- /2021/17/input.ans: -------------------------------------------------------------------------------- 1 | 10296 2 | 2371 3 | -------------------------------------------------------------------------------- /2021/18/example.ans: -------------------------------------------------------------------------------- 1 | 4140 2 | 3993 3 | -------------------------------------------------------------------------------- /2021/18/example.in: -------------------------------------------------------------------------------- 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/18/input.ans: -------------------------------------------------------------------------------- 1 | 3494 2 | 4712 3 | -------------------------------------------------------------------------------- /2021/19/example.ans: -------------------------------------------------------------------------------- 1 | 79 2 | 3621 3 | -------------------------------------------------------------------------------- /2021/19/input.ans: -------------------------------------------------------------------------------- 1 | 359 2 | 12292 3 | -------------------------------------------------------------------------------- /2021/20/20.jl: -------------------------------------------------------------------------------- 1 | lookup, _, lines... = readlines() .|> s -> (Int.(collect(s) .== '#') |> join) 2 | default = '0' 3 | for iteration in 1:50 4 | sy, sx = length(lines), length(lines[1]) 5 | atmap(y, x) = (y ∈ 1:sy && x ∈ 1:sx) ? lines[y][x] : default 6 | get_index(Y, X) = parse(Int, join(atmap(Y+y, X+x) for x=-1:1, y=-1:1), base=2) + 1 7 | global lines = [[lookup[get_index(Y, X)] for X=0:sx+1] for Y=0:sy+1] 8 | global default = (default == '0') ? lookup[1] : lookup[end] 9 | iteration ∈ [2, 50] && println(lines .|> (line -> line .== '1') |> sum |> sum) 10 | end 11 | -------------------------------------------------------------------------------- /2021/20/example.ans: -------------------------------------------------------------------------------- 1 | 35 2 | 3351 3 | -------------------------------------------------------------------------------- /2021/20/example.in: -------------------------------------------------------------------------------- 1 | ..#.#..#####.#.#.#.###.##.....###.##.#..###.####..#####..#....#..#..##..###..######.###...####..#..#####..##..#.#####...##.#.#..#.##..#.#......#.###.######.###.####...#.##.##..#..#..#####.....#.#....###..#.##......#.....#..#..#..##..#...##.######.####.####.#.#...#.......#..#.#.#...####.##.#......#..#...##.#.##..#...##.#.##..###.#......#.#.......#.#.#.####.###.##...#.....####.#..#..#.##.#....##..#.####....##...##..#...#......#.#.......#.......##..####..#...#.#.#...##..#.#..###..#####........#..####......#..# 2 | 3 | #..#. 4 | #.... 5 | ##..# 6 | ..#.. 7 | ..### 8 | -------------------------------------------------------------------------------- /2021/20/input.ans: -------------------------------------------------------------------------------- 1 | 5339 2 | 18395 3 | -------------------------------------------------------------------------------- /2021/21/21.jl: -------------------------------------------------------------------------------- 1 | function part1(p1, p2, dice=100, goal=1000) 2 | s1, s2 = 0, 0 3 | die_value, rolls = 0, 0 4 | die() = rolls += 1; mod1(die_value += 1, dice) 5 | roll() = die() + die() + die() 6 | while s1 < goal || s2 < goal 7 | s1 += (p1 = mod1(p1 + roll(), 10)) 8 | s1 >= goal && break 9 | s2 += (p2 = mod1(p2 + roll(), 10)) 10 | end 11 | return min(s1, s2) * rolls 12 | end 13 | 14 | function part2(P1, P2, goal=22) # Add 1 to goal, since julia is 1 indexed, so dp lookup is different 15 | dp = zeros(Int64, (goal+11, goal+11, 10, 10, 2)) 16 | dp[1, 1, P1, P2, 1] = 1 17 | dice = [sum(1 for a=1:3, b=1:3, c=1:3 if a+b+c==s) for s=3:9] 18 | for s1=1:goal-1, s2=1:goal-1 19 | for d1=1:10, d2=1:10, add=3:9 20 | d1a = mod1(d1+add, 10) 21 | dp[s1+d1a, s2, d1a, d2, 2] += dp[s1, s2, d1, d2, 1] * dice[add-2] 22 | d2a = mod1(d2+add, 10) 23 | dp[s1, s2+d2a, d1, d2a, 1] += dp[s1, s2, d1, d2, 2] * dice[add-2] 24 | end 25 | end 26 | dps = sum(dp, dims=(3, 4, 5)) 27 | S1, S2 = 0, 0 28 | for s1=1:goal+11, s2=1:goal+11 29 | if max(s1, s2) >= goal 30 | s1 > s2 ? S1 += dps[s1, s2, 1, 1, 1] : S2 += dps[s1, s2, 1, 1, 1] 31 | end 32 | end 33 | return max(S1, S2) 34 | end 35 | 36 | function main() 37 | p1, p2 = parse.(Int, getindex.(split.(readlines(), ": "), 2)) 38 | println(part1(p1, p2)) 39 | println(part2(p1, p2)) 40 | end 41 | main() 42 | -------------------------------------------------------------------------------- /2021/21/example.ans: -------------------------------------------------------------------------------- 1 | 739785 2 | 444356092776315 3 | -------------------------------------------------------------------------------- /2021/21/example.in: -------------------------------------------------------------------------------- 1 | Player 1 starting position: 4 2 | Player 2 starting position: 8 3 | -------------------------------------------------------------------------------- /2021/21/input.ans: -------------------------------------------------------------------------------- 1 | 675024 2 | 570239341223618 3 | -------------------------------------------------------------------------------- /2021/22/22.jl: -------------------------------------------------------------------------------- 1 | function solve(data) 2 | volume(v) = prod(max(0, v[i+1] - v[i] + 1) for i=1:2:5) 3 | intersection(v1, v2) = [(i % 2 == 1 ? max : min)(v1[i], v2[i]) for i=1:6] 4 | cubes = [] 5 | for (onoff, nums) in data 6 | function remove_volume(original, remove) 7 | # Function to remove one cube from another, by replacing it with up to 6 other cubes 8 | intersecting = intersection(original, remove) 9 | volume(intersecting) == 0 && return [original] 10 | original_divided = [] 11 | add(v) = volume(v) != 0 && push!(original_divided, v) 12 | x, X, y, Y, z, Z = original 13 | xi, Xi, yi, Yi, zi, Zi = intersecting 14 | add([x, xi-1, y, Y, z, Z]) 15 | add([Xi+1, X, y, Y, z, Z]) 16 | add([xi, Xi, y, yi-1, z, Z]) 17 | add([xi, Xi, Yi+1, Y, z, Z]) 18 | add([xi, Xi, yi, Yi, z, zi-1]) 19 | add([xi, Xi, yi, Yi, Zi+1, Z]) 20 | return original_divided 21 | end 22 | # Remove the current cube from every previous cube (doesn't matter if on or off) 23 | !isempty(cubes) && (cubes = reduce(vcat, remove_volume(cube, nums) for cube in cubes)) 24 | # Add the cube if it is turned on 25 | onoff && push!(cubes, nums) 26 | end 27 | # Sum all cubes, since none are intersecting after the previous operations 28 | return cubes .|> volume |> sum 29 | end 30 | function main() 31 | extract_ints(str) = parse.(Int, m.match for m in eachmatch(r"-?\d+", str)) 32 | data = split.(readlines()) .|> sp -> (sp[1] == "on", extract_ints(sp[2])) 33 | data_part1 = filter(nums -> all(i ∈ -50:50 for i=nums[2]), data) 34 | 35 | println(solve(data_part1)) 36 | println(solve(data)) 37 | end 38 | main() 39 | -------------------------------------------------------------------------------- /2021/22/example.ans: -------------------------------------------------------------------------------- 1 | 474140 2 | 2758514936282235 3 | -------------------------------------------------------------------------------- /2021/22/input.ans: -------------------------------------------------------------------------------- 1 | 607657 2 | 1187742789778677 3 | -------------------------------------------------------------------------------- /2021/23/example.ans: -------------------------------------------------------------------------------- 1 | 12521 2 | 44169 3 | -------------------------------------------------------------------------------- /2021/23/example.in: -------------------------------------------------------------------------------- 1 | ############# 2 | #...........# 3 | ###B#C#B#D### 4 | #A#D#C#A# 5 | ######### 6 | -------------------------------------------------------------------------------- /2021/23/input.ans: -------------------------------------------------------------------------------- 1 | 16508 2 | 43626 3 | -------------------------------------------------------------------------------- /2021/24/24.jl: -------------------------------------------------------------------------------- 1 | # Already parsed input file, since this one depends so much on the input. 2 | # Making it general is not very useful. 3 | 4 | function main() 5 | div_z = [1, 1, 1, 1, 26, 1, 26, 26, 1, 1, 26, 26, 26, 26] 6 | add_x = [14, 13, 13, 12, -12, 12, -2, -11, 13, 14, 0, -12, -13, -6] 7 | add_w = [8, 8, 3, 10, 8, 8, 8, 5, 9, 3, 4, 9, 2, 7] 8 | num = 11111111111111 9 | function calculate_z() 10 | z, x = 0, 0 11 | for p=13:-1:0 12 | i = 14 - p 13 | w = (num ÷ 10^p) % 10 14 | x = (z % 26 + add_x[i]) != w 15 | z = z ÷ div_z[i] * (25x+1) + (w+add_w[i]) * x 16 | (w == 0 || div_z[i] == 26 && x != 0) && return num += 10^p; 17 | end 18 | return z 19 | end 20 | solutions = [] 21 | add_sol() = (push!(solutions, num); (num += 1)) 22 | while num < 1e14 23 | calculate_z() == 0 && add_sol() 24 | end 25 | println(solutions[end]) 26 | println(solutions[1]) 27 | end 28 | main() 29 | 30 | -------------------------------------------------------------------------------- /2021/24/input.ans: -------------------------------------------------------------------------------- 1 | 79997391969649 2 | 16931171414113 3 | -------------------------------------------------------------------------------- /2021/25/25.jl: -------------------------------------------------------------------------------- 1 | function main() 2 | game = readlines() .|> collect 3 | sy, sx = length(game), length(game[1]) 4 | for iteration in 1:1000 5 | something_changed = false 6 | new_pos = Dict() 7 | for (dir, addx, addy) in [('>', 1, 0), ('v', 0, 1)] 8 | for y in 1:sy, x in 1:sx 9 | if game[y][x] == dir 10 | ny, nx = mod1(y+addy, sy), mod1(x+addx, sx) 11 | if (game[ny][nx] == '.' || dir == 'v' && game[ny][nx] == '>') && (ny, nx) ∉ keys(new_pos) 12 | new_pos[(ny, nx)] = dir 13 | something_changed = true 14 | else 15 | new_pos[(y, x)] = dir 16 | end 17 | end 18 | end 19 | end 20 | game = [[get(new_pos, (y, x), '.') for x in 1:sx] for y in 1:sy] 21 | !something_changed && return println(iteration) 22 | end 23 | end 24 | main() 25 | -------------------------------------------------------------------------------- /2021/25/example.ans: -------------------------------------------------------------------------------- 1 | 58 2 | -------------------------------------------------------------------------------- /2021/25/example.in: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /2021/25/input.ans: -------------------------------------------------------------------------------- 1 | 498 2 | -------------------------------------------------------------------------------- /2022/01/01.kt: -------------------------------------------------------------------------------- 1 | fun main() { 2 | val input = generateSequence(::readlnOrNull).toList() 3 | val groups = input.scan(0) { s, e -> s + if (e == "") 1 else 0 } 4 | val elves = input 5 | .map { it.toIntOrNull() } 6 | .withIndex() 7 | .filter { it.value != null } 8 | .groupBy { groups[it.index] } 9 | .map { it.value.sumOf { it.value!! } } 10 | 11 | println(elves.max()) 12 | println(elves.sorted().takeLast(3).sum()) 13 | } 14 | -------------------------------------------------------------------------------- /2022/01/01.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | elves = sorted([sum(map(int, line.split("\n"))) for line in sys.stdin.read().strip().split("\n\n")]) 4 | 5 | print(elves[-1]) 6 | print(sum(elves[-3:])) 7 | -------------------------------------------------------------------------------- /2022/01/input.ans: -------------------------------------------------------------------------------- 1 | 69883 2 | 207576 3 | -------------------------------------------------------------------------------- /2022/02/02.kt: -------------------------------------------------------------------------------- 1 | val points = mapOf("A Y" to 6, "B Z" to 6, "C X" to 6, "A X" to 3, "B Y" to 3, "C Z" to 3) 2 | 3 | fun getPoints(s: String): Int = points.getOrDefault(s, 0) + "-XYZ".indexOf(s[2]) 4 | 5 | fun List.score() = this.map(::getPoints).sum() 6 | 7 | fun rotate(s: String): Char = "XYZ"[("ABC".indexOf(s[0]) + "YZX".indexOf(s[2])) % 3] 8 | 9 | fun List.newStrategy() = this.map { "${it[0]} ${rotate(it)}" } 10 | 11 | fun main() { 12 | val moves = generateSequence(::readlnOrNull).toList() 13 | println(moves.score()) 14 | println(moves.newStrategy().score()) 15 | } 16 | -------------------------------------------------------------------------------- /2022/02/02.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | points = {"A Y": 6, "B Z": 6, "C X": 6, "A X": 3, "B Y": 3, "C Z": 3} 4 | 5 | def score(moves: str): 6 | return points.get(moves, 0) + "-XYZ".index(moves[2]) 7 | 8 | def change(moves: str): 9 | index = ("ABC".index(moves[0]) + "YZX".index(moves[2])) % 3 10 | return moves[:2] + "XYZ"[index] 11 | 12 | lines = sys.stdin.read().strip().split("\n") 13 | 14 | print(sum(map(score, lines))) 15 | print(sum(map(score, map(change, lines)))) 16 | -------------------------------------------------------------------------------- /2022/02/example.ans: -------------------------------------------------------------------------------- 1 | 15 2 | 12 3 | -------------------------------------------------------------------------------- /2022/02/example.in: -------------------------------------------------------------------------------- 1 | A Y 2 | B X 3 | C Z 4 | -------------------------------------------------------------------------------- /2022/02/input.ans: -------------------------------------------------------------------------------- 1 | 11603 2 | 12725 3 | -------------------------------------------------------------------------------- /2022/03/03.kt: -------------------------------------------------------------------------------- 1 | fun main() { 2 | val rucksacks = generateSequence(::readlnOrNull).toList() 3 | val cost = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" 4 | 5 | val s1 = rucksacks 6 | .map { it.chunked(it.length / 2)} 7 | .map { it[0].toSet() intersect it[1].toSet() } 8 | .sumOf { cost.indexOf(it.first()) } 9 | println(s1) 10 | 11 | val s2 = rucksacks 12 | .chunked(3) 13 | .map { it[0].toSet() intersect it[1].toSet() intersect it[2].toSet() } 14 | .sumOf { cost.indexOf(it.first()) } 15 | println(s2) 16 | } 17 | -------------------------------------------------------------------------------- /2022/03/03.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import string 3 | s1, s2 = 0, 0 4 | lines = sys.stdin.read().strip().split("\n") 5 | 6 | for line in lines: 7 | half = len(line) // 2 8 | for c in set(line[:half]) & set(line[half:]): 9 | s1 += string.ascii_letters.index(c) + 1 10 | 11 | for l1, l2, l3 in zip(lines[0::3], lines[1::3], lines[2::3]): 12 | for c in set(l1) & set(l2) & set(l3): 13 | s2 += string.ascii_letters.index(c) + 1 14 | 15 | print(s1) 16 | print(s2) 17 | -------------------------------------------------------------------------------- /2022/03/example.ans: -------------------------------------------------------------------------------- 1 | 157 2 | 70 3 | -------------------------------------------------------------------------------- /2022/03/example.in: -------------------------------------------------------------------------------- 1 | vJrwpWtwJgWrhcsFMMfFFhFp 2 | jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL 3 | PmmdzqPrVvPwwTWBwg 4 | wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn 5 | ttgJtRGJQctTZtZT 6 | CrZsJsPPZsGzwwsLwLmpwMDw 7 | -------------------------------------------------------------------------------- /2022/03/input.ans: -------------------------------------------------------------------------------- 1 | 7863 2 | 2488 3 | -------------------------------------------------------------------------------- /2022/04/04.kt: -------------------------------------------------------------------------------- 1 | fun Boolean.toInt() = if (this) 1 else 0 2 | 3 | fun main() { 4 | val seq = generateSequence(::readlnOrNull).toList() 5 | .map { it.replace(',', '-').split('-') } 6 | .map { it.map { it.toInt() } } 7 | val s1 = seq 8 | .map { (a, b, c, d) -> (a..b intersect c..d).size-1 in setOf(b-a, d-c) } 9 | .sumOf { it.toInt() } 10 | val s2 = seq 11 | .map { it[0]..it[1] intersect it[2]..it[3] } 12 | .sumOf { (!it.isEmpty()).toInt() } 13 | println(s1) 14 | println(s2) 15 | } 16 | -------------------------------------------------------------------------------- /2022/04/04.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | s1 = s2 = 0 4 | for line in sys.stdin.readlines(): 5 | a, b, c, d = map(int, line.strip().replace(",", "-").split("-")) 6 | range1, range2 = set(range(a, b+1)), set(range(c, d+1)) 7 | 8 | s1 += len(range1 & range2) in (b-a+1, d-c+1) 9 | s2 += bool(range1 & range2) 10 | 11 | print(s1) 12 | print(s2) 13 | 14 | -------------------------------------------------------------------------------- /2022/04/example.ans: -------------------------------------------------------------------------------- 1 | 2 2 | 4 3 | -------------------------------------------------------------------------------- /2022/04/example.in: -------------------------------------------------------------------------------- 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/04/input.ans: -------------------------------------------------------------------------------- 1 | 459 2 | 779 3 | -------------------------------------------------------------------------------- /2022/05/05.kt: -------------------------------------------------------------------------------- 1 | fun solve(input: String, moveTogether: Boolean) { 2 | val (raw_towers, moves) = input.split("\n\n") 3 | val towers = raw_towers.split("\n").dropLast(1).asReversed() 4 | val stacks: MutableList> = mutableListOf() 5 | 6 | for (j in 1 until towers[0].length step 4) { 7 | stacks.add(mutableListOf()) 8 | for (i in 0 until towers.size) 9 | if (towers[i][j] != ' ') 10 | stacks.last().add(towers[i][j]) 11 | } 12 | val nums = moves 13 | .split("\n") 14 | .map {it.filter {!it.isLetter()}} 15 | .map { it.split(" ")} 16 | .map { it.map {it.trim().toInt()}} 17 | 18 | for ((num, from, to) in nums) { 19 | if (!moveTogether) 20 | for (i in 1..num) 21 | stacks[to-1].add(stacks[from-1].removeLast()) 22 | else { 23 | val tmp: MutableList = mutableListOf() 24 | for (i in 1..num) 25 | tmp.add(stacks[from-1].removeLast()) 26 | for (i in 1..num) 27 | stacks[to-1].add(tmp.removeLast()) 28 | 29 | } 30 | } 31 | println(stacks.map { it.last() }.joinToString("")) 32 | } 33 | 34 | fun main() { 35 | val input = generateSequence(::readlnOrNull).joinToString("\n") 36 | solve(input, false) 37 | solve(input, true) 38 | } 39 | -------------------------------------------------------------------------------- /2022/05/05.py: -------------------------------------------------------------------------------- 1 | import sys, re 2 | towers, instructions = sys.stdin.read().rstrip().split("\n\n") 3 | *towers, indices = towers.split("\n") 4 | tower_count = int(indices.strip().split()[-1]) 5 | 6 | stacks1 = [[] for _ in range(tower_count)] 7 | 8 | for line in towers[::-1]: 9 | for i in range(tower_count): 10 | c = line[i*4+1] 11 | if c != ' ': 12 | stacks1[i].append(c) 13 | 14 | stacks2 = [l.copy() for l in stacks1] 15 | 16 | for line in instructions.split("\n"): 17 | a, b, c = map(int, re.fullmatch(r"move (\d+) from (\d+) to (\d+)", line).groups()) 18 | for _ in range(a): 19 | new = stacks1[b-1].pop() 20 | stacks1[c-1].append(new) 21 | 22 | stacks2[c-1].extend(stacks2[b-1][-a:]) 23 | for _ in range(a): 24 | stacks2[b-1].pop() 25 | 26 | print(''.join(s[-1] for s in stacks1)) 27 | print(''.join(s[-1] for s in stacks2)) 28 | -------------------------------------------------------------------------------- /2022/05/input.ans: -------------------------------------------------------------------------------- 1 | MQSHJMWNH 2 | LLWJRBHVZ 3 | -------------------------------------------------------------------------------- /2022/06/06.kt: -------------------------------------------------------------------------------- 1 | fun String.solve(n: Int) = n + this.windowed(n).indexOfFirst { it.toSet().size == it.length } 2 | 3 | fun main() { 4 | val s = readln() 5 | println(s.solve(4)) 6 | println(s.solve(14)) 7 | } 8 | -------------------------------------------------------------------------------- /2022/06/06.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | def solve(n): 3 | for i in range(len(s)): 4 | if len(set(s[i:i+n])) == n: 5 | return i+n 6 | 7 | print(solve(4)) 8 | print(solve(14)) 9 | -------------------------------------------------------------------------------- /2022/06/input.ans: -------------------------------------------------------------------------------- 1 | 1794 2 | 2851 3 | -------------------------------------------------------------------------------- /2022/07/07.kt: -------------------------------------------------------------------------------- 1 | data class Tree(val name: String, var parent: Tree?) { 2 | var size: Int = 0 3 | val children: MutableList = mutableListOf() 4 | } 5 | 6 | fun main() { 7 | val shell = generateSequence(::readlnOrNull).toList() 8 | .map { it.replace("$ ", "") } 9 | .filter { it != "ls" } 10 | val root = Tree("/", null) 11 | var current = root 12 | for (line in shell) { 13 | var (command, arg) = line.split(" ") 14 | when (command) { 15 | "cd" -> when (arg) { 16 | "/" -> current = root 17 | ".." -> current = current.parent!! 18 | else -> current = current.children.filter { it.name == arg }.first() 19 | } 20 | "dir" -> current.children.add(Tree(arg, current)) 21 | else -> current.size += command.toInt() 22 | } 23 | } 24 | val sizes: MutableList = mutableListOf() 25 | fun recursiveSizes(tree: Tree): Int { 26 | sizes.add(tree.size + tree.children.sumOf(::recursiveSizes) ) 27 | return sizes.last() 28 | } 29 | recursiveSizes(root) 30 | println(sizes.filter { it <= 100000 }.sum()) 31 | val needed = 30000000 - (70000000 - sizes.max()) 32 | println(sizes.filter { it >= needed }.min()) 33 | } 34 | -------------------------------------------------------------------------------- /2022/07/07.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from dataclasses import dataclass, field 3 | 4 | @dataclass 5 | class Tree: 6 | name: str 7 | parent: "Tree" = None 8 | size: int = 0 9 | children: dict = field(default_factory=dict) 10 | 11 | current = root = Tree("/") 12 | 13 | for line in sys.stdin.read().strip().split("\n"): 14 | match line.split(): 15 | case ["$", "cd", "/"]: 16 | current = root 17 | case ["$", "cd", ".."]: 18 | current = current.parent or current 19 | case ["$", "cd", name]: 20 | current = current.children[name] 21 | case ["$", "ls"]: 22 | pass 23 | case ["dir", name]: 24 | current.children[name] = Tree(name, current) 25 | case [num, name]: 26 | current.size += int(num) 27 | 28 | sizes = [] 29 | def rec_size(tree): 30 | size = (tree.size or 0) + sum(map(rec_size, tree.children.values())) 31 | sizes.append(size) 32 | return size 33 | 34 | rec_size(root) 35 | 36 | print(sum(s for s in sizes if s <= 100000)) 37 | needed = 30000000 - (70000000 - max(sizes)) 38 | print(min([a for a in sorted(sizes) if a >= needed])) 39 | 40 | 41 | -------------------------------------------------------------------------------- /2022/07/input.ans: -------------------------------------------------------------------------------- 1 | 1749646 2 | 1498966 3 | -------------------------------------------------------------------------------- /2022/08/08.kt: -------------------------------------------------------------------------------- 1 | 2 | 3 | fun main() { 4 | val s = generateSequence(::readlnOrNull).toList() 5 | val indices = (0..s.size-1).toList() 6 | val visible: MutableSet> = mutableSetOf() 7 | var highest: Int 8 | for (i in indices) { 9 | for (order in listOf(indices, indices.reversed())) { 10 | highest = 0 11 | for (x in order) { 12 | if (highest < s[i][x].code) 13 | visible.add(Pair(i, x)) 14 | highest = maxOf(s[i][x].code, highest) 15 | } 16 | highest = 0 17 | for (y in order) { 18 | if (highest < s[y][i].code) 19 | visible.add(Pair(y, i)) 20 | highest = maxOf(s[y][i].code, highest) 21 | } 22 | } 23 | } 24 | println(visible.size) 25 | 26 | var best = 0 27 | fun is_valid(y: Int, x: Int, size: Int) = 0 <= y && y < size && 0 <= x && x < size 28 | for (Y in indices) { 29 | for (X in indices) { 30 | var scenic = 1 31 | for ((ya, xa) in listOf(Pair(1, 0), Pair(-1, 0), Pair(0, 1), Pair(0, -1))) { 32 | var dist = 0 33 | var y = Y+ya 34 | var x = X+xa 35 | while (is_valid(y, x, s.size)) { 36 | dist += 1 37 | if (s[y][x] >= s[Y][X]) 38 | break 39 | y = y+ya 40 | x = x+xa 41 | } 42 | scenic *= dist 43 | } 44 | best = maxOf(best, scenic) 45 | } 46 | } 47 | println(best) 48 | } 49 | -------------------------------------------------------------------------------- /2022/08/08.py: -------------------------------------------------------------------------------- 1 | import sys 2 | s = [list(a) for a in sys.stdin.read().strip().split("\n")] 3 | 4 | # === Part 1 === 5 | visible = set() 6 | indices = list(range(len(s))) 7 | for i in indices: 8 | for order in (indices, list(reversed(indices))): 9 | m = '/' 10 | for x in order: 11 | if m < s[i][x]: 12 | visible.add((i, x)) 13 | m = max(s[i][x], m) 14 | m = '/' 15 | for y in order: 16 | if m < s[y][i]: 17 | visible.add((y, i)) 18 | m = max(s[y][i], m) 19 | print(len(visible)) 20 | 21 | # === Part 2 === 22 | best = 0 23 | is_valid = lambda y, x: 0 <= y < len(s) and 0 <= x < len(s[0]) 24 | for Y in range(len(s)): 25 | for X in range(len(s[0])): 26 | scenic = 1 27 | for ya, xa in [(1, 0), (-1, 0), (0, 1), (0, -1)]: 28 | dist, y, x = 0, Y+ya, X+xa 29 | while is_valid(y, x): 30 | dist += 1 31 | if s[y][x] >= s[Y][X]: 32 | break 33 | y, x = y+ya, x+xa 34 | scenic *= dist 35 | best = max(best, scenic) 36 | print(best) 37 | -------------------------------------------------------------------------------- /2022/08/input.ans: -------------------------------------------------------------------------------- 1 | 1794 2 | 199272 3 | -------------------------------------------------------------------------------- /2022/09/09.kt: -------------------------------------------------------------------------------- 1 | operator fun Pair.plus(o: Pair) = Pair(this.first + o.first, this.second + o.second) 2 | 3 | fun main() { 4 | val input = generateSequence(::readlnOrNull).toList().map { it.split(" ") } 5 | val visited2: MutableSet> = mutableSetOf() 6 | val visited10: MutableSet> = mutableSetOf() 7 | val lookup = mapOf("D" to Pair(0, 1), "U" to Pair(0, -1), "L" to Pair(-1, 0), "R" to Pair(1, 0)) 8 | val rope = MutableList(10) { Pair(0, 0) } 9 | for ((dir, steps) in input) { 10 | for (j in 1..steps.toInt()) { 11 | rope[0] = rope[0] + lookup[dir]!! 12 | for (i in 0..rope.size-2) { 13 | val dx = rope[i].first - rope[i+1].first 14 | val dy = rope[i].second - rope[i+1].second 15 | if (Math.abs(dx) >= 2 || Math.abs(dy) >= 2) 16 | rope[i+1] = rope[i+1] + Pair(dx.coerceIn(-1..1), dy.coerceIn(-1..1)) 17 | } 18 | visited2.add(rope[1]) 19 | visited10.add(rope.last()) 20 | } 21 | } 22 | println(visited2.size) 23 | println(visited10.size) 24 | } 25 | -------------------------------------------------------------------------------- /2022/09/09.py: -------------------------------------------------------------------------------- 1 | import sys 2 | visited_segment2 = set() 3 | visited_segment10 = set() 4 | rope = [[0, 0] for _ in range(10)] 5 | lookup = {"L": (-1, 0), "R": (1, 0), "D": (0, 1), "U": (0, -1)} 6 | for dir, steps in [line.split() for line in sys.stdin.readlines()]: 7 | for _ in range(int(steps)): 8 | rope[0][0] += lookup[dir][0] 9 | rope[0][1] += lookup[dir][1] 10 | for i, ((hx, hy), (sx, sy)) in enumerate(zip(rope, rope[1:])): 11 | if abs(hx - sx) > 1 or abs(hy - sy) > 1: 12 | rope[i+1][0] += max(-1, min(hx - sx, 1)) 13 | rope[i+1][1] += max(-1, min(hy - sy, 1)) 14 | visited_segment2.add(tuple(rope[1])) 15 | visited_segment10.add(tuple(rope[-1])) 16 | print(len(visited_segment2)) 17 | print(len(visited_segment10)) 18 | -------------------------------------------------------------------------------- /2022/09/input.ans: -------------------------------------------------------------------------------- 1 | 6337 2 | 2455 3 | -------------------------------------------------------------------------------- /2022/10/10.kt: -------------------------------------------------------------------------------- 1 | fun main() { 2 | val vals = generateSequence(::readlnOrNull).joinToString("\n").split(" ", "\n") 3 | .map { it.toIntOrNull() ?: 0 } 4 | .scan(1, Int::plus) 5 | .withIndex() 6 | println(vals.filter { (it.index+1) % 40 == 20 }.sumOf { (it.index+1) * it.value }) 7 | val p2 = vals 8 | .map { (i, v) -> if (v-1 <= i % 40 && i % 40 <= v+1) "#" else " " } 9 | .chunked(40) 10 | .map { it.joinToString("") } 11 | println(p2.joinToString("\n").trim()) 12 | } 13 | -------------------------------------------------------------------------------- /2022/10/10.py: -------------------------------------------------------------------------------- 1 | import sys 2 | X, s = 1, 0 3 | crt = [[] for _ in range(6)] 4 | for cycle, line in enumerate(sys.stdin.read().replace(" ", "\n").split()): 5 | crt[cycle // 40].append('#' if X - 1 <= cycle % 40 <= X + 1 else ' ') 6 | if (cycle+1) % 40 == 20: 7 | s += X * (cycle+1) 8 | if line not in ["addx", "noop"]: 9 | X += int(line) 10 | print(s) 11 | print(*[''.join(line) for line in crt], sep='\n') 12 | -------------------------------------------------------------------------------- /2022/10/example.ans: -------------------------------------------------------------------------------- 1 | 13140 2 | ## ## ## ## ## ## ## ## ## ## 3 | ### ### ### ### ### ### ### 4 | #### #### #### #### #### 5 | ##### ##### ##### ##### 6 | ###### ###### ###### #### 7 | ####### ####### ####### 8 | -------------------------------------------------------------------------------- /2022/10/example.in: -------------------------------------------------------------------------------- 1 | addx 15 2 | addx -11 3 | addx 6 4 | addx -3 5 | addx 5 6 | addx -1 7 | addx -8 8 | addx 13 9 | addx 4 10 | noop 11 | addx -1 12 | addx 5 13 | addx -1 14 | addx 5 15 | addx -1 16 | addx 5 17 | addx -1 18 | addx 5 19 | addx -1 20 | addx -35 21 | addx 1 22 | addx 24 23 | addx -19 24 | addx 1 25 | addx 16 26 | addx -11 27 | noop 28 | noop 29 | addx 21 30 | addx -15 31 | noop 32 | noop 33 | addx -3 34 | addx 9 35 | addx 1 36 | addx -3 37 | addx 8 38 | addx 1 39 | addx 5 40 | noop 41 | noop 42 | noop 43 | noop 44 | noop 45 | addx -36 46 | noop 47 | addx 1 48 | addx 7 49 | noop 50 | noop 51 | noop 52 | addx 2 53 | addx 6 54 | noop 55 | noop 56 | noop 57 | noop 58 | noop 59 | addx 1 60 | noop 61 | noop 62 | addx 7 63 | addx 1 64 | noop 65 | addx -13 66 | addx 13 67 | addx 7 68 | noop 69 | addx 1 70 | addx -33 71 | noop 72 | noop 73 | noop 74 | addx 2 75 | noop 76 | noop 77 | noop 78 | addx 8 79 | noop 80 | addx -1 81 | addx 2 82 | addx 1 83 | noop 84 | addx 17 85 | addx -9 86 | addx 1 87 | addx 1 88 | addx -3 89 | addx 11 90 | noop 91 | noop 92 | addx 1 93 | noop 94 | addx 1 95 | noop 96 | noop 97 | addx -13 98 | addx -19 99 | addx 1 100 | addx 3 101 | addx 26 102 | addx -30 103 | addx 12 104 | addx -1 105 | addx 3 106 | addx 1 107 | noop 108 | noop 109 | noop 110 | addx -9 111 | addx 18 112 | addx 1 113 | addx 2 114 | noop 115 | noop 116 | addx 9 117 | noop 118 | noop 119 | noop 120 | addx -1 121 | addx 2 122 | addx -37 123 | addx 1 124 | addx 3 125 | noop 126 | addx 15 127 | addx -21 128 | addx 22 129 | addx -6 130 | addx 1 131 | noop 132 | addx 2 133 | addx 1 134 | noop 135 | addx -10 136 | noop 137 | noop 138 | addx 20 139 | addx 1 140 | addx 2 141 | addx 2 142 | addx -6 143 | addx -11 144 | noop 145 | noop 146 | noop 147 | -------------------------------------------------------------------------------- /2022/10/input.ans: -------------------------------------------------------------------------------- 1 | 15880 2 | ### # ## #### # # ## #### ## 3 | # # # # # # # # # # # # # 4 | # # # # ### ## # # # # 5 | ### # # ## # # # #### # # ## 6 | # # # # # # # # # # # # 7 | # #### ### # # # # # #### ### 8 | -------------------------------------------------------------------------------- /2022/11/11.py: -------------------------------------------------------------------------------- 1 | import sys, math, operator 2 | 3 | monkeys = [] 4 | 5 | class Monkey: 6 | modulo = 1 7 | def __init__(self, monkey: str): 8 | _, items, op, test, if_t, if_f = monkey.split("\n") 9 | self.items = [int(a) for a in items.split(":")[1].split(',')] 10 | ops = {"*": operator.mul, "+": operator.add} 11 | *_, op, arg = op.split(":")[1].split() 12 | self.op = lambda x: ops[op](x, x if arg == "old" else int(arg)) 13 | self.divisible_by = int(test.split()[-1]) 14 | Monkey.modulo *= self.divisible_by 15 | self.if_t = int(if_t.split()[-1]) 16 | self.if_f = int(if_f.split()[-1]) 17 | self.passes = 0 18 | 19 | def round(self, div_by_3: bool): 20 | for item in self.items: 21 | new_worry = self.op(item) // (3 if div_by_3 else 1) % Monkey.modulo 22 | self.passes += 1 23 | new_index = self.if_t if new_worry % self.divisible_by == 0 else self.if_f 24 | monkeys[new_index].items.append(new_worry) 25 | self.items.clear() 26 | 27 | 28 | monkeys2 = [] 29 | for i, monkey in enumerate(sys.stdin.read().strip().split("\n\n")): 30 | monkeys.append(Monkey(monkey)) 31 | monkeys2.append(Monkey(monkey)) 32 | 33 | for i in range(20): 34 | for monkey in monkeys: 35 | monkey.round(True) 36 | print(math.prod(sorted([a.passes for a in monkeys])[-2:])) 37 | 38 | monkeys = monkeys2 39 | for i in range(10000): 40 | for monkey in monkeys: 41 | monkey.round(False) 42 | print(math.prod(sorted([a.passes for a in monkeys])[-2:])) 43 | -------------------------------------------------------------------------------- /2022/11/input.ans: -------------------------------------------------------------------------------- 1 | 108240 2 | 25712998901 3 | -------------------------------------------------------------------------------- /2022/12/12.kt: -------------------------------------------------------------------------------- 1 | fun bfs(field: List, queue: MutableList>, target: Pair): Int { 2 | val dist = queue.associate { it to 0 }.toMutableMap() 3 | val dirs = listOf(-1 to 0, 1 to 0, 0 to 1, 0 to -1) 4 | while (!queue.isEmpty()) { 5 | val (y, x) = queue.removeFirst() 6 | dirs 7 | .map { (ya, xa) -> Pair(y+ya, x+xa) } 8 | .filter { (ya, xa) -> ya in field.indices && xa in field[0].indices } 9 | .filter { !dist.contains(it) } 10 | .filter { (ya, xa) -> field[ya][xa] <= field[y][x] + 1 } 11 | .forEach { 12 | dist[it] = dist[Pair(y, x)]!! + 1 13 | queue.add(it) 14 | } 15 | } 16 | return dist[target]!! 17 | } 18 | 19 | fun main() { 20 | var field = generateSequence(::readlnOrNull).toList() 21 | fun findChars(c: Char) = field 22 | .mapIndexed { y, l -> l.mapIndexed { x, _ -> y to x } } 23 | .flatten() 24 | .filter { (y, x) -> field[y][x] == c } 25 | .toMutableList() 26 | val S = findChars('S') 27 | val E = findChars('E').first() 28 | field = field.map { it.replace("S", "a").replace("E", "z") } 29 | println(bfs(field, S, E)) 30 | println(bfs(field, findChars('a'), E)) 31 | } 32 | -------------------------------------------------------------------------------- /2022/12/12.py: -------------------------------------------------------------------------------- 1 | import sys, collections 2 | 3 | field = sys.stdin.read().strip().split("\n") 4 | S = next((i, f.index('S')) for i, f in enumerate(field) if "S" in f) 5 | E = next((i, f.index('E')) for i, f in enumerate(field) if "E" in f) 6 | field = ' '.join(field).replace("S", "a").replace("E", "z").split() 7 | best_from_start = {} 8 | is_valid = lambda y, x: 0 <= y < len(field) and 0 <= x < len(field[0]) 9 | for sy, sx in [(sy, sx) for sy in range(len(field)) for sx in range(len(field[0]))]: 10 | if field[sy][sx] == 'a': 11 | queue = collections.deque([(sy, sx)]) 12 | dist = {(sy, sx): 0} 13 | while queue: 14 | y, x = queue.popleft() 15 | for y2, x2 in [(y+ya, x+xa) for ya, xa in [(1, 0), (-1, 0), (0, 1), (0, -1)]]: 16 | if is_valid(y2, x2) and (y2, x2) not in dist: 17 | if ord(field[y2][x2]) <= ord(field[y][x]) + 1: 18 | dist[(y2, x2)] = dist[(y, x)] + 1 19 | queue.append((y2, x2)) 20 | best_from_start[(sy, sx)] = dist.get(E, 1e9) 21 | print(best_from_start[S]) 22 | print(min(best_from_start.values())) 23 | 24 | -------------------------------------------------------------------------------- /2022/12/input.ans: -------------------------------------------------------------------------------- 1 | 391 2 | 386 3 | -------------------------------------------------------------------------------- /2022/13/13.kt: -------------------------------------------------------------------------------- 1 | fun String.parseLists(): Any { 2 | val stack: MutableList> = mutableListOf(mutableListOf()) 3 | this.replace("]", ",}").replace("[", "{,").replace(",,", ",").split(",").forEach { 4 | when (it) { 5 | "{" -> { val m: MutableList = mutableListOf(); stack.last().add(m); stack.add(m) } 6 | "}" -> stack.removeLast() 7 | else -> stack.last().add(it.toInt()) 8 | } 9 | } 10 | return stack[0][0] 11 | } 12 | 13 | fun cmp(a: Any, b: Any): Int { 14 | if (a is Int && b is Int) 15 | return when { a < b -> -1; a > b -> 1; else -> 0 } 16 | val aList = if (a is MutableList<*>) a else mutableListOf(a) 17 | val bList = if (b is MutableList<*>) b else mutableListOf(b) 18 | for ((u, v) in aList zip bList) 19 | if (cmp(u!!, v!!) != 0) 20 | return cmp(u, v) 21 | return cmp(aList.size, bList.size) 22 | } 23 | 24 | fun main() { 25 | var lists = generateSequence(::readlnOrNull) 26 | .filter { !it.isEmpty() } 27 | .map { it.parseLists() } 28 | .toMutableList() 29 | 30 | lists 31 | .chunked(2) 32 | .withIndex() 33 | .filter { (_, pair) -> cmp(pair[0], pair[1]) <= 0 } 34 | .sumOf { (i, _) -> i+1 } 35 | .also(::println) 36 | 37 | val distress = listOf(listOf(listOf(2)), listOf(listOf(6))) 38 | lists 39 | .also { it.addAll(distress) } 40 | .sortedWith(::cmp) 41 | .withIndex() 42 | .filter { it.value in distress } 43 | .fold(1) { acc, (i, _) -> (i+1) * acc } 44 | .also(::println) 45 | } 46 | -------------------------------------------------------------------------------- /2022/13/13.py: -------------------------------------------------------------------------------- 1 | import sys, functools 2 | 3 | def cmp(a, b): 4 | if isinstance(a, int) and isinstance(b, int): 5 | return 0 if a == b else (-1 if a < b else 1) 6 | a = [a] if isinstance(a, int) else a 7 | b = [b] if isinstance(b, int) else b 8 | return ([cmp(*p) for p in zip(a, b) if cmp(*p) != 0] + [cmp(len(a), len(b))])[0] 9 | 10 | lists = [eval(a) for a in sys.stdin.read().strip().replace("\n\n", "\n").split("\n")] 11 | print(sum(i for i, pair in enumerate(zip(lists[::2], lists[1::2]), 1) if cmp(*pair) <= 0)) 12 | 13 | new = sorted(lists + [[[2]], [[6]]], key=functools.cmp_to_key(cmp)) 14 | print((new.index([[2]]) + 1) * (new.index([[6]]) + 1)) 15 | -------------------------------------------------------------------------------- /2022/13/example.ans: -------------------------------------------------------------------------------- 1 | 13 2 | 140 3 | -------------------------------------------------------------------------------- /2022/13/example.in: -------------------------------------------------------------------------------- 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/13/input.ans: -------------------------------------------------------------------------------- 1 | 6076 2 | 24805 3 | -------------------------------------------------------------------------------- /2022/14/14.kt: -------------------------------------------------------------------------------- 1 | fun main() { 2 | val lines = generateSequence(::readlnOrNull).toList() 3 | .map { it.split(" -> ", ",").map { it.toInt() }.chunked(2) } 4 | val width = lines.flatten().maxOf { it[0] } + 200 5 | val height = lines.flatten().maxOf { it[1] } + 2 6 | val field = MutableList(height) { MutableList(width) { '.' } } 7 | fun range(a: Int, b: Int) = minOf(a, b)..maxOf(a, b) 8 | fun drawLine(rx: IntRange, ry: IntRange) = rx.map { x -> ry.map { y -> field[y][x] = '#' } } 9 | lines.map { it.zipWithNext { (x1, y1), (x2, y2) -> drawLine(range(x1, x2), range(y1, y2))} } 10 | 11 | fun fill(): Int { 12 | var endDfs = false 13 | fun dfs(x: Int, y: Int): Boolean { 14 | endDfs = endDfs || y >= field.size || field[0][500] == 'O' 15 | if (endDfs || field[y][x] != '.') 16 | return endDfs 17 | if (!(dfs(x, y+1) || dfs(x-1, y+1) || dfs(x+1, y+1))) 18 | field[y][x] = 'O' 19 | return true 20 | } 21 | while (!endDfs) dfs(500, 0) 22 | return field.flatten().count { it == 'O' } 23 | } 24 | println(fill()) 25 | field.add(MutableList(width) { '#' }) 26 | println(fill()) 27 | } 28 | -------------------------------------------------------------------------------- /2022/14/14.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | lines = [[list(map(int, c.split(','))) for c in l.strip().split(" -> ")] for l in stdin.readlines()] 3 | width = max(x+200 for x, _ in sum(lines, [])) 4 | height = max(y for _, y in sum(lines, [])) 5 | 6 | def solve(floor='.'): 7 | field = [['.'] * width for _ in range(height + 2)] + [[floor] * width] 8 | for walls in lines: 9 | for (x1, y1), (x2, y2) in zip(walls, walls[1:]): 10 | for x in range(min(x1, x2), max(x1, x2)+1): 11 | for y in range(min(y1, y2), max(y1, y2)+1): 12 | field[y][x] = '#' 13 | 14 | while True: 15 | sx, sy = 500, 0 16 | while sy+1 < len(field): 17 | for xa in (0, -1, 1): 18 | if field[sy+1][sx+xa] == '.': 19 | sy, sx = sy+1, sx+xa 20 | break 21 | else: 22 | field[sy][sx] = 'o' 23 | break 24 | if sy+1 >= len(field) or field[0][500] == 'o': 25 | return sum(field, []).count("o") 26 | 27 | print(solve(floor='.')) 28 | print(solve(floor='#')) 29 | -------------------------------------------------------------------------------- /2022/14/input.ans: -------------------------------------------------------------------------------- 1 | 793 2 | 24166 3 | -------------------------------------------------------------------------------- /2022/15/15.kt: -------------------------------------------------------------------------------- 1 | fun dist(x1: Long, y1: Long, x2: Long, y2: Long) = Math.abs(x1 - x2) + Math.abs(y1 - y2) 2 | 3 | fun main() { 4 | val sensors = generateSequence(::readlnOrNull).toList() 5 | .map { Regex("-?\\d+").findAll(it).toList() } 6 | .map { it.map { it.value.toLong() } } 7 | .sortedBy() { it[0] } 8 | val y = 2_000_000L 9 | (-1_000_000L..6_000_000L).count { x -> 10 | sensors 11 | .filter { it[2] != x || it[3] != y } 12 | .any { (xs, ys, xb, yb) -> dist(xs, ys, x, y) <= dist(xs, ys, xb, yb) } 13 | }.run(::println) 14 | 15 | for (y in 0L..4_000_000L) { 16 | var x = 0L 17 | for ((xs, ys, xb, yb) in sensors) 18 | if (dist(xs, ys, x, y) <= dist(xs, ys, xb, yb)) 19 | x = xs + dist(xs, ys, xb, yb) - Math.abs(ys - y) + 1 20 | if (x <= 4_000_000L) 21 | println(x * 4_000_000L + y) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /2022/15/15.py: -------------------------------------------------------------------------------- 1 | # Use pypy, as otherwise this is slow 2 | import sys, re 3 | lines = sys.stdin.read().strip().split("\n") 4 | sensors = sorted([[int(a) for a in re.findall(r"-?\d+", l)] for l in lines]) 5 | sensors = sorted([[*map(int, re.findall(r"-?\d+", l))] for l in lines]) 6 | dist = lambda x1, y1, x2, y2: abs(x1 - x2) + abs(y1 - y2) 7 | 8 | s, y = 0, 2_000_000 9 | for x in range(-1_000_000, 6_000_000): 10 | for sx, sy, bx, by in sensors: 11 | if dist(sx, sy, bx, by) >= dist(sx, sy, x, y) and (bx != x or by != y): 12 | s += 1 13 | break 14 | print(s) 15 | 16 | for y in range(4_000_001): 17 | x = 0 18 | for sx, sy, bx, by in sensors: 19 | if dist(sx, sy, bx, by) >= dist(sx, sy, x, y): 20 | x = sx + dist(sx, sy, bx, by) - abs(sy - y) + 1 21 | if x <= 4_000_000: 22 | print(x * 4_000_000 + y) 23 | -------------------------------------------------------------------------------- /2022/15/input.ans: -------------------------------------------------------------------------------- 1 | 5716881 2 | 10852583132904 3 | -------------------------------------------------------------------------------- /2022/16/example.ans: -------------------------------------------------------------------------------- 1 | 1651 2 | 1707 3 | -------------------------------------------------------------------------------- /2022/16/example.in: -------------------------------------------------------------------------------- 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/16/input.ans: -------------------------------------------------------------------------------- 1 | 1789 2 | 2496 3 | -------------------------------------------------------------------------------- /2022/17/example.ans: -------------------------------------------------------------------------------- 1 | 3068 2 | 1514285714288 3 | -------------------------------------------------------------------------------- /2022/17/example.in: -------------------------------------------------------------------------------- 1 | >>><<><>><<<>><>>><<<>>><<<><<<>><>><<>> 2 | -------------------------------------------------------------------------------- /2022/17/input.ans: -------------------------------------------------------------------------------- 1 | 3059 2 | 1500874635587 3 | -------------------------------------------------------------------------------- /2022/18/18.kt: -------------------------------------------------------------------------------- 1 | data class Point(var x: Int, var y: Int, var z: Int) { 2 | operator fun plus(o: Point): Point = Point(x+o.x, y+o.y, z+o.z) 3 | fun adjacent(): List = dirs.map { this+it }.toList() 4 | fun min(): Int = minOf(x, y, z) 5 | fun max(): Int = maxOf(x, y, z) 6 | } 7 | 8 | val dirs = listOf( 9 | Point(1, 0, 0), Point(0, 1, 0), Point(0, 0, 1), 10 | Point(-1, 0, 0), Point(0, -1, 0), Point(0, 0, -1), 11 | ) 12 | 13 | fun main() { 14 | val input = generateSequence(::readlnOrNull) 15 | .map { it.split(",").map { it.toInt() } } 16 | .map { (x, y, z) -> Point(x, y, z) }.toList() 17 | val bounds = input.minOf { it.min()-1 }..input.maxOf { it.max()+1 } 18 | 19 | // Part 1 20 | input.sumOf { it.adjacent().count { !input.contains(it) } }.run(::println) 21 | 22 | // Part 2 23 | val queue = mutableListOf(Point(bounds.first, bounds.first, bounds.first)) 24 | val visited: MutableSet = mutableSetOf() 25 | var count = 0 26 | 27 | while (queue.isNotEmpty()) { 28 | val point = queue.removeAt(0) 29 | if (point in visited) continue 30 | visited.add(point) 31 | for (adj in point.adjacent()) { 32 | if (adj in input) 33 | count++ 34 | else if (adj.x in bounds && adj.y in bounds && adj.z in bounds) 35 | queue.add(adj) 36 | } 37 | } 38 | println(count) 39 | } 40 | -------------------------------------------------------------------------------- /2022/18/input.ans: -------------------------------------------------------------------------------- 1 | 3448 2 | 2052 3 | -------------------------------------------------------------------------------- /2022/19/input.ans: -------------------------------------------------------------------------------- 1 | 1550 2 | 18630 3 | -------------------------------------------------------------------------------- /2022/20/20.kt: -------------------------------------------------------------------------------- 1 | import java.util.Collections.swap 2 | 3 | fun MutableList>.simulate(times: Int, decryptKey: Long = 1L) { 4 | for (index in 0 until size * times) { 5 | var i = indexOfFirst { it.index == index % size } 6 | var v = (this[i].value * decryptKey % (size-1)).toInt() 7 | repeat(Math.abs(v)) { i = (i + v / Math.abs(v)).mod(size).also { swap(this, i, it) } } 8 | } 9 | val i0 = indexOfFirst { it.value == 0L } 10 | (i0..i0+3000 step 1000).sumOf { this[it%size].value * decryptKey }.run(::println) 11 | } 12 | 13 | fun main() { 14 | generateSequence(::readlnOrNull).map { it.toLong() }.withIndex().toList() 15 | .also { it.toMutableList().simulate(1) } 16 | .also { it.toMutableList().simulate(10, 811589153L) } 17 | } 18 | -------------------------------------------------------------------------------- /2022/20/example.ans: -------------------------------------------------------------------------------- 1 | 3 2 | 1623178306 3 | -------------------------------------------------------------------------------- /2022/20/example.in: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | -3 4 | 3 5 | -2 6 | 0 7 | 4 8 | -------------------------------------------------------------------------------- /2022/20/input.ans: -------------------------------------------------------------------------------- 1 | 5904 2 | 8332585833851 3 | -------------------------------------------------------------------------------- /2022/21/21.kt: -------------------------------------------------------------------------------- 1 | fun main() { 2 | val input = generateSequence(::readlnOrNull).map { it.split(": ") }.toList() 3 | val known = input 4 | .filter { (_, value) -> value[0].isDigit() } 5 | .associate { (name, value) -> name to value.toDouble() } 6 | .toMutableMap() 7 | val inputsWithOps = input.filter { " " in it[1] }.map { (n, v) -> n to v.split(" ") } 8 | 9 | fun updateKnown() { 10 | for (i in 1..50) for ((name, value) in inputsWithOps) { 11 | var (var1, op, var2) = value 12 | if (var1 in known && var2 in known) 13 | known[name] = when (op) { 14 | "+" -> known[var1]!! + known[var2]!! 15 | "-" -> known[var1]!! - known[var2]!! 16 | "*" -> known[var1]!! * known[var2]!! 17 | "/" -> known[var1]!! / known[var2]!! 18 | else -> 0.0 19 | } 20 | } 21 | } 22 | updateKnown() 23 | println(Math.round(known["root"]!!)) 24 | val (rootVar1, _, rootVar2) = inputsWithOps.single { it.first == "root" }.second 25 | 26 | fun binSearch(increasing: Boolean): Long? { 27 | var (lo, hi) = -1e20 to 1e20 28 | repeat (100) { 29 | val mid = (lo + hi) / 2L 30 | known["humn"] = Math.round(mid).toDouble() 31 | updateKnown() 32 | if (known[rootVar1]!! == known[rootVar2]!!) 33 | return Math.round(mid) 34 | if ((known[rootVar1]!! > known[rootVar2]!!) xor increasing) 35 | hi = mid 36 | else 37 | lo = mid 38 | } 39 | return null 40 | } 41 | println(listOf(binSearch(true), binSearch(false)).firstNotNullOf { it }) 42 | } 43 | -------------------------------------------------------------------------------- /2022/21/example.ans: -------------------------------------------------------------------------------- 1 | 152 2 | 301 3 | -------------------------------------------------------------------------------- /2022/21/example.in: -------------------------------------------------------------------------------- 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/21/input.ans: -------------------------------------------------------------------------------- 1 | 66174565793494 2 | 3327575724809 3 | -------------------------------------------------------------------------------- /2022/22/input.ans: -------------------------------------------------------------------------------- 1 | 88226 2 | 57305 3 | -------------------------------------------------------------------------------- /2022/23/example.ans: -------------------------------------------------------------------------------- 1 | 110 2 | 20 3 | -------------------------------------------------------------------------------- /2022/23/example.in: -------------------------------------------------------------------------------- 1 | ....#.. 2 | ..###.# 3 | #...#.# 4 | .#...## 5 | #.###.. 6 | ##.#.## 7 | .#..#.. 8 | -------------------------------------------------------------------------------- /2022/23/input.ans: -------------------------------------------------------------------------------- 1 | 4091 2 | 1036 3 | -------------------------------------------------------------------------------- /2022/24/example.ans: -------------------------------------------------------------------------------- 1 | 18 2 | 54 3 | -------------------------------------------------------------------------------- /2022/24/example.in: -------------------------------------------------------------------------------- 1 | #.###### 2 | #>>.<^<# 3 | #.<..<<# 4 | #>v.><># 5 | #<^v^^># 6 | ######.# 7 | -------------------------------------------------------------------------------- /2022/24/input.ans: -------------------------------------------------------------------------------- 1 | 242 2 | 720 3 | -------------------------------------------------------------------------------- /2022/25/25.kt: -------------------------------------------------------------------------------- 1 | import kotlin.math.* 2 | fun pow5(e: Int): Long = 5.0.pow(e.toDouble()).toLong() 3 | 4 | fun main() { 5 | var s = generateSequence(::readlnOrNull) 6 | .map { it.map { "=-012".indexOf(it) - 2 } } 7 | .sumOf { it.reversed().mapIndexed { i, v -> pow5(i) * v }.sum() } 8 | 9 | for (power in log(1.0 * s, 5.0).toInt() downTo 0) 10 | (-2..2) 11 | .minBy { abs(s - pow5(power) * it) } 12 | .also { s -= pow5(power) * it } 13 | .also { print("=-012"[it+2]) } 14 | } 15 | -------------------------------------------------------------------------------- /2022/25/example.ans: -------------------------------------------------------------------------------- 1 | 2=-1=0 2 | -------------------------------------------------------------------------------- /2022/25/example.in: -------------------------------------------------------------------------------- 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 14 | -------------------------------------------------------------------------------- /2022/25/input.ans: -------------------------------------------------------------------------------- 1 | 20-==01-2-=1-2---1-0 2 | -------------------------------------------------------------------------------- /2023/01/01.py: -------------------------------------------------------------------------------- 1 | import re 2 | s1, s2 = 0, 0 3 | digits = "0|1|2|3|4|5|6|7|8|9|_|one|two|three|four|five|six|seven|eight|nine" 4 | as_num = lambda num: digits.split('|').index(num) % 10 5 | 6 | for line in open(0): 7 | nums1 = [as_num(n[1]) for n in re.finditer(f'(?=({digits[:20]}))', line) if n[1]] 8 | nums2 = [as_num(n[1]) for n in re.finditer(f'(?=({digits}))', line) if n[1]] 9 | s1 += nums1[0]*10 + nums1[-1] if nums1 else 0 10 | s2 += nums2[0]*10 + nums2[-1] if nums2 else 0 11 | print(s1, s2, sep="\n") 12 | -------------------------------------------------------------------------------- /2023/01/01.rs: -------------------------------------------------------------------------------- 1 | use std::io::Read; 2 | 3 | const DIGITS: [&str; 10] = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]; 4 | const WORDS: [&str; 10] = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]; 5 | 6 | fn main() { 7 | let mut input = String::new(); 8 | std::io::stdin().read_to_string(&mut input).unwrap(); 9 | 10 | let mut s1 = 0; 11 | let mut s2 = 0; 12 | for line in input.lines() { 13 | let mut nums: Vec<(usize, i32)> = vec![]; 14 | DIGITS.iter().for_each(|digit| { 15 | line.match_indices(digit) 16 | .for_each(|i| nums.push((i.0, i.1.parse().unwrap()))) 17 | }); 18 | nums.sort(); 19 | s1 += nums.first().unwrap_or(&(0, 0)).1 * 10 + nums.last().unwrap_or(&(0, 0)).1; 20 | 21 | WORDS.iter().for_each(|digit| { 22 | line.match_indices(digit).for_each(|i| { 23 | nums.push((i.0, WORDS.iter().position(|&x| x == i.1).unwrap() as i32)) 24 | }) 25 | }); 26 | nums.sort(); 27 | s2 += nums.first().unwrap_or(&(0, 0)).1 * 10 + nums.last().unwrap_or(&(0, 0)).1; 28 | } 29 | println!("{}\n{}", s1, s2); 30 | } -------------------------------------------------------------------------------- /2023/01/input.ans: -------------------------------------------------------------------------------- 1 | 54644 2 | 53348 3 | -------------------------------------------------------------------------------- /2023/02/02.py: -------------------------------------------------------------------------------- 1 | import re 2 | s1, s2 = 0, 0 3 | for i, line in enumerate(open(0), 1): 4 | r, g, b = [max(map(int, re.findall(fr"(\d+) {c}", line))) for c in "rgb"] 5 | s1 += (r <= 12 and g <= 13 and b <= 14) * i 6 | s2 += r * g * b 7 | 8 | print(s1, s2, sep="\n") 9 | -------------------------------------------------------------------------------- /2023/02/02.rs: -------------------------------------------------------------------------------- 1 | use std::io::Read; 2 | use regex::Regex; 3 | use std::cmp::max; 4 | 5 | fn main() { 6 | let mut input = String::new(); 7 | std::io::stdin().read_to_string(&mut input).unwrap(); 8 | let re = Regex::new(r"(\d+) (r|g|b)").unwrap(); 9 | 10 | let mut s1 = 0; 11 | let mut s2 = 0; 12 | for (index, line) in input.lines().enumerate() { 13 | let mut r = 0; 14 | let mut g = 0; 15 | let mut b = 0; 16 | for cap in re.captures_iter(line) { 17 | let num = cap.get(1).unwrap().as_str().parse().unwrap(); 18 | let col = cap.get(2).unwrap().as_str(); 19 | match col { 20 | "r" => r = max(r, num), 21 | "g" => g = max(g, num), 22 | "b" => b = max(b, num), 23 | _ => {} 24 | } 25 | 26 | } 27 | if r <= 12 && g <= 13 && b <= 14 { 28 | s1 += index + 1 29 | } 30 | s2 += r * g * b 31 | } 32 | println!("{}\n{}", s1, s2); 33 | } 34 | -------------------------------------------------------------------------------- /2023/02/input.ans: -------------------------------------------------------------------------------- 1 | 2156 2 | 66909 3 | -------------------------------------------------------------------------------- /2023/03/03.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | from collections import defaultdict 3 | 4 | lines = stdin.read().strip().split('\n') 5 | gear_to_num = defaultdict(list) 6 | s1 = 0 7 | 8 | def is_valid(y, x): 9 | return 0 <= y < len(lines) and 0 <= x < len(lines[0]) 10 | 11 | for y in range(len(lines)): 12 | for x_start in range(len(lines[y])): 13 | x_end = x_start 14 | if lines[y][x_start].isdigit() and (not is_valid(y, x_start-1) or not lines[y][x_start-1].isdigit()): 15 | while is_valid(y, x_end+1) and lines[y][x_end+1].isdigit(): 16 | x_end += 1 17 | good = False 18 | for yd in range(y-1, y+2): 19 | for xd in range(x_start-1, x_end+2): 20 | if is_valid(yd, xd) and lines[yd][xd] not in '.0123456789': 21 | good = True 22 | if lines[yd][xd] in '*': 23 | gear_to_num[(yd, xd)].append(int(lines[y][x_start:x_end+1])) 24 | 25 | s1 += good * int(lines[y][x_start:x_end+1]) 26 | 27 | s2 = sum(n[0] * n[1] for n in gear_to_num.values() if len(n) == 2) 28 | print(s1, s2, sep="\n") 29 | -------------------------------------------------------------------------------- /2023/03/03.rs: -------------------------------------------------------------------------------- 1 | use std::{io::{stdin, Read}, collections::HashMap}; 2 | use regex::Regex; 3 | 4 | fn is_valid(y: i32, x: i32, lines: &Vec<&str>) -> bool { 5 | (0..lines.len() as i32).contains(&y) && (0..lines[y as usize].len() as i32).contains(&x) 6 | } 7 | 8 | fn main() { 9 | let mut input = String::new(); 10 | stdin().read_to_string(&mut input).unwrap(); 11 | let lines = input.trim().split("\n").collect::>(); 12 | 13 | let mut gear_to_nums = HashMap::new(); 14 | 15 | let mut s1 = 0; 16 | let mut num; 17 | for (y, line) in lines.iter().enumerate() { 18 | let re = Regex::new(r"\d+").unwrap(); 19 | for cap in re.captures_iter(line).map(|g| g.get(0).unwrap()) { 20 | num = line[cap.start()..cap.end()].parse::().unwrap(); 21 | let mut good = false; 22 | for ya in y as i32 - 1..y as i32 + 2 { 23 | for xa in cap.start() as i32 - 1..cap.end() as i32 + 1 { 24 | if is_valid(ya, xa, &lines) { 25 | let c = lines[ya as usize].chars().nth(xa as usize).unwrap(); 26 | good |= !c.is_ascii_digit() && c != '.'; 27 | if c == '*' { 28 | gear_to_nums.entry((ya, xa)).or_insert_with(Vec::new).push(num); 29 | } 30 | } 31 | } 32 | } 33 | if good { 34 | s1 += num; 35 | } 36 | } 37 | } 38 | let s2: i32 = gear_to_nums 39 | .values() 40 | .filter(|v| v.len() == 2) 41 | .map(|v| v[0] * v[1]) 42 | .sum(); 43 | println!("{}\n{}", s1, s2); 44 | } -------------------------------------------------------------------------------- /2023/04/04.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | 3 | lines = stdin.read().strip().split("\n") 4 | p = 0 5 | repeat = [1] * len(lines) 6 | for i, line in enumerate(lines): 7 | right, left = line.split(":")[1].split("|") 8 | shared = len(set(right.split()) & set(left.split())) 9 | if shared: 10 | p += 2**(shared - 1) 11 | for j in range(i+1, min(i+1+shared, len(lines))): 12 | repeat[j] += repeat[i] 13 | print(p, sum(repeat), sep='\n') 14 | -------------------------------------------------------------------------------- /2023/05/05.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | 3 | seeds, *mappings = stdin.read().strip().split('\n\n') 4 | 5 | seeds = list(map(int, seeds.split()[1:])) 6 | mappings = [[[int(a) for a in m.split()] for m in maps.split('\n')[1:]] for maps in mappings] 7 | 8 | def solve(for_ranges): 9 | min_seed = (1e12, 1e12) 10 | for for_range in for_ranges: 11 | for seed in for_range: 12 | initial_seed = seed 13 | for mapping in mappings: 14 | for dst, src, size in mapping: 15 | if src <= seed < src + size: 16 | seed = dst + (seed - src) 17 | break 18 | if seed < min_seed[1]: 19 | min_seed = (initial_seed, seed) 20 | return min_seed 21 | 22 | print(solve([[seed] for seed in seeds])[1]) 23 | 24 | ranges = [range(s, s+count, 100000) for s, count in zip(seeds[0::2], seeds[1::2])] 25 | initial, _ = solve(ranges) 26 | print(solve([range(initial-100000, initial+1)])[1]) 27 | -------------------------------------------------------------------------------- /2023/06/06.py: -------------------------------------------------------------------------------- 1 | import re 2 | get_nums = lambda string: [int(a) for a in re.findall("\d+", string)] 3 | 4 | def solve(times, distances): 5 | times, distances = get_nums(times), get_nums(distances) 6 | result = 1 7 | for time, dist in zip(times, distances): 8 | result *= sum((time - start) * start > dist for start in range(time)) 9 | return result 10 | 11 | times, distances = input(), input() 12 | print(solve(times, distances)) 13 | print(solve(times.replace(' ', ''), distances.replace(' ', ''))) 14 | 15 | -------------------------------------------------------------------------------- /2023/07/07.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | from collections import Counter 3 | 4 | def sort_by(cards_and_bid, joker='_'): 5 | cards = cards_and_bid[0].replace(joker, "") 6 | types = [c[1] for c in Counter(cards).most_common()] or [0] 7 | types[0] += cards_and_bid[0].count(joker) 8 | strength = [f'{joker}23456789TJQKA'.index(card) for card in cards_and_bid[0]] 9 | return types, strength 10 | 11 | def solve(joker=''): 12 | as_sorted = sorted(hands, key=lambda k: sort_by(k, joker)) 13 | return sum(i * int(bid) for i, (cards, bid) in enumerate(as_sorted, 1)) 14 | 15 | hands = [line.split() for line in stdin.read().strip().split("\n")] 16 | 17 | print(solve()) 18 | print(solve(joker='J')) 19 | -------------------------------------------------------------------------------- /2023/08/08.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | import re 3 | import math 4 | 5 | rl, _, *lines = stdin.read().strip().split('\n') 6 | 7 | parsed = [re.findall(r'[A-Z]{3}', line) for line in lines] 8 | tree = {top: (left, right) for top, left, right in parsed} 9 | 10 | def solve(curr, s=0): 11 | while not curr.endswith('Z'): 12 | curr = tree[curr][rl[s % len(rl)] == 'R'] 13 | s+=1 14 | return s 15 | 16 | print(solve("AAA")) 17 | print(math.lcm(*[solve(top) for top in tree if top.endswith('A')])) 18 | 19 | 20 | -------------------------------------------------------------------------------- /2023/09/09.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | 3 | lines = stdin.read().strip().split('\n') 4 | 5 | first = last = 0 6 | for line in lines: 7 | diff = [int(a) for a in line.split()] 8 | sign = 1 9 | while any(diff): 10 | last += diff[-1] 11 | first += diff[0] * sign 12 | sign *= -1 13 | diff = [b - a for a, b in zip(diff, diff[1:])] 14 | 15 | print(first, last, sep='\n') 16 | -------------------------------------------------------------------------------- /2023/09/09.rs: -------------------------------------------------------------------------------- 1 | use std::io::{stdin, Read}; 2 | use itertools::Itertools; 3 | 4 | fn main() { 5 | let mut input = String::new(); 6 | stdin().read_to_string(&mut input).unwrap(); 7 | 8 | let mut first = 0; 9 | let mut last = 0; 10 | for line in input.lines() { 11 | let mut diff = line.split(' ').map(|n| n.parse().unwrap()).collect::>(); 12 | let mut sign = 1; 13 | while let [a, .., z] = *diff { 14 | first += a * sign; 15 | last += z; 16 | sign *= -1; 17 | diff = diff.iter().tuple_windows().map(|(a, b)| b - a).collect(); 18 | } 19 | } 20 | println!("{}\n{}", last, first); 21 | } -------------------------------------------------------------------------------- /2023/10/10.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | from collections import deque 3 | 4 | lines = stdin.read().strip().split('\n') 5 | 6 | dirs = [(0, 1), (1, 0), (-1, 0), (0, -1)] 7 | allowed = ["-7J", "|JL", "|F7", "-FL"] 8 | 9 | def is_valid(y, x): 10 | return -0.5 <= y < len(lines) and -0.5 <= x < len(lines[0]) 11 | 12 | q = deque() 13 | for y, line in enumerate(lines): 14 | if 'S' in line: 15 | q.append((y, line.index('S'), 0)) 16 | 17 | # Part 1: use BFS with allow_from and allow_to to check whether there is a connection 18 | inside = {(y, x) for y in range(len(lines)) for x in range(len(lines[0]))} 19 | visited = set() 20 | max_dist = 0 21 | 22 | while q: 23 | y, x, dist = q.popleft() 24 | max_dist = max(max_dist, dist) 25 | visited.add((y, x)) 26 | inside.discard((y, x)) 27 | 28 | for (dy, dx), allow_to, allow_from in zip(dirs, allowed, allowed[::-1]): 29 | ya, xa = y+dy, x+dx 30 | if is_valid(ya, xa) and lines[ya][xa] in allow_to and lines[y][x] in allow_from+"S": 31 | if (ya, xa) not in visited: 32 | q.append((ya, xa, dist+1)) 33 | visited.add((y+dy/2, x+dx/2)) 34 | 35 | 36 | # Part 2: use a 0.5 grid to find all non-visited spaces, using the same visited set as in P1. 37 | # Since we start outside of the grid, any cells inside will not be reached. 38 | q.append((-0.5, -0.5)) 39 | 40 | while q: 41 | y, x = q.popleft() 42 | inside.discard((y, x)) 43 | 44 | for dy, dx in dirs: 45 | ya, xa = y+dy/2, x+dx/2 46 | if is_valid(ya, xa) and (ya, xa) not in visited: 47 | q.append((ya, xa)) 48 | visited.add((ya, xa)) 49 | 50 | print(max_dist) 51 | print(len(inside)) 52 | -------------------------------------------------------------------------------- /2023/11/11.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | from itertools import combinations, product 3 | 4 | lines = stdin.read().strip().split('\n') 5 | 6 | Ys, Xs = len(lines), len(lines[0]) 7 | cols = [0] * Ys 8 | rows = [0] * Xs 9 | 10 | for y, line in enumerate(lines): 11 | if line.count('.') == len(line): 12 | rows[y] += 1 13 | for x in range(Xs): 14 | if all(lines[y][x] != '#' for y in range(Ys)): 15 | cols[x] += 1 16 | 17 | galaxies = [(y, x) for y, x in product(range(Ys), range(Xs)) if lines[y][x] == '#'] 18 | 19 | def solve(multiplier=1, s=0): 20 | for (y, x), (Y, X) in combinations(galaxies, r=2): 21 | y, Y = sorted([y, Y]) 22 | x, X = sorted([x, X]) 23 | s += Y - y + X - x + (sum(rows[y:Y]) + sum(cols[x:X])) * multiplier 24 | return s 25 | 26 | print(solve()) 27 | print(solve(1000000-1)) 28 | 29 | -------------------------------------------------------------------------------- /2023/12/12.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | from functools import cache 3 | 4 | @cache 5 | def decide(line, curr, needed, s=0): 6 | if not line: 7 | return (needed or (0,)) == (curr,) 8 | 9 | match line[0]: 10 | case '?': 11 | s += decide('.' + line[1:], curr, needed) 12 | s += decide('#' + line[1:], curr, needed) 13 | case '#' if needed and curr < needed[0]: 14 | s += decide(line[1:], curr+1, needed) 15 | case '.' if not needed or curr == 0: 16 | s += decide(line[1:], 0, needed) 17 | case '.' if curr == needed[0]: 18 | s += decide(line[1:], 0, needed[1:]) 19 | return s 20 | 21 | s1 = s2 = 0 22 | for line in stdin: 23 | chars, needed = line.split() 24 | needed = tuple(int(n) for n in needed.split(",")) 25 | 26 | s1 += decide(chars, 0, needed) 27 | s2 += decide('?'.join([chars] * 5), 0, needed * 5) 28 | 29 | print(s1, s2, sep='\n') 30 | -------------------------------------------------------------------------------- /2023/13/13.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | import re 3 | from collections import defaultdict, Counter, deque 4 | from itertools import permutations, combinations 5 | 6 | fields = stdin.read().strip().split('\n\n') 7 | 8 | def count_wrong_reflections(field, x): 9 | wrong = 0 10 | for y in range(len(field)): 11 | wrong += sum(a != b for a, b in zip(field[y][:x][::-1], field[y][x:])) 12 | return wrong 13 | 14 | s1 = s2 = 0 15 | for field in fields: 16 | field = field.split('\n') 17 | for x in range(1, len(field[0])): 18 | reflections = count_wrong_reflections(field, x) 19 | s1 += x if reflections == 0 else 0 20 | s2 += x if reflections == 1 else 0 21 | 22 | transposed = list(zip(*field)) 23 | for y in range(1, len(transposed[0])): 24 | reflections = count_wrong_reflections(transposed, y) 25 | s1 += y*100 if reflections == 0 else 0 26 | s2 += y*100 if reflections == 1 else 0 27 | 28 | print(s1, s2, sep="\n") 29 | -------------------------------------------------------------------------------- /2023/14/14.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | 3 | DIRS = [(-1, 0), (0, -1), (1, 0), (0, 1)] 4 | 5 | lines = [list(line.strip()) for line in stdin] 6 | 7 | Y, X = len(lines), len(lines[0]) 8 | coords = [(y, x) for y in range(Y) for x in range(X)] 9 | 10 | def find_o_coords(): 11 | return [(y, x) for y, x in coords if lines[y][x] == 'O'] 12 | 13 | seen = {} 14 | 15 | for i in range(1, 10000): 16 | for yd, xd in DIRS: 17 | for y, x in find_o_coords(): 18 | ybest, xbest = yo, xo = y, x 19 | while 0 <= y < Y and 0 <= x < X and lines[y][x] != '#': 20 | if lines[y][x] == '.': 21 | ybest, xbest = y, x 22 | y, x = y+yd, x+xd 23 | lines[yo][xo], lines[ybest][xbest] = lines[ybest][xbest], lines[yo][xo] 24 | 25 | load_on_beams = sum(Y-y for y, _ in find_o_coords()) 26 | if i == 1 and (yd, xd) == DIRS[0]: 27 | print(load_on_beams) 28 | 29 | if str(lines) in seen: 30 | repeat_interval = i - seen[str(lines)] 31 | if (1_000_000_000 - i) % repeat_interval == 0: 32 | print(load_on_beams) 33 | exit() 34 | seen[str(lines)] = i 35 | -------------------------------------------------------------------------------- /2023/15/15.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | 3 | def hash(s, val=0): 4 | return hash(s[1:], (val + ord(s[0])) * 17 % 256) if s else val 5 | 6 | boxes = [{} for _ in range(256)] 7 | s1 = s2 = 0 8 | for step in stdin.read().strip().split(','): 9 | s1 += hash(step) 10 | match step.replace('-', '=').partition("="): 11 | case [label, "=", ""]: 12 | boxes[hash(label)].pop(label, None) 13 | case [label, "=", num]: 14 | boxes[hash(label)][label] = int(num) 15 | 16 | for i, box in enumerate(boxes, 1): 17 | for j, num in enumerate(box.values(), 1): 18 | s2 += i * j * num 19 | 20 | print(s1, s2, sep='\n') 21 | -------------------------------------------------------------------------------- /2023/16/16.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.setrecursionlimit(10000000) 3 | 4 | lines = sys.stdin.read().strip().split('\n') 5 | 6 | dirs = [(0, 1), (1, 0), (0, -1), (-1, 0)] 7 | Y, X = len(lines), len(lines[0]) 8 | 9 | def go(y, x, d, visited, return_energized=True): 10 | if 0 <= y < Y and 0 <= x < X and (y, x, d) not in visited: 11 | visited.add((y, x, d)) 12 | go_dir = lambda d: go(y+d[0], x+d[1], d, visited, False) 13 | match lines[y][x]: 14 | case '/': 15 | go_dir((-d[1], -d[0])) 16 | case '\\': 17 | go_dir((d[1], d[0])) 18 | case '|': 19 | go_dir(dirs[1]) 20 | go_dir(dirs[3]) 21 | case '-': 22 | go_dir(dirs[0]) 23 | go_dir(dirs[2]) 24 | case _: 25 | go_dir(d) 26 | if return_energized: 27 | return len({(y, x) for y, x, _ in visited}) 28 | 29 | p2 = [] 30 | for y in range(Y): 31 | for x in range(X): 32 | for is_edge, (dy, dx) in zip((x == 0, y == 0, x == X-1, y == Y-1), dirs): 33 | if is_edge: 34 | p2 += [go(y, x, (dy, dx), set())] 35 | 36 | print(go(0, 0, dirs[0], set())) 37 | print(max(p2)) 38 | -------------------------------------------------------------------------------- /2023/17/17.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | from queue import PriorityQueue 3 | 4 | lines = stdin.read().splitlines() 5 | Y, X = len(lines), len(lines[0]) 6 | dirs = [(0, 1), (1, 0), (0, -1), (-1, 0)] 7 | 8 | def solve(min_straight, max_straight): 9 | q = PriorityQueue() 10 | q.put((0, 0, 0, 0, 0)) 11 | visited = set() 12 | while not q.empty(): 13 | dist, y, x, movedy, movedx = tup = q.get() 14 | if y == Y-1 and x == X-1: 15 | return dist 16 | if tup[1:] in visited: 17 | continue 18 | visited.add(tup[1:]) 19 | for dy, dx in dirs: 20 | ay, ax = y+dy, x+dx 21 | if movedy * dy < 0 or movedx * dx < 0: 22 | continue # prevent reversing 23 | movedy2 = movedy + dy 24 | movedx2 = movedx + dx 25 | straight = max(abs(movedy2), abs(movedx2)) 26 | if abs(movedy2) > 0 and abs(movedx2) > 0: 27 | if straight < min_straight: 28 | continue # prevent turning if not at least n straight 29 | movedy2 *= abs(dy) 30 | movedx2 *= abs(dx) 31 | 32 | new_tup = (ay, ax, movedy2, movedx2) 33 | if 0 <= ay < Y and 0 <= ax < X and straight <= max_straight and new_tup not in visited: 34 | q.put((dist+int(lines[ay][ax]), ay, ax, movedy2, movedx2)) 35 | 36 | print(solve(0, 3)) 37 | print(solve(4, 10)) 38 | -------------------------------------------------------------------------------- /2023/18/18.py: -------------------------------------------------------------------------------- 1 | def solve(instructions, s=2, xy=0.): 2 | for d in instructions: 3 | s += abs(d.real+d.imag) + d.imag*xy.real - d.real*xy.imag 4 | xy += d 5 | print(int(s // 2)) 6 | 7 | split = [line.split() for line in open(0)] 8 | solve(1j**"RDLU".index(d) * int(num) for d, num, _ in split) 9 | solve(1j**int(c[7]) * int(c[2:7], 16) for *_, c in split) 10 | -------------------------------------------------------------------------------- /2023/18/18_non-complex.py: -------------------------------------------------------------------------------- 1 | dirs = [(0, 1), (1, 0), (0, -1), (-1, 0)] 2 | 3 | def solve(instructions, s=0, y=0, x=0): 4 | for d, num in instructions: 5 | y2 = y + num * dirs[d][0] 6 | x2 = x + num * dirs[d][1] 7 | s += num + (y2*x - x2*y) # Border + Shoelace formula 8 | y, x = y2, x2 9 | print(s // 2 + 1) 10 | 11 | split = [line.split() for line in open(0)] 12 | solve(("RDLU".index(d), int(num)) for d, num, _ in split) 13 | solve((int(c[7]), int(c[2:7], 16)) for *_, c in split) 14 | -------------------------------------------------------------------------------- /2023/18/18scanline.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | from collections import defaultdict 3 | 4 | lines = stdin.read().splitlines() 5 | dirs = {"R": (0, 1), "D": (1, 0), "L": (0, -1), "U": (-1, 0)} 6 | 7 | def solve(instructions): 8 | y = x = s = 0 9 | y_vis = defaultdict(list) 10 | x_vis = defaultdict(list) 11 | for d, num in instructions: 12 | if d in "RL": 13 | x_prev = x 14 | x += num * dirs[d][1] 15 | s += abs(x_prev - x) - 1 16 | x_vis[y].append(sorted([x_prev, x])) 17 | else: 18 | ynext = y + num * dirs[d][0] 19 | for ya in range(min(ynext, y), max(ynext, y)+1): 20 | y_vis[ya].append((x, d)) 21 | y = ynext 22 | 23 | for y, xs in y_vis.items(): 24 | xs.sort() 25 | curr, d = xs[0] 26 | indices = [0] 27 | for i, ((_, d1), (_, d2)) in enumerate(zip(xs, xs[1:])): 28 | if d1 != d2 and d2 == xs[0][1]: 29 | indices.append(i+1) 30 | indices.append(len(xs)) 31 | for i1, i2 in zip(indices, indices[1:]): 32 | x1, d1 = xs[i1] 33 | x2, d2 = xs[i2-1] 34 | for a1, a2 in x_vis[y]: 35 | if x1 <= a1 < a2 <= x2: 36 | s -= a2 - a1 - 1 # Remove x line which were counted twice 37 | s += x2 - x1 + 1 38 | return s 39 | 40 | 41 | split = [line.split() for line in lines] 42 | print(solve([(d, int(num)) for d, num, _ in split])) 43 | print(solve([("RDLU"[int(c[-2])], int(c[2:-2], 16)) for *_, c in split])) 44 | -------------------------------------------------------------------------------- /2023/19/19.py: -------------------------------------------------------------------------------- 1 | import re 2 | import math 3 | instructions, queries = open(0).read().split('\n\n') 4 | 5 | rules = {} 6 | 7 | def is_accepted(x, m, a, s, rule): 8 | if len(rule) == 1: 9 | if rule[0][0] in rules: 10 | return is_accepted(x, m, a, s, rules[rule[0][0]]) 11 | return rule[0][0] == 'A' 12 | condition, trueval = rule[0] 13 | if eval(condition): 14 | return is_accepted(x, m, a, s, [[trueval]]) 15 | return is_accepted(x, m, a, s, rule[1:]) 16 | 17 | def range_combinations(ranges, rule): 18 | if len(rule) == 1: 19 | if (curr := rule[0][0]) in rules: 20 | return range_combinations(ranges, rules[curr]) 21 | return math.prod(map(len, ranges.values())) * (curr == 'A') 22 | (var, op, *digits), trueval = rule[0] 23 | num = int(''.join(digits)) + (op == '>') 24 | lower = range(ranges[var].start, num) 25 | upper = range(num, ranges[var].stop) 26 | 27 | rtrue = ranges | {var: lower if op == '<' else upper} 28 | rfalse = ranges | {var: upper if op == '<' else lower} 29 | return range_combinations(rtrue, [[trueval]]) \ 30 | + range_combinations(rfalse, rule[1:]) 31 | 32 | 33 | for inst in instructions.splitlines(): 34 | name, conditions = inst.strip("}").split("{") 35 | rules[name] = [rule.split(":") for rule in conditions.split(',')] 36 | 37 | s = 0 38 | for query in queries.splitlines(): 39 | xmas = [int(a) for a in re.findall("(\d+)", query)] 40 | if is_accepted(*xmas, rules["in"]): 41 | s += sum(xmas) 42 | 43 | print(s) 44 | ranges = {key: range(1, 4001) for key in "xmas"} 45 | print(range_combinations(ranges, rules['in'])) 46 | -------------------------------------------------------------------------------- /2023/20/20.py: -------------------------------------------------------------------------------- 1 | from collections import deque 2 | import math 3 | 4 | modules = {} 5 | flipflops = {} 6 | conjunctions = {} 7 | rx_parent = '' 8 | 9 | for line in open(0): 10 | name, destinations = line.strip().split(" -> ") 11 | pure_name = name.strip("&%") 12 | modules[pure_name] = destinations.split(', ') 13 | if name[0] == '%': 14 | flipflops[pure_name] = False 15 | elif name[0] == '&': 16 | conjunctions[pure_name] = {} 17 | 18 | for name, destinations in modules.items(): 19 | for dest in destinations: 20 | if dest in conjunctions: 21 | conjunctions[dest][name] = False 22 | if dest == 'rx': 23 | rx_parent = name 24 | 25 | q = deque() 26 | counts = [0, 0] 27 | rx_repeats = [False] * len(conjunctions[rx_parent]) 28 | 29 | def push(name, i, send=False): 30 | if name in flipflops: 31 | send = flipflops[name] 32 | elif name in conjunctions: 33 | send = not all(conjunctions[name].values()) 34 | 35 | if name == rx_parent: 36 | for j, is_good in enumerate(conjunctions[rx_parent].values()): 37 | if is_good: 38 | rx_repeats[j] = i 39 | 40 | for dest in modules.get(name, []): 41 | counts[send] += 1 42 | if dest in flipflops: 43 | if not send: 44 | flipflops[dest] = not flipflops[dest] 45 | q.append(dest) 46 | elif dest in conjunctions: 47 | conjunctions[dest][name] = send 48 | q.append(dest) 49 | 50 | for i in range(1, 100000): 51 | q.append("broadcaster") 52 | counts[0] += 1 53 | while q: 54 | push(q.popleft(), i) 55 | 56 | if i == 1000: 57 | print(counts[0] * counts[1]) 58 | 59 | if all(rx_repeats): 60 | print(math.prod(rx_repeats)) 61 | break 62 | -------------------------------------------------------------------------------- /2023/21/21.py: -------------------------------------------------------------------------------- 1 | from collections import deque 2 | 3 | lines = open(0).read().splitlines() 4 | Y, X = len(lines), len(lines[0]) 5 | dirs = [(0, 1), (1, 0), (0, -1), (-1, 0)] 6 | 7 | q = deque() 8 | dists = {} 9 | 10 | for y, line in enumerate(lines): 11 | if 'S' in line: 12 | q.append((y, line.index('S'))) 13 | 14 | while q: 15 | y, x = q.popleft() 16 | for dy, dx in dirs: 17 | ya, xa = y + dy, x + dx 18 | if 0 <= ya < Y and 0 <= xa < X and lines[ya][xa] != '#' and (ya, xa) not in dists: 19 | dists[(ya, xa)] = dists.get((y, x), 0)+1 20 | q.append((ya, xa)) 21 | 22 | n = 26501365 // X 23 | 24 | even_full = sum(d % 2 == 0 for d in dists.values()) 25 | odd_full = sum(d % 2 == 1 for d in dists.values()) 26 | even_edges = sum(d % 2 == 0 and d > 65 for d in dists.values()) 27 | odd_edges = sum(d % 2 == 1 and d > 65 for d in dists.values()) 28 | 29 | print(even_full - even_edges) 30 | 31 | p2 = (n+1)**2 * odd_full + n**2 * even_full - (n+1) * odd_edges + n * even_edges 32 | print(p2) 33 | -------------------------------------------------------------------------------- /2023/23/23.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.setrecursionlimit(1000000000) 3 | from collections import deque 4 | 5 | lines = open(0).read().splitlines() 6 | Y, X = len(lines), len(lines[0]) 7 | dirs = [(0, 1), (1, 0), (0, -1), (-1, 0)] 8 | 9 | max_dist = 0 10 | def dfs(y, x, dist, visited, part2=False): 11 | global max_dist 12 | if (y, x) == (Y-1, X-2): 13 | if dist > max_dist: 14 | # Prints all current largest paths. After a couple minutes it finds the correct answer 15 | # However it does not finish within half an hour. 16 | print(dist) 17 | max_dist = dist 18 | 19 | adj = [] 20 | for i, (dy, dx) in enumerate(dirs): 21 | ya, xa = y+dy, x+dx 22 | if 0 <= ya < Y and 0 <= xa < X and lines[ya][xa] != '#' and (ya, xa) not in visited: 23 | adj.append((ya, xa)) 24 | if not part2 and lines[ya][xa] in '>v<^' and '>v<^'.index(lines[ya][xa]) == i: 25 | continue 26 | if len(adj) == 1: 27 | visited.add(adj[0]) 28 | dfs(adj[0][0], adj[0][1], dist+1, visited) 29 | elif len(adj) > 1: 30 | for a in adj: 31 | dfs(a[0], a[1], dist+1, visited | {a}) 32 | 33 | dfs(0, 1, 0, {(0, 1)}) 34 | dfs(0, 1, 0, {(0, 1)}, part2=True) 35 | -------------------------------------------------------------------------------- /2023/24/24.py: -------------------------------------------------------------------------------- 1 | 2 | import z3 3 | 4 | lines = open(0).read().splitlines() 5 | 6 | sx, sy, sz = z3.Real('x'), z3.Real('y'), z3.Real('z') 7 | sdx, sdy, sdz = z3.Real('dx'), z3.Real('dy'), z3.Real('dz') 8 | solver = z3.Solver() 9 | 10 | coords = [] 11 | for i, line in enumerate(lines): 12 | x, y, z, dx, dy, dz = map(int, line.replace("@", ",").split(",")) 13 | coords.append((x, y, z, dx, dy, dz)) 14 | if i < 3: 15 | t = z3.Real(f't{i}') 16 | solver.add(sx + sdx * t == x + dx * t) 17 | solver.add(sy + sdy * t == y + dy * t) 18 | solver.add(sz + sdz * t == z + dz * t) 19 | 20 | 21 | s1 = 0 22 | for i, (x1, y1, z1, dx1, dy1, dz1) in enumerate(coords): 23 | for x2, y2, z2, dx2, dy2, dz2 in coords[i+1:]: 24 | slope1 = dy1 / dx1 25 | slope2 = dy2 / dx2 26 | b1 = y1 - slope1 * x1 27 | b2 = y2 - slope2 * x2 28 | if slope1 != slope2: 29 | ix = (b2 - b1) / (slope1 - slope2) 30 | iy = slope1 * ix + b1 31 | 32 | if 2e14 <= ix <= 4e14 and 2e14 <= iy <= 4e14: 33 | if (x1 - ix) * dx1 < 0 and (x2 - ix) * dx2 < 0: 34 | if (y1 - iy) * dy1 < 0 and (y2 - iy) * dy2 < 0: 35 | s1 += 1 36 | 37 | print(s1) 38 | assert solver.check() == z3.sat 39 | model = solver.model() 40 | get = lambda var: model.eval(var).as_long() 41 | print(get(sx) + get(sy) + get(sz)) 42 | -------------------------------------------------------------------------------- /2023/25/25.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | import random 3 | import networkx as nx 4 | 5 | g = nx.Graph() 6 | for line in open(0): 7 | at, tos = line.split(":") 8 | for to in tos.strip().split(' '): 9 | g.add_edge(at, to, capacity=1) 10 | 11 | while True: 12 | start = random.choice(list(g.nodes)) 13 | end = random.choice(list(g.nodes)) 14 | cut, part = nx.minimum_cut(g, start, end) 15 | if cut == 3: 16 | print(len(part[0])*len(part[1])) 17 | break 18 | -------------------------------------------------------------------------------- /2023/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "aoc2023" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | regex = "1.10.2" 10 | itertools = "0.9.0" 11 | 12 | [[bin]] 13 | name = "01" 14 | path = "01/01.rs" 15 | 16 | [[bin]] 17 | name = "02" 18 | path = "02/02.rs" 19 | 20 | [[bin]] 21 | name = "03" 22 | path = "03/03.rs" 23 | 24 | [[bin]] 25 | name = "04" 26 | path = "04/04.rs" 27 | 28 | [[bin]] 29 | name = "05" 30 | path = "05/05.rs" 31 | 32 | [[bin]] 33 | name = "06" 34 | path = "06/06.rs" 35 | 36 | [[bin]] 37 | name = "07" 38 | path = "07/07.rs" 39 | 40 | [[bin]] 41 | name = "08" 42 | path = "08/08.rs" 43 | 44 | [[bin]] 45 | name = "09" 46 | path = "09/09.rs" 47 | 48 | [[bin]] 49 | name = "10" 50 | path = "10/10.rs" 51 | 52 | [[bin]] 53 | name = "11" 54 | path = "11/11.rs" 55 | 56 | [[bin]] 57 | name = "12" 58 | path = "12/12.rs" 59 | 60 | [[bin]] 61 | name = "13" 62 | path = "13/13.rs" 63 | 64 | [[bin]] 65 | name = "14" 66 | path = "14/14.rs" 67 | 68 | [[bin]] 69 | name = "15" 70 | path = "15/15.rs" 71 | 72 | [[bin]] 73 | name = "16" 74 | path = "16/16.rs" 75 | 76 | [[bin]] 77 | name = "17" 78 | path = "17/17.rs" 79 | 80 | [[bin]] 81 | name = "18" 82 | path = "18/18.rs" 83 | 84 | [[bin]] 85 | name = "19" 86 | path = "19/19.rs" 87 | 88 | [[bin]] 89 | name = "20" 90 | path = "20/20.rs" 91 | 92 | [[bin]] 93 | name = "21" 94 | path = "21/21.rs" 95 | 96 | [[bin]] 97 | name = "22" 98 | path = "22/22.rs" 99 | 100 | [[bin]] 101 | name = "23" 102 | path = "23/23.rs" 103 | 104 | [[bin]] 105 | name = "24" 106 | path = "24/24.rs" 107 | 108 | [[bin]] 109 | name = "25" 110 | path = "25/25.rs" 111 | -------------------------------------------------------------------------------- /2024/01/01.py: -------------------------------------------------------------------------------- 1 | n = [int(a) for a in open(0).read().split()] 2 | 3 | s1 = s2 = 0 4 | for a, b in zip(sorted(n[::2]), sorted(n[1::2])): 5 | s1 += abs(a - b) 6 | s2 += a * n[1::2].count(a) 7 | print(s1, s2, sep="\n") 8 | -------------------------------------------------------------------------------- /2024/02/02.py: -------------------------------------------------------------------------------- 1 | is_safe = lambda n: sorted(n) in (n, n[::-1]) and all(1 <= abs(a - b) <= 3 for a, b in zip(n, n[1:])) 2 | 3 | s1 = s2 = 0 4 | for line in open(0): 5 | n = [int(a) for a in line.split()] 6 | s1 += is_safe(n) 7 | s2 += any(is_safe(n[:i] + n[i+1:]) for i in range(len(n))) 8 | print(s1, s2, sep="\n") 9 | 10 | -------------------------------------------------------------------------------- /2024/03/03.py: -------------------------------------------------------------------------------- 1 | import re 2 | s1, s2, enabled = 0, 0, True 3 | 4 | for a, b, dont in re.findall(r"mul\((\d+),(\d+)\)|do(n't)?", open(0).read()): 5 | if a or b: 6 | s1 += int(a) * int(b) 7 | s2 += int(a) * int(b) * enabled 8 | else: 9 | enabled = dont == '' 10 | print(s1, s2, sep="\n") 11 | -------------------------------------------------------------------------------- /2024/04/04.py: -------------------------------------------------------------------------------- 1 | coords = {x+1j*y: c for y, r in enumerate(open(0)) for x, c in enumerate(r)} 2 | g = lambda c: coords.get(c, "") 3 | 4 | s1 = s2 = 0 5 | for c in coords: 6 | for d in [1, 1j, 1+1j, 1-1j, -1, -1j, -1+1j, -1-1j]: 7 | s1 += g(c) + g(c+d) + g(c+d*2) + g(c+d*3) == "XMAS" 8 | if d.imag and d.real: 9 | s2 += g(c+d) + g(c) + g(c-d) == "MAS" and g(c+d*1j) + g(c-d*1j) == "MS" 10 | 11 | print(s1, s2, sep="\n") 12 | -------------------------------------------------------------------------------- /2024/05/05.py: -------------------------------------------------------------------------------- 1 | rules, pages = open(0).read().split("\n\n") 2 | rules = {tuple(r.split("|")) for r in rules.splitlines()} 3 | 4 | s = [0, 0] 5 | for row in pages.splitlines(): 6 | old, new = row.split(","), [] 7 | for o in old * 100: 8 | if o in new: continue 9 | if all(b in new for b, a in rules if o == a and b in old): 10 | new.append(o) 11 | s[new != old] += int(new[len(new)//2]) 12 | 13 | print(*s, sep="\n") 14 | -------------------------------------------------------------------------------- /2024/06/06.py: -------------------------------------------------------------------------------- 1 | coords = {x+1j*y: c for y, r in enumerate(open(0)) for x, c in enumerate(r) if c != '\n'} 2 | 3 | for pos, c in coords.items(): 4 | if c == "^": 5 | start = pos 6 | 7 | def solve(obstruction, pos=start, d=-1j): 8 | seen = set() 9 | while pos in coords: 10 | seen.add((pos, d)) 11 | while coords.get(pos + d, "#") != '#' and pos + d != obstruction: 12 | pos += d 13 | seen.add((pos, d)) 14 | if pos + d not in coords: 15 | return {p for p, _ in seen} 16 | d *= 1j 17 | if (pos, d) in seen: 18 | return True 19 | 20 | seen = solve(-1) 21 | print(len(seen), sum(solve(coord) is True for coord in seen)) 22 | -------------------------------------------------------------------------------- /2024/07/07.py: -------------------------------------------------------------------------------- 1 | from operator import * 2 | 3 | def concat(a, b): 4 | return int(str(a) + str(b)) 5 | 6 | s1 = s2 = 0 7 | for line in open(0): 8 | first, rest = line.split(": ") 9 | n = [int(a) for a in rest.split()] 10 | first = int(first) 11 | repeat = len(n) - 1 12 | for mask in range(3**repeat): 13 | s = n[0] 14 | for_part1 = True 15 | for i in range(repeat): 16 | mask, index = divmod(mask, 3) 17 | for_part1 &= index != 2 18 | op = [add, mul, concat][index] 19 | s = op(s, n[i+1]) 20 | if s > first: 21 | break 22 | if s == first: 23 | s1 += first * for_part1 24 | s2 += first 25 | break 26 | 27 | print(s1, s2, sep="\n") 28 | -------------------------------------------------------------------------------- /2024/08/08.py: -------------------------------------------------------------------------------- 1 | from itertools import * 2 | 3 | coords = {x+1j*y: c for y, r in enumerate(open(0)) for x, c in enumerate(r.strip())} 4 | 5 | by = lambda v: v[1] 6 | order = groupby(sorted(coords.items(), key=by), by) 7 | 8 | p1, p2 = set(), set() 9 | 10 | for char, coord in order: 11 | if char == '.': continue 12 | for (a, _), (b, _) in combinations(coord, r=2): 13 | diff = a - b 14 | p1 |= {a + diff*i for i in (-2, 1)} 15 | p2 |= {a + diff*i for i in range(-100, 100)} 16 | 17 | print(len(p1 & coords.keys())) 18 | print(len(p2 & coords.keys())) 19 | -------------------------------------------------------------------------------- /2024/09/09.py: -------------------------------------------------------------------------------- 1 | def solve1(files, s=0, index=-1, f=-1): 2 | while f+1 < len(files): 3 | file = files[f := f + 1] 4 | is_file = f%2 == 0 5 | for _ in range(file): 6 | i = f//2 if is_file else len(files) // 2 7 | s += i * (index := index + 1) 8 | if not is_file: 9 | files[-1] -= 1 10 | while files[-1] == 0 or len(files) % 2 == 0 and len(files)-1 != f: 11 | files.pop() 12 | if len(files)-1 == f: 13 | break 14 | return s 15 | 16 | def solve2(files, free_spaces, s=0, index=-1): 17 | spaces = [[] for j in free_spaces] 18 | files = list(enumerate(files)) 19 | 20 | for i, file in reversed(files): 21 | for j, empty in enumerate(free_spaces): 22 | if i <= j: 23 | break 24 | if empty >= file: 25 | spaces[j].append((i, file)) 26 | files[i] = (0, file) 27 | free_spaces[j] -= file 28 | break 29 | 30 | for file, space, empty in zip(files, spaces, free_spaces): 31 | for i, count in [file] + space + [(0, empty)]: 32 | while count: 33 | s += i * (index := index + 1) 34 | count -= 1 35 | return s 36 | 37 | filesystem = [int(a) for a in input()] 38 | print(solve1(filesystem[:])) 39 | print(solve2(filesystem[::2], filesystem[1::2])) 40 | -------------------------------------------------------------------------------- /2024/10/10.py: -------------------------------------------------------------------------------- 1 | coords = {x+1j*y: int(h) for y, r in enumerate(open(0)) for x, h in enumerate(r.strip())} 2 | 3 | def hike(c, peaks, paths=0): 4 | if coords[c] == 9: 5 | peaks.add(c) 6 | return 1 7 | for d in [1, 1j, -1, -1j]: 8 | if coords.get(c+d) == coords[c] + 1: 9 | paths += hike(c+d, peaks) 10 | return paths 11 | 12 | p1, s2 = {c: set() for c in coords}, 0 13 | for c in coords: 14 | if coords[c] == 0: 15 | s2 += hike(c, p1[c]) 16 | 17 | print(sum(map(len, p1.values()))) 18 | print(s2) 19 | -------------------------------------------------------------------------------- /2024/11/11.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | counts = Counter([int(a) for a in input().split()]) 4 | 5 | for i in range(75): 6 | for n, occ in list(counts.items()): 7 | if (l := len(str(n))) % 2 == 0: 8 | counts[n // 10**(l//2)] += occ 9 | counts[n % 10**(l//2)] += occ 10 | else: 11 | counts[n * 2024 or 1] += occ 12 | counts[n] -= occ 13 | if i in (24, 74): 14 | print(sum(counts.values())) 15 | -------------------------------------------------------------------------------- /2024/12/12.py: -------------------------------------------------------------------------------- 1 | coords = {x+1j*y: c for y, r in enumerate(open(0)) for x, c in enumerate(r.strip())} 2 | dir_corners = [.5+.5j, .5-.5j, -.5+.5j, -.5-.5j] 3 | visited = set() 4 | 5 | def adjacent(coord, dirs=[1, 1j, -1, -1j]): 6 | return [coord + d for d in dirs] 7 | 8 | def fill_region(c): 9 | visited.add(c) 10 | region = [c] 11 | for adj in adjacent(c): 12 | if coords.get(adj) == coords[c] and adj not in visited: 13 | region += fill_region(adj) 14 | return region 15 | 16 | s1 = s2 = 0 17 | for c, char in coords.items(): 18 | if c in visited: continue 19 | 20 | perimeter, corners = 0, set() 21 | 22 | for r in (region := fill_region(c)): 23 | perimeter += sum(adj not in region for adj in adjacent(r)) 24 | 25 | for corner in adjacent(r, dir_corners): 26 | k = [adj for adj in adjacent(corner, dir_corners) if adj in region] 27 | if len(k) in [1, 3]: 28 | corners.add(corner) 29 | elif abs(k[0] - k[1]) != 1: 30 | corners |= {corner, corner+0.1} 31 | 32 | s1 += perimeter * len(region) 33 | s2 += len(corners) * len(region) 34 | 35 | print(s1, s2, sep="\n") 36 | -------------------------------------------------------------------------------- /2024/13/13.py: -------------------------------------------------------------------------------- 1 | import re 2 | import z3 3 | 4 | s = [0, 0] 5 | for machine in open(0).read().split("\n\n"): 6 | (ax,ay), (bx,by), (px,py) = [map(int, x) for x in re.findall(r"(\d+).*?(\d+)", machine)] 7 | 8 | for i, add in enumerate([0, 10000000000000]): 9 | a, b = z3.Int('a'), z3.Int('b') 10 | 11 | solver = z3.Optimize() 12 | solver.add(px + add == a * ax + b * bx) 13 | solver.add(py + add == a * ay + b * by) 14 | solver.minimize(a * 3 + b) 15 | 16 | if solver.check() == z3.sat: 17 | model = solver.model() 18 | s[i] += model.eval(a).as_long() * 3 + model.eval(b).as_long() 19 | print(*s, sep="\n") 20 | -------------------------------------------------------------------------------- /2024/14/14.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | X, Y = 101, 103 4 | nums = [list(map(int, re.findall(r"-?\d+", line))) for line in open(0)] 5 | 6 | for i in range(X * Y): 7 | quadrant = [0, 0, 0, 0] 8 | picture = [" "] * (X * Y) 9 | for x, y, vx, vy in nums: 10 | nx = (x + vx * i) % X 11 | ny = (y + vy * i) % Y 12 | picture[ny * X + nx] = "#" 13 | if nx != X//2 and ny != Y//2: 14 | quadrant[(nx > X//2) + (ny > Y//2) * 2] += 1 15 | 16 | if i == 100: 17 | print(quadrant[0] * quadrant[1] * quadrant[2] * quadrant[3]) 18 | 19 | if ("#" * 20) in ''.join(picture): 20 | print(i) 21 | break 22 | -------------------------------------------------------------------------------- /2024/15/15.py: -------------------------------------------------------------------------------- 1 | def solve(field): 2 | coords = {x+1j*y: c for y, r in enumerate(field.split("\n")) for x, c in enumerate(r)} 3 | 4 | pos = [c for c in coords if coords[c] == "@"][0] 5 | coords[pos] = "." 6 | 7 | def find_boxes(c): 8 | if coords[c] not in "]O[": 9 | return {} 10 | c_adj = c + ("]O[".index(coords[c]) - 1 if dir.imag else 0) 11 | return {c: coords[c], c_adj: coords[c_adj]} \ 12 | | find_boxes(c+dir) \ 13 | | find_boxes(c_adj+dir) 14 | 15 | for move in moves.replace("\n", ""): 16 | dir = {'>': 1, 'v': 1j, '<': -1, '^': -1j}[move] 17 | if coords[pos+dir] == '#': continue 18 | 19 | boxes = find_boxes(pos+dir) 20 | if all(coords[box+dir] != "#" for box in boxes): 21 | coords |= {box: '.' for box in boxes} 22 | coords |= {box+dir: boxes[box] for box in boxes} 23 | pos += dir 24 | 25 | print(int(sum(c.imag*100 + c.real for c in coords if coords[c] in '[O'))) 26 | 27 | field, moves = open(0).read().split("\n\n") 28 | 29 | solve(field) 30 | for r1, r2 in [("#", "##"), ("O", "[]"), (".", ".."), ("@", "@.")]: 31 | field = field.replace(r1, r2) 32 | solve(field) 33 | -------------------------------------------------------------------------------- /2024/16/16.py: -------------------------------------------------------------------------------- 1 | import networkx as nx 2 | coords = {x+1j*y: c for y, r in enumerate(open(0)) for x, c in enumerate(r.strip())} 3 | 4 | G = nx.DiGraph() 5 | for c in coords: 6 | for d in [1, 1j, -1, -1j]: 7 | G.add_edge((c, d), (c, 0), weight=0) 8 | G.add_edge((c, 0), (c, d), weight=1000) 9 | if coords[c] != '#' != coords[c+d]: 10 | G.add_edge((c, d), (c+d, d), weight=1) 11 | 12 | E, S = [c for c in coords if coords[c] in 'SE'] 13 | 14 | paths = list(nx.all_shortest_paths(G, (S, 1), (E, 0), "weight")) 15 | 16 | print(sum(G.edges[e]["weight"] for e in zip(paths[0], paths[0][1:]))) 17 | print(len({p[0] for p in sum(paths, [])})) 18 | -------------------------------------------------------------------------------- /2024/17/17.py: -------------------------------------------------------------------------------- 1 | import re 2 | a, b, c, *nums = map(int, re.findall(r"\d+", open(0).read())) 3 | 4 | def compute(A=a, B=b, C=c, pointer=0): 5 | out = [] 6 | while pointer < len(nums): 7 | num = nums[pointer+1] 8 | combo = {4:A, 5:B, 6:C}.get(num, num) 9 | match nums[pointer]: 10 | case 0: A = A // 2**combo 11 | case 1: B ^= num 12 | case 2: B = combo % 8 13 | case 3 if A != 0: pointer = num - 2 14 | case 4: B ^= C 15 | case 5: out.append(combo % 8) 16 | case 6: B = A // 2**combo 17 | case 7: C = A // 2**combo 18 | pointer += 2 19 | return out 20 | 21 | print(*compute(), sep=",") 22 | 23 | def find_A(A, at=15): 24 | if at == -1: 25 | print(A) 26 | exit(0) 27 | while True: 28 | if nums[at:] == compute(A)[at:]: 29 | find_A(A, at-1) 30 | A += 8**at 31 | find_A(8**15) 32 | -------------------------------------------------------------------------------- /2024/18/18.py: -------------------------------------------------------------------------------- 1 | import networkx as nx 2 | from bisect import bisect 3 | 4 | def solve(bad, S=70): 5 | G = nx.grid_graph((S+1, S+1)) 6 | G.remove_nodes_from(bad) 7 | return nx.has_path(G, (0,0), (S,S)) \ 8 | and nx.shortest_path_length(G, (0,0), (S,S)) 9 | 10 | bad = [tuple(map(int, line.split(","))) for line in open(0)] 11 | print(solve(bad[:1024])) 12 | 13 | i = bisect(range(len(bad)), 0, key=lambda x: not solve(bad[:x])) 14 | print(*bad[i-1], sep=",") 15 | -------------------------------------------------------------------------------- /2024/19/19.py: -------------------------------------------------------------------------------- 1 | patterns, designs = open(0).read().split("\n\n") 2 | patterns = patterns.split(", ") 3 | 4 | def arrangements(design): 5 | dp = [1] + [0] * len(design) 6 | for i in range(len(design)): 7 | for pattern in patterns: 8 | if design[i:].startswith(pattern): 9 | dp[i+len(pattern)] += dp[i] 10 | return dp[-1] 11 | 12 | p = [arrangements(d) for d in designs.split()] 13 | print(sum(map(bool, p))) 14 | print(sum(p)) 15 | -------------------------------------------------------------------------------- /2024/20/20.py: -------------------------------------------------------------------------------- 1 | import networkx as nx 2 | 3 | coords = {x+1j*y: c for y, r in enumerate(open(0)) for x, c in enumerate(r.strip())} 4 | 5 | G = nx.Graph() 6 | for c in coords: 7 | for d in [1, 1j, -1, -1j]: 8 | if coords[c] != '#' != coords[c+d]: 9 | G.add_edge(c, c+d) 10 | 11 | S = [c for c in coords if coords[c] in 'S'][0] 12 | coord_to_dist = nx.shortest_path_length(G, S).items() 13 | 14 | s1 = s2 = 0 15 | for c1, dist1 in coord_to_dist: 16 | for c2, dist2 in coord_to_dist: 17 | diff = int(abs((c2-c1).real) + abs((c2-c1).imag)) 18 | if dist2 - dist1 - diff >= 100: 19 | s1 += diff <= 2 20 | s2 += diff <= 20 21 | 22 | print(s1, s2, sep="\n") # use pypy instead of python 23 | -------------------------------------------------------------------------------- /2024/21/21.py: -------------------------------------------------------------------------------- 1 | from functools import cache 2 | 3 | N = {'7':0, '8':1, '9':2, '4':1j, '5':1+1j, '6':2+1j, 4 | '1':2j, '2':1+2j, '3':2+2j, ' ':3j, '0':1+3j, 'A':2+3j} 5 | R = {' ':0, '^':1, 'A':2, '<':1j, 'v':1+1j, '>':2+1j} 6 | 7 | @cache 8 | def path(start, end): 9 | pad = N if (start in N and end in N) else R 10 | diff = pad[end] - pad[start] 11 | dx, dy = int(diff.real), int(diff.imag) 12 | yy = ("^"*-dy) + ("v"*dy) 13 | xx = ("<"*-dx) + (">"*dx) 14 | 15 | bad = pad[" "] - pad[start] 16 | prefer_yy_first = (dx>0 or bad==dx) and bad!=dy*1j 17 | return (yy+xx if prefer_yy_first else xx+yy) + "A" 18 | 19 | @cache 20 | def length(code, depth, s=0): 21 | if depth == 0: return len(code) 22 | for i, c in enumerate(code): 23 | s += length(path(code[i-1], c), depth-1) 24 | return s 25 | 26 | codes = open(0).read().split() 27 | print(sum(int(code[:-1]) * length(code, 3) for code in codes)) 28 | print(sum(int(code[:-1]) * length(code, 26) for code in codes)) 29 | -------------------------------------------------------------------------------- /2024/22/22.py: -------------------------------------------------------------------------------- 1 | s1, s2 = 0, {} 2 | for num in map(int, open(0)): 3 | seen = set() 4 | last4 = (10, 10, 10, 10) 5 | for _ in range(2000): 6 | prev = num%10 7 | num ^= num*64 % 16777216 8 | num ^= num//32 9 | num ^= num*2048 % 16777216 10 | last4 = last4[1:] + (num%10 - prev,) 11 | if last4 not in seen: 12 | seen.add(last4) 13 | s2[last4] = s2.get(last4, 0) + num%10 14 | s1 += num 15 | 16 | print(s1) 17 | print(max(s2.values())) 18 | -------------------------------------------------------------------------------- /2024/23/23.py: -------------------------------------------------------------------------------- 1 | import networkx as nx 2 | 3 | G = nx.Graph(line.strip().split("-") for line in open(0)) 4 | cliques = list(nx.enumerate_all_cliques(G)) 5 | 6 | print(sum(any(a[0]=='t' for a in c) for c in cliques if len(c) == 3)) 7 | print(','.join(sorted(cliques[-1]))) 8 | -------------------------------------------------------------------------------- /2024/25/25.py: -------------------------------------------------------------------------------- 1 | occ = {".": [], "#": []} 2 | 3 | for schematic in open(0).read().split("\n\n"): 4 | counts = tuple(c.count("#") for c in zip(*schematic.split())) 5 | occ[schematic[0]].append(counts) 6 | 7 | print(sum(all(k+l<=7 for k,l in zip(key,lock)) 8 | for key in occ['.'] 9 | for lock in occ["#"])) 10 | -------------------------------------------------------------------------------- /AoCTiles/README.md: -------------------------------------------------------------------------------- 1 | # AoC Tiles 2 | 3 | This script has moved to [LiquidFun/aoc_tiles](https://github.com/LiquidFun/aoc_tiles). It has been improved and can now easily be run as a pre-commit hook. See the link for more details. 4 | -------------------------------------------------------------------------------- /Media/2020/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2020/01.png -------------------------------------------------------------------------------- /Media/2020/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2020/02.png -------------------------------------------------------------------------------- /Media/2020/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2020/03.png -------------------------------------------------------------------------------- /Media/2020/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2020/04.png -------------------------------------------------------------------------------- /Media/2020/05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2020/05.png -------------------------------------------------------------------------------- /Media/2020/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2020/06.png -------------------------------------------------------------------------------- /Media/2020/07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2020/07.png -------------------------------------------------------------------------------- /Media/2020/08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2020/08.png -------------------------------------------------------------------------------- /Media/2021/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/01.png -------------------------------------------------------------------------------- /Media/2021/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/02.png -------------------------------------------------------------------------------- /Media/2021/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/03.png -------------------------------------------------------------------------------- /Media/2021/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/04.png -------------------------------------------------------------------------------- /Media/2021/05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/05.png -------------------------------------------------------------------------------- /Media/2021/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/06.png -------------------------------------------------------------------------------- /Media/2021/07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/07.png -------------------------------------------------------------------------------- /Media/2021/08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/08.png -------------------------------------------------------------------------------- /Media/2021/09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/09.png -------------------------------------------------------------------------------- /Media/2021/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/10.png -------------------------------------------------------------------------------- /Media/2021/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/11.png -------------------------------------------------------------------------------- /Media/2021/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/12.png -------------------------------------------------------------------------------- /Media/2021/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/13.png -------------------------------------------------------------------------------- /Media/2021/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/14.png -------------------------------------------------------------------------------- /Media/2021/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/15.png -------------------------------------------------------------------------------- /Media/2021/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/16.png -------------------------------------------------------------------------------- /Media/2021/17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/17.png -------------------------------------------------------------------------------- /Media/2021/18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/18.png -------------------------------------------------------------------------------- /Media/2021/19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/19.png -------------------------------------------------------------------------------- /Media/2021/20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/20.png -------------------------------------------------------------------------------- /Media/2021/21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/21.png -------------------------------------------------------------------------------- /Media/2021/22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/22.png -------------------------------------------------------------------------------- /Media/2021/23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/23.png -------------------------------------------------------------------------------- /Media/2021/24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/24.png -------------------------------------------------------------------------------- /Media/2021/25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021/25.png -------------------------------------------------------------------------------- /Media/2021loc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2021loc.png -------------------------------------------------------------------------------- /Media/2022/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/01.png -------------------------------------------------------------------------------- /Media/2022/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/02.png -------------------------------------------------------------------------------- /Media/2022/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/03.png -------------------------------------------------------------------------------- /Media/2022/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/04.png -------------------------------------------------------------------------------- /Media/2022/05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/05.png -------------------------------------------------------------------------------- /Media/2022/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/06.png -------------------------------------------------------------------------------- /Media/2022/07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/07.png -------------------------------------------------------------------------------- /Media/2022/08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/08.png -------------------------------------------------------------------------------- /Media/2022/09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/09.png -------------------------------------------------------------------------------- /Media/2022/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/10.png -------------------------------------------------------------------------------- /Media/2022/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/11.png -------------------------------------------------------------------------------- /Media/2022/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/12.png -------------------------------------------------------------------------------- /Media/2022/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/13.png -------------------------------------------------------------------------------- /Media/2022/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/14.png -------------------------------------------------------------------------------- /Media/2022/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/15.png -------------------------------------------------------------------------------- /Media/2022/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/16.png -------------------------------------------------------------------------------- /Media/2022/17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/17.png -------------------------------------------------------------------------------- /Media/2022/18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/18.png -------------------------------------------------------------------------------- /Media/2022/19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/19.png -------------------------------------------------------------------------------- /Media/2022/20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/20.png -------------------------------------------------------------------------------- /Media/2022/21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/21.png -------------------------------------------------------------------------------- /Media/2022/22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/22.png -------------------------------------------------------------------------------- /Media/2022/23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/23.png -------------------------------------------------------------------------------- /Media/2022/24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/24.png -------------------------------------------------------------------------------- /Media/2022/25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2022/25.png -------------------------------------------------------------------------------- /Media/2023/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFun/adventofcode/16f97a337386efb1219b9ed52fb2bffbc8c0bb2c/Media/2023/01.png -------------------------------------------------------------------------------- /init-day.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | year="2024" 4 | SCRIPT_DIR="$(dirname "$(realpath "$0")")" 5 | cookie="$(cat $SCRIPT_DIR/.aoc_tiles/session.cookie)" 6 | input_prefix="input" 7 | sample_prefix="example" 8 | 9 | # Example comes before input alphabetically, so it shows up in front in the program-tester.sh 10 | 11 | if [[ "$1" ]]; then 12 | dir=$(printf "%02d" "$1") 13 | path="$SCRIPT_DIR/$year/$dir" 14 | if ! [[ -d "$path" ]]; then 15 | echo "Creating folder for problem $dir in $path" 16 | mkdir "$path" 17 | fi 18 | cd "$path" 19 | 20 | # Download input from advent of code 21 | input_file="$path/${input_prefix}.in" 22 | echo $input_file 23 | if ! [[ -f "$input_file" ]]; then 24 | echo "Downloading input for problem $dir" 25 | # Don't DDOS! So check if file exists already 26 | nozero=$(echo "$1" | awk '$0*=1') 27 | curl "https://adventofcode.com/$year/day/$nozero/input" --cookie "session=$cookie" > "$input_file" 28 | else 29 | echo "Skipping $dir because input file exists $input_file" 30 | fi 31 | 32 | # Add empty file so there are not that many lines when showing input instead 33 | # input_ans_file="${input_prefix}.ans" 34 | # if ! [[ -f "$input_ans_file" ]]; then 35 | # echo "Create empty input answer file" 36 | # touch "$input_ans_file" 37 | # fi 38 | 39 | # Prepare dummy python solution 40 | # solution_file="$1.py" 41 | # if ! [[ -f "$solution_file" ]]; then 42 | # echo "Create dummy python solution $solution_file" 43 | # cp "../../dummy.py" "$solution_file" 44 | # fi 45 | 46 | 47 | # nvim "$solution_file" "${sample_prefix}.in" "${sample_prefix}.ans" -c "norm G$" 48 | else 49 | echo "Supply some number as first argument to initialize a problem!" 50 | fi 51 | --------------------------------------------------------------------------------