├── 2015 ├── 04.js ├── 25.js └── 10.js ├── 2016 ├── .vscode │ ├── settings.json │ ├── tasks.json │ └── launch.json ├── src │ ├── 15-input.ts │ ├── 12-input.ts │ ├── 25-input.ts │ ├── 23-input.ts │ ├── 20.ts │ ├── 01-input.ts │ ├── 15.ts │ ├── 18.ts │ └── run.ts ├── tsconfig.json ├── tslint.json ├── package.json └── gulpfile.js ├── 2017 ├── src │ ├── 14-input.ts │ ├── 06-input.ts │ ├── 10-input.ts │ ├── 19-input.01.txt │ ├── 19-input.ts │ ├── 23-input.ts │ ├── 13-input.ts │ ├── 24-input.ts │ ├── 18-input.ts │ ├── 22-input.ts │ ├── 04.ts │ ├── 05.ts │ ├── 15.ts │ ├── 09.ts │ ├── 02.ts │ ├── 13.ts │ ├── 17.ts │ ├── 12.ts │ ├── 11.02.ts │ ├── run.ts │ ├── 02-input.ts │ ├── 25.ts │ └── 01.ts ├── .vscode │ ├── settings.json │ └── tasks.json ├── tslint.json ├── tsconfig.json ├── package.json └── webpack.config.js ├── 2018 ├── inputs │ ├── 20-test1.txt │ ├── 20-test2.txt │ ├── 08-test.txt │ ├── 20-test3.txt │ ├── 06-test.txt │ ├── 20-test4.txt │ ├── 15-test8.txt │ ├── 20-test5.txt │ ├── 13-test2.txt │ ├── 15-test1.txt │ ├── 15-test2.txt │ ├── 15-test3.txt │ ├── 15-test4.txt │ ├── 15-test5.txt │ ├── 25-test1.txt │ ├── 13-test1.txt │ ├── 19-test1.txt │ ├── 15-test0.txt │ ├── 15-test6.txt │ ├── 25-test2.txt │ ├── 25-test3.txt │ ├── 23-test2.txt │ ├── 25-test4.txt │ ├── 17-test1.txt │ ├── 18-test1.txt │ ├── 23-test1.txt │ ├── 12-test.txt │ ├── 07-test.txt │ ├── 21.txt │ ├── 19.txt │ ├── 24-test1.txt │ ├── 12.txt │ ├── 04-test.txt │ ├── 06.txt │ ├── 15.txt │ ├── 15-test7.txt │ ├── 15-test9.txt │ └── 10-test.txt ├── ts │ ├── .gitignore │ ├── jest.config.js │ ├── tslint.json │ ├── package.json │ ├── .vscode │ │ └── launch.json │ ├── D08.test.ts │ ├── tsconfig.json │ ├── D05.test.ts │ └── D01.test.ts ├── elixir │ ├── 13.exs │ ├── 15.exs │ ├── 16.exs │ ├── 17.exs │ ├── 18.exs │ ├── 19.exs │ ├── 20.exs │ ├── 21.exs │ ├── 22.exs │ ├── 23.exs │ ├── 24.exs │ ├── 11.exs │ ├── 10.exs │ ├── 09.exs │ ├── 05.exs │ ├── 08.exs │ ├── 01.exs │ ├── 14.exs │ └── 03.exs └── go │ ├── Readme.md │ └── 05_test.go ├── 2019 ├── ts │ ├── .gitignore │ ├── prettier.config.js │ ├── jest.config.js │ ├── .eslintrc.js │ ├── D09.test.ts │ ├── D01.test.ts │ ├── package.json │ ├── D08.test.ts │ ├── D02.test.ts │ ├── D13.test.ts │ └── D04.test.ts ├── inputs │ ├── 06d.txt │ ├── 03a.txt │ ├── 18a.txt │ ├── 06c.txt │ ├── 24.txt │ ├── 07a.txt │ ├── 10a.txt │ ├── 24a.txt │ ├── 03b.txt │ ├── 07b.txt │ ├── 18f.txt │ ├── 03c.txt │ ├── 12a.txt │ ├── 12b.txt │ ├── 07d.txt │ ├── 12.txt │ ├── 06a.txt │ ├── 07c.txt │ ├── 14a.txt │ ├── 06b.txt │ ├── 18h.txt │ ├── 18g.txt │ ├── 14b.txt │ ├── 18b.txt │ ├── 18c.txt │ ├── 10b.txt │ ├── 10c.txt │ ├── 10d.txt │ ├── 18i.txt │ ├── 18e.txt │ ├── 07e.txt │ ├── 18d.txt │ ├── 14c.txt │ ├── 14d.txt │ ├── 02.txt │ ├── 20a.txt │ ├── 10e.txt │ ├── 10.txt │ ├── 16.txt │ ├── 14e.txt │ ├── 07.txt │ ├── 01.txt │ ├── 19.txt │ └── 20b.txt ├── clj │ ├── .gitignore │ ├── README.md │ ├── project.clj │ └── test │ │ ├── d01.clj │ │ └── d02.clj └── go │ ├── 01_test.go │ ├── 04_test.go │ └── 02_test.go ├── 2020 ├── ts │ ├── .gitignore │ ├── jest.config.js │ ├── prettier.config.js │ ├── .eslintrc.js │ ├── D06.test.ts │ ├── package.json │ ├── D03.test.ts │ ├── D15.test.ts │ ├── D05.test.ts │ ├── D25.test.ts │ └── D02.test.ts ├── inputs │ ├── 17-test.txt │ ├── 13-test.txt │ ├── 12-test.txt │ ├── 01-test.txt │ ├── 02-test.txt │ ├── 10-test-01.txt │ ├── 08-test.txt │ ├── 14-test-01.txt │ ├── 17.txt │ ├── 06-test.txt │ ├── 22-test.txt │ ├── 14-test-02.txt │ ├── 11-test.txt │ ├── 09-test.txt │ ├── 21-test.txt │ ├── 18-test-01.txt │ ├── 18-test-02.txt │ ├── 03-test.txt │ ├── 13.txt │ ├── 10-test-02.txt │ ├── 07-test-02.txt │ ├── 04-test-01.txt │ ├── 04-test-02.txt │ ├── 04-test-03.txt │ ├── 22.txt │ ├── 07-test-01.txt │ ├── 24-test.txt │ └── 10.txt └── fsharp │ ├── .gitignore │ ├── aoc2020-test │ ├── Program.fs │ ├── Common.fs │ └── AOC2020.fsproj │ └── AOC2020_Solution.sln ├── 2021 ├── inputs │ ├── 06-test.txt │ ├── 16-test-1.txt │ ├── 07-test.txt │ ├── 16-test-0.txt │ ├── 12-test-0.txt │ ├── 02-test.txt │ ├── 09-test.txt │ ├── 01-test.txt │ ├── 12-test-1.txt │ ├── 03-test.txt │ ├── 25-test.txt │ ├── 22-test-01.txt │ ├── 11.txt │ ├── 05-test.txt │ ├── 11-test.txt │ ├── 15-test.txt │ ├── 12-test-2.txt │ ├── 12.txt │ ├── 13-test.txt │ ├── 14-test.txt │ ├── 10-test.txt │ ├── 04-test.txt │ ├── 18-test.txt │ ├── 20-test.txt │ ├── 06.txt │ ├── 22-test-02.txt │ ├── 08-test.txt │ ├── 16.txt │ └── 14.txt ├── fs │ ├── .gitignore │ ├── Program.fs │ ├── Common.fs │ ├── D06.fs │ ├── aoc-2021.sln │ ├── D01.fs │ └── D02.fs └── ts │ ├── prettier.config.js │ ├── jest.config.js │ ├── D01.test.ts │ ├── .eslintrc.js │ ├── package.json │ ├── D06.test.ts │ ├── D02.test.ts │ └── D07.test.ts ├── 2022 ├── inputs │ ├── 02-test.txt │ ├── 17-test.txt │ ├── 20-test.txt │ ├── 08-test.txt │ ├── 12-test.txt │ ├── 14-test.txt │ ├── 09-test-01.txt │ ├── 04-test.txt │ ├── 09-test-02.txt │ ├── 24-test.txt │ ├── 23-test.txt │ ├── 01-test.txt │ ├── 25-test.txt │ ├── 18-test.txt │ ├── 05-test.txt │ ├── 03-test.txt │ ├── 22-test.txt │ ├── 21-test.txt │ ├── 13-test.txt │ ├── 07-test.txt │ ├── 19-test.txt │ ├── 16-test.txt │ ├── 11-test.txt │ ├── 15-test.txt │ └── 11.txt ├── fs │ ├── .gitignore │ ├── Program.fs │ ├── D01.fs │ ├── D25.fs │ ├── D02.fs │ ├── Common.fs │ ├── D10.fs │ ├── D06.fs │ ├── aoc-2022.sln │ ├── D04.fs │ └── D03.fs └── ts │ ├── prettier.config.js │ ├── jest.config.js │ ├── D01.test.ts │ ├── .eslintrc.js │ ├── D25.test.ts │ ├── package.json │ ├── D04.test.ts │ ├── D03.test.ts │ └── D10.ts ├── 2023 ├── inputs │ ├── 06-t1.txt │ ├── 10-t1.txt │ ├── 10-t2.txt │ ├── 01-t1.txt │ ├── 15-t1.txt │ ├── 09-t1.txt │ ├── 07-t1.txt │ ├── 08-t2.txt │ ├── 06.txt │ ├── 20-t1.txt │ ├── 20-t2.txt │ ├── 22-t1.txt │ ├── 01-t2.txt │ ├── 10-t4.txt │ ├── 24-t1.txt │ ├── 10-t3.txt │ ├── 12-t1.txt │ ├── 03-t1.txt │ ├── 08-t1.txt │ ├── 11-t1.txt │ ├── 14-t1.txt │ ├── 16-t1.txt │ ├── 21-t1.txt │ ├── 08-t3.txt │ ├── 13-t1.txt │ ├── 17-t1.txt │ ├── 10-t5.txt │ ├── 10-t6.txt │ ├── 18-t1.txt │ ├── 04-t1.txt │ ├── 02-t1.txt │ ├── 19-t1.txt │ ├── 05-t1.txt │ ├── 23-t1.txt │ └── 20.txt ├── fs │ ├── .gitignore │ ├── Program.fs │ ├── D04.fs │ ├── Common.fs │ ├── aoc-2023.sln │ ├── aoc-2023.fsproj │ └── D01.fs └── ts │ ├── prettier.config.js │ ├── jest.config.js │ ├── .eslintrc.js │ ├── package.json │ ├── D09.test.ts │ ├── D14.P1.test.ts │ ├── D04.test.ts │ └── D06.test.ts ├── .gitignore └── README.md /2018/inputs/20-test1.txt: -------------------------------------------------------------------------------- 1 | ^WNE$ -------------------------------------------------------------------------------- /2018/ts/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /2019/ts/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /2021/inputs/06-test.txt: -------------------------------------------------------------------------------- 1 | 3,4,3,1,2 -------------------------------------------------------------------------------- /2019/inputs/06d.txt: -------------------------------------------------------------------------------- 1 | COM)YOU 2 | COM)SAN -------------------------------------------------------------------------------- /2020/ts/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /2021/inputs/16-test-1.txt: -------------------------------------------------------------------------------- 1 | 04005AC33890 -------------------------------------------------------------------------------- /2020/inputs/17-test.txt: -------------------------------------------------------------------------------- 1 | .#. 2 | ..# 3 | ### -------------------------------------------------------------------------------- /2022/inputs/02-test.txt: -------------------------------------------------------------------------------- 1 | A Y 2 | B X 3 | C Z -------------------------------------------------------------------------------- /2018/inputs/20-test2.txt: -------------------------------------------------------------------------------- 1 | ^ENWWW(NEEE|SSE(EE|N))$ -------------------------------------------------------------------------------- /2019/inputs/03a.txt: -------------------------------------------------------------------------------- 1 | R8,U5,L5,D3 2 | U7,R6,D4,L4 -------------------------------------------------------------------------------- /2021/inputs/07-test.txt: -------------------------------------------------------------------------------- 1 | 16,1,2,0,4,2,7,1,2,14 -------------------------------------------------------------------------------- /2020/inputs/13-test.txt: -------------------------------------------------------------------------------- 1 | 939 2 | 7,13,x,x,59,x,31,19 -------------------------------------------------------------------------------- /2018/inputs/08-test.txt: -------------------------------------------------------------------------------- 1 | 2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2 -------------------------------------------------------------------------------- /2019/inputs/18a.txt: -------------------------------------------------------------------------------- 1 | ######### 2 | #b.A.@.a# 3 | ######### -------------------------------------------------------------------------------- /2020/inputs/12-test.txt: -------------------------------------------------------------------------------- 1 | F10 2 | N3 3 | F7 4 | R90 5 | F11 -------------------------------------------------------------------------------- /2021/inputs/16-test-0.txt: -------------------------------------------------------------------------------- 1 | A0016C880162017C3686B18A3D4780 -------------------------------------------------------------------------------- /2018/elixir/13.exs: -------------------------------------------------------------------------------- 1 | # No solution 2 | IO.puts("Not done") 3 | -------------------------------------------------------------------------------- /2018/elixir/15.exs: -------------------------------------------------------------------------------- 1 | # No solution 2 | IO.puts("Not done") 3 | -------------------------------------------------------------------------------- /2018/elixir/16.exs: -------------------------------------------------------------------------------- 1 | # No solution 2 | IO.puts("Not done") 3 | -------------------------------------------------------------------------------- /2018/elixir/17.exs: -------------------------------------------------------------------------------- 1 | # No solution 2 | IO.puts("Not done") 3 | -------------------------------------------------------------------------------- /2018/elixir/18.exs: -------------------------------------------------------------------------------- 1 | # No solution 2 | IO.puts("Not done") 3 | -------------------------------------------------------------------------------- /2018/elixir/19.exs: -------------------------------------------------------------------------------- 1 | # No solution 2 | IO.puts("Not done") 3 | -------------------------------------------------------------------------------- /2018/elixir/20.exs: -------------------------------------------------------------------------------- 1 | # No solution 2 | IO.puts("Not done") 3 | -------------------------------------------------------------------------------- /2018/elixir/21.exs: -------------------------------------------------------------------------------- 1 | # No solution 2 | IO.puts("Not done") 3 | -------------------------------------------------------------------------------- /2018/elixir/22.exs: -------------------------------------------------------------------------------- 1 | # No solution 2 | IO.puts("Not done") 3 | -------------------------------------------------------------------------------- /2018/elixir/23.exs: -------------------------------------------------------------------------------- 1 | # No solution 2 | IO.puts("Not done") 3 | -------------------------------------------------------------------------------- /2018/elixir/24.exs: -------------------------------------------------------------------------------- 1 | # No solution 2 | IO.puts("Not done") 3 | -------------------------------------------------------------------------------- /2019/inputs/06c.txt: -------------------------------------------------------------------------------- 1 | COM)A 2 | A)B 3 | B)YOU 4 | COM)D 5 | D)SAN -------------------------------------------------------------------------------- /2019/inputs/24.txt: -------------------------------------------------------------------------------- 1 | .#.## 2 | .#.#. 3 | ##.#. 4 | ####. 5 | #.### -------------------------------------------------------------------------------- /2022/inputs/17-test.txt: -------------------------------------------------------------------------------- 1 | >>><<><>><<<>><>>><<<>>><<<><<<>><>><<>> -------------------------------------------------------------------------------- /2022/inputs/20-test.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | -3 4 | 3 5 | -2 6 | 0 7 | 4 -------------------------------------------------------------------------------- /2018/inputs/20-test3.txt: -------------------------------------------------------------------------------- 1 | ^ENNWSWW(NEWS|)SSSEEN(WNSE|)EE(SWEN|)NNN$ -------------------------------------------------------------------------------- /2019/inputs/07a.txt: -------------------------------------------------------------------------------- 1 | 3,15,3,16,1002,16,10,16,1,16,15,15,4,15,99,0,0 -------------------------------------------------------------------------------- /2019/inputs/10a.txt: -------------------------------------------------------------------------------- 1 | .#..# 2 | ..... 3 | ##### 4 | ....# 5 | ...## -------------------------------------------------------------------------------- /2019/inputs/24a.txt: -------------------------------------------------------------------------------- 1 | ....# 2 | #..#. 3 | #..## 4 | ..#.. 5 | #.... -------------------------------------------------------------------------------- /2020/inputs/01-test.txt: -------------------------------------------------------------------------------- 1 | 1721 2 | 979 3 | 366 4 | 299 5 | 675 6 | 1456 -------------------------------------------------------------------------------- /2022/inputs/08-test.txt: -------------------------------------------------------------------------------- 1 | 30373 2 | 25512 3 | 65332 4 | 33549 5 | 35390 -------------------------------------------------------------------------------- /2023/inputs/06-t1.txt: -------------------------------------------------------------------------------- 1 | Time: 7 15 30 2 | Distance: 9 40 200 -------------------------------------------------------------------------------- /2023/inputs/10-t1.txt: -------------------------------------------------------------------------------- 1 | ..... 2 | .S-7. 3 | .|.|. 4 | .L-J. 5 | ..... -------------------------------------------------------------------------------- /2023/inputs/10-t2.txt: -------------------------------------------------------------------------------- 1 | ..F7. 2 | .FJ|. 3 | SJ.L7 4 | |F--J 5 | LJ... -------------------------------------------------------------------------------- /2018/inputs/06-test.txt: -------------------------------------------------------------------------------- 1 | 1, 1 2 | 1, 6 3 | 8, 3 4 | 3, 4 5 | 5, 5 6 | 8, 9 -------------------------------------------------------------------------------- /2020/fsharp/.gitignore: -------------------------------------------------------------------------------- 1 | **/[Bb]in/ 2 | **/[Oo]bj/ 3 | .vs/ 4 | *.user 5 | -------------------------------------------------------------------------------- /2020/inputs/02-test.txt: -------------------------------------------------------------------------------- 1 | 1-3 a: abcde 2 | 1-3 b: cdefg 3 | 2-9 c: ccccccccc -------------------------------------------------------------------------------- /2021/fs/.gitignore: -------------------------------------------------------------------------------- 1 | **/[Bb]in/ 2 | **/[Oo]bj/ 3 | .vs/ 4 | *.user 5 | pg/ -------------------------------------------------------------------------------- /2021/fs/Program.fs: -------------------------------------------------------------------------------- 1 | module Program = let [] main _ = 0 2 | -------------------------------------------------------------------------------- /2022/fs/.gitignore: -------------------------------------------------------------------------------- 1 | **/[Bb]in/ 2 | **/[Oo]bj/ 3 | .vs/ 4 | *.user 5 | pg/ -------------------------------------------------------------------------------- /2022/fs/Program.fs: -------------------------------------------------------------------------------- 1 | module Program = let [] main _ = 0 2 | -------------------------------------------------------------------------------- /2023/fs/.gitignore: -------------------------------------------------------------------------------- 1 | **/[Bb]in/ 2 | **/[Oo]bj/ 3 | .vs/ 4 | *.user 5 | pg/ -------------------------------------------------------------------------------- /2023/inputs/01-t1.txt: -------------------------------------------------------------------------------- 1 | 1abc2 2 | pqr3stu8vwx 3 | a1b2c3d4e5f 4 | treb7uchet -------------------------------------------------------------------------------- /2023/inputs/15-t1.txt: -------------------------------------------------------------------------------- 1 | rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7 -------------------------------------------------------------------------------- /2018/inputs/20-test4.txt: -------------------------------------------------------------------------------- 1 | ^ESSWWN(E|NNENN(EESS(WNSE|)SSS|WWWSSSSE(SW|NNNE)))$ -------------------------------------------------------------------------------- /2023/inputs/09-t1.txt: -------------------------------------------------------------------------------- 1 | 0 3 6 9 12 15 2 | 1 3 6 10 15 21 3 | 10 13 16 21 30 45 -------------------------------------------------------------------------------- /2019/ts/prettier.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | singleQuote: true 3 | }; 4 | -------------------------------------------------------------------------------- /2022/inputs/12-test.txt: -------------------------------------------------------------------------------- 1 | Sabqponm 2 | abcryxxl 3 | accszExk 4 | acctuvwj 5 | abdefghi -------------------------------------------------------------------------------- /2022/inputs/14-test.txt: -------------------------------------------------------------------------------- 1 | 498,4 -> 498,6 -> 496,6 2 | 503,4 -> 502,4 -> 502,9 -> 494,9 -------------------------------------------------------------------------------- /2020/fsharp/aoc2020-test/Program.fs: -------------------------------------------------------------------------------- 1 | module Program = let [] main _ = 0 2 | -------------------------------------------------------------------------------- /2021/inputs/12-test-0.txt: -------------------------------------------------------------------------------- 1 | start-A 2 | start-b 3 | A-c 4 | A-b 5 | b-d 6 | A-end 7 | b-end -------------------------------------------------------------------------------- /2022/inputs/09-test-01.txt: -------------------------------------------------------------------------------- 1 | R 4 2 | U 4 3 | L 3 4 | D 1 5 | R 4 6 | D 1 7 | L 5 8 | R 2 -------------------------------------------------------------------------------- /2023/fs/Program.fs: -------------------------------------------------------------------------------- 1 | module Program = 2 | [] 3 | let main _ = 0 4 | -------------------------------------------------------------------------------- /2023/inputs/07-t1.txt: -------------------------------------------------------------------------------- 1 | 32T3K 765 2 | T55J5 684 3 | KK677 28 4 | KTJJT 220 5 | QQQJA 483 -------------------------------------------------------------------------------- /2018/inputs/15-test8.txt: -------------------------------------------------------------------------------- 1 | ######### 2 | #G#...#G# 3 | #.#.....# 4 | #...E...# 5 | ######### -------------------------------------------------------------------------------- /2018/inputs/20-test5.txt: -------------------------------------------------------------------------------- 1 | ^WSSEESWWWNW(S|NENNEEEENN(ESSSSW(NWSW|SSEN)|WSWWN(E|WWS(E|SS))))$ -------------------------------------------------------------------------------- /2019/inputs/03b.txt: -------------------------------------------------------------------------------- 1 | R75,D30,R83,U83,L12,D49,R71,U7,L72 2 | U62,R66,U55,R34,D71,R55,D58,R83 -------------------------------------------------------------------------------- /2019/inputs/07b.txt: -------------------------------------------------------------------------------- 1 | 3,23,3,24,1002,24,10,24,1002,23,-1,23,101,5,23,23,1,24,23,23,4,23,99,0,0 -------------------------------------------------------------------------------- /2021/inputs/02-test.txt: -------------------------------------------------------------------------------- 1 | forward 5 2 | down 5 3 | forward 8 4 | up 3 5 | down 8 6 | forward 2 -------------------------------------------------------------------------------- /2021/inputs/09-test.txt: -------------------------------------------------------------------------------- 1 | 2199943210 2 | 3987894921 3 | 9856789892 4 | 8767896789 5 | 9899965678 -------------------------------------------------------------------------------- /2022/inputs/04-test.txt: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /2022/inputs/09-test-02.txt: -------------------------------------------------------------------------------- 1 | R 5 2 | U 8 3 | L 8 4 | D 3 5 | R 17 6 | D 10 7 | L 25 8 | U 20 -------------------------------------------------------------------------------- /2023/inputs/08-t2.txt: -------------------------------------------------------------------------------- 1 | LLR 2 | 3 | AAA = (BBB, BBB) 4 | BBB = (AAA, ZZZ) 5 | ZZZ = (ZZZ, ZZZ) -------------------------------------------------------------------------------- /2017/src/14-input.ts: -------------------------------------------------------------------------------- 1 | export const ip1401 = `flqrgnkx`; 2 | export const ip1402 = `ugkiagan`; 3 | -------------------------------------------------------------------------------- /2018/elixir/11.exs: -------------------------------------------------------------------------------- 1 | # No elixir solution for day 11, the optimal solution is summed area tables 2 | -------------------------------------------------------------------------------- /2019/inputs/18f.txt: -------------------------------------------------------------------------------- 1 | ####### 2 | #a.#Cd# 3 | ##...## 4 | ##.@.## 5 | ##...## 6 | #cB#Ab# 7 | ####### -------------------------------------------------------------------------------- /2022/inputs/24-test.txt: -------------------------------------------------------------------------------- 1 | #.###### 2 | #>>.<^<# 3 | #.<..<<# 4 | #>v.><># 5 | #<^v^^># 6 | ######.# -------------------------------------------------------------------------------- /2023/inputs/06.txt: -------------------------------------------------------------------------------- 1 | Time: 61 70 90 66 2 | Distance: 643 1184 1362 1041 -------------------------------------------------------------------------------- /2023/inputs/20-t1.txt: -------------------------------------------------------------------------------- 1 | broadcaster -> a, b, c 2 | %a -> b 3 | %b -> c 4 | %c -> inv 5 | &inv -> a -------------------------------------------------------------------------------- /2018/inputs/13-test2.txt: -------------------------------------------------------------------------------- 1 | />-<\ 2 | | | 3 | | /<+-\ 4 | | | | v 5 | \>+/ -------------------------------------------------------------------------------- /2018/inputs/15-test1.txt: -------------------------------------------------------------------------------- 1 | ####### 2 | #.G...# 3 | #...EG# 4 | #.#.#G# 5 | #..G#E# 6 | #.....# 7 | ####### -------------------------------------------------------------------------------- /2018/inputs/15-test2.txt: -------------------------------------------------------------------------------- 1 | ####### 2 | #G..#E# 3 | #E#E.E# 4 | #G.##.# 5 | #...#E# 6 | #...E.# 7 | ####### -------------------------------------------------------------------------------- /2018/inputs/15-test3.txt: -------------------------------------------------------------------------------- 1 | ####### 2 | #E..EG# 3 | #.#G.E# 4 | #E.##E# 5 | #G..#.# 6 | #..E#.# 7 | ####### -------------------------------------------------------------------------------- /2018/inputs/15-test4.txt: -------------------------------------------------------------------------------- 1 | ####### 2 | #E.G#.# 3 | #.#G..# 4 | #G.#.G# 5 | #G..#.# 6 | #...E.# 7 | ####### -------------------------------------------------------------------------------- /2018/inputs/15-test5.txt: -------------------------------------------------------------------------------- 1 | ####### 2 | #.E...# 3 | #.#..G# 4 | #.###.# 5 | #E#G#G# 6 | #...#G# 7 | ####### -------------------------------------------------------------------------------- /2018/ts/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: 'ts-jest', 3 | testEnvironment: 'node', 4 | }; -------------------------------------------------------------------------------- /2019/inputs/03c.txt: -------------------------------------------------------------------------------- 1 | R98,U47,R26,D63,R33,U87,L62,D20,R33,U53,R51 2 | U98,R91,D20,R16,D67,R40,U7,R15,U6,R7 -------------------------------------------------------------------------------- /2019/inputs/12a.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /2019/inputs/12b.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /2022/inputs/23-test.txt: -------------------------------------------------------------------------------- 1 | ....#.. 2 | ..###.# 3 | #...#.# 4 | .#...## 5 | #.###.. 6 | ##.#.## 7 | .#..#.. -------------------------------------------------------------------------------- /2023/inputs/20-t2.txt: -------------------------------------------------------------------------------- 1 | broadcaster -> a 2 | %a -> inv, con 3 | &inv -> b 4 | %b -> con 5 | &con -> output -------------------------------------------------------------------------------- /2019/inputs/07d.txt: -------------------------------------------------------------------------------- 1 | 3,26,1001,26,-4,26,3,27,1002,27,2,27,1,27,26,27,4,27,1001,28,-1,28,1005,28,6,99,0,0,5 -------------------------------------------------------------------------------- /2019/inputs/12.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /2019/ts/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: 'ts-jest', 3 | testEnvironment: 'node' 4 | }; 5 | -------------------------------------------------------------------------------- /2020/inputs/10-test-01.txt: -------------------------------------------------------------------------------- 1 | 16 2 | 10 3 | 15 4 | 5 5 | 1 6 | 11 7 | 7 8 | 19 9 | 6 10 | 12 11 | 4 -------------------------------------------------------------------------------- /2021/inputs/01-test.txt: -------------------------------------------------------------------------------- 1 | 199 2 | 200 3 | 208 4 | 210 5 | 200 6 | 207 7 | 240 8 | 269 9 | 260 10 | 263 -------------------------------------------------------------------------------- /2018/inputs/25-test1.txt: -------------------------------------------------------------------------------- 1 | 0,0,0,0 2 | 3,0,0,0 3 | 0,3,0,0 4 | 0,0,3,0 5 | 0,0,0,3 6 | 0,0,0,6 7 | 9,0,0,0 8 | 12,0,0,0 -------------------------------------------------------------------------------- /2019/inputs/06a.txt: -------------------------------------------------------------------------------- 1 | COM)B 2 | B)C 3 | C)D 4 | D)E 5 | E)F 6 | B)G 7 | G)H 8 | D)I 9 | E)J 10 | J)K 11 | K)L -------------------------------------------------------------------------------- /2019/inputs/07c.txt: -------------------------------------------------------------------------------- 1 | 3,31,3,32,1002,32,10,32,1001,31,-2,31,1007,31,0,33,1002,33,7,33,1,33,31,31,1,32,31,31,4,31,99,0,0,0 -------------------------------------------------------------------------------- /2020/inputs/08-test.txt: -------------------------------------------------------------------------------- 1 | nop +0 2 | acc +1 3 | jmp +4 4 | acc +3 5 | jmp -3 6 | acc -99 7 | acc +1 8 | jmp -4 9 | acc +6 -------------------------------------------------------------------------------- /2020/inputs/14-test-01.txt: -------------------------------------------------------------------------------- 1 | mask = XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X 2 | mem[8] = 11 3 | mem[7] = 101 4 | mem[8] = 0 -------------------------------------------------------------------------------- /2020/inputs/17.txt: -------------------------------------------------------------------------------- 1 | ....###. 2 | #...#### 3 | ##.#.### 4 | ..#.#... 5 | ##.#.#.# 6 | #.###### 7 | ..#..#.# 8 | ######.# -------------------------------------------------------------------------------- /2020/inputs/06-test.txt: -------------------------------------------------------------------------------- 1 | abc 2 | 3 | a 4 | b 5 | c 6 | 7 | ab 8 | ac 9 | 10 | a 11 | a 12 | a 13 | a 14 | 15 | b -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/**/node_modules/* 2 | **/**/dist/* 3 | **/**/yarn-error.log 4 | 5 | .fake 6 | .ionide 7 | .vscode 8 | 2023/fs/pg -------------------------------------------------------------------------------- /2017/src/06-input.ts: -------------------------------------------------------------------------------- 1 | export const ip0601 = "0 2 7 0"; 2 | export const ip0602 = "0 5 10 0 11 14 13 4 11 8 8 7 1 4 12 11"; 3 | -------------------------------------------------------------------------------- /2018/elixir/10.exs: -------------------------------------------------------------------------------- 1 | # No solution for day 10, did not found a way to clean console programmatically 2 | IO.puts("Not done") 3 | -------------------------------------------------------------------------------- /2018/inputs/13-test1.txt: -------------------------------------------------------------------------------- 1 | /->-\ 2 | | | /----\ 3 | | /-+--+-\ | 4 | | | | | v | 5 | \-+-/ \-+--/ 6 | \------/ -------------------------------------------------------------------------------- /2020/inputs/22-test.txt: -------------------------------------------------------------------------------- 1 | Player 1: 2 | 9 3 | 2 4 | 6 5 | 3 6 | 1 7 | 8 | Player 2: 9 | 5 10 | 8 11 | 4 12 | 7 13 | 10 -------------------------------------------------------------------------------- /2023/inputs/22-t1.txt: -------------------------------------------------------------------------------- 1 | 1,0,1~1,2,1 2 | 0,0,2~2,0,2 3 | 0,2,3~2,2,3 4 | 0,0,4~0,2,4 5 | 2,0,5~2,2,5 6 | 0,1,6~2,1,6 7 | 1,1,8~1,1,9 -------------------------------------------------------------------------------- /2016/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.exclude": { 3 | "node_modules/": true, 4 | "dist/": true 5 | } 6 | } -------------------------------------------------------------------------------- /2017/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.exclude": { 3 | "node_modules/": true, 4 | "dist/": true 5 | } 6 | } -------------------------------------------------------------------------------- /2019/inputs/14a.txt: -------------------------------------------------------------------------------- 1 | 10 ORE => 10 A 2 | 1 ORE => 1 B 3 | 7 A, 1 B => 1 C 4 | 7 A, 1 C => 1 D 5 | 7 A, 1 D => 1 E 6 | 7 A, 1 E => 1 FUEL -------------------------------------------------------------------------------- /2017/src/10-input.ts: -------------------------------------------------------------------------------- 1 | export const ip1001 = `3,4,1,5`; 2 | export const ip1002 = `225,171,131,2,35,5,0,13,1,246,54,97,255,98,254,110`; 3 | -------------------------------------------------------------------------------- /2018/inputs/19-test1.txt: -------------------------------------------------------------------------------- 1 | #ip 0 2 | seti 5 0 1 3 | seti 6 0 2 4 | addi 0 1 0 5 | addr 1 2 3 6 | setr 1 0 0 7 | seti 8 0 4 8 | seti 9 0 5 -------------------------------------------------------------------------------- /2019/inputs/06b.txt: -------------------------------------------------------------------------------- 1 | COM)B 2 | B)C 3 | C)D 4 | D)E 5 | E)F 6 | B)G 7 | G)H 8 | D)I 9 | E)J 10 | J)K 11 | K)L 12 | K)YOU 13 | I)SAN -------------------------------------------------------------------------------- /2020/ts/jest.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | module.exports = { 3 | preset: 'ts-jest', 4 | testEnvironment: 'node' 5 | }; 6 | -------------------------------------------------------------------------------- /2023/inputs/01-t2.txt: -------------------------------------------------------------------------------- 1 | two1nine 2 | eightwothree 3 | abcone2threexyz 4 | xtwone3four 5 | 4nineeightseven2 6 | zoneight234 7 | 7pqrstsixteen -------------------------------------------------------------------------------- /2019/inputs/18h.txt: -------------------------------------------------------------------------------- 1 | ############# 2 | #DcBa.#.GhKl# 3 | #.###@#@#I### 4 | #e#d#####j#k# 5 | ###C#@#@###J# 6 | #fEbA.#.FgHi# 7 | ############# -------------------------------------------------------------------------------- /2021/inputs/12-test-1.txt: -------------------------------------------------------------------------------- 1 | dc-end 2 | HN-start 3 | start-kj 4 | dc-start 5 | dc-HN 6 | LN-dc 7 | HN-end 8 | kj-sa 9 | kj-HN 10 | kj-dc -------------------------------------------------------------------------------- /2022/inputs/01-test.txt: -------------------------------------------------------------------------------- 1 | 1000 2 | 2000 3 | 3000 4 | 5 | 4000 6 | 7 | 5000 8 | 6000 9 | 10 | 7000 11 | 8000 12 | 9000 13 | 14 | 10000 -------------------------------------------------------------------------------- /2017/src/19-input.01.txt: -------------------------------------------------------------------------------- 1 | | 2 | | +--+ 3 | A | C 4 | F---|----E|--+ 5 | | | | D 6 | +B-+ +--+ -------------------------------------------------------------------------------- /2018/elixir/09.exs: -------------------------------------------------------------------------------- 1 | # No solution for day 09, current knowlegde of elixir not enough to implement LinkedList or Zipper 2 | IO.puts("Not done") 3 | -------------------------------------------------------------------------------- /2018/go/Readme.md: -------------------------------------------------------------------------------- 1 | To run tests 2 | 3 | ``` 4 | go test -v 5 | ``` 6 | 7 | To run specific test 8 | ``` 9 | go test -v -run 01 10 | ``` -------------------------------------------------------------------------------- /2018/inputs/15-test0.txt: -------------------------------------------------------------------------------- 1 | ######### 2 | #G..G..G# 3 | #.......# 4 | #.......# 5 | #G..E..G# 6 | #.......# 7 | #.......# 8 | #G..G..G# 9 | ######### -------------------------------------------------------------------------------- /2018/inputs/15-test6.txt: -------------------------------------------------------------------------------- 1 | ######### 2 | #G......# 3 | #.E.#...# 4 | #..##..G# 5 | #...##..# 6 | #...#...# 7 | #.G...G.# 8 | #.....G.# 9 | ######### -------------------------------------------------------------------------------- /2022/inputs/25-test.txt: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /2020/inputs/14-test-02.txt: -------------------------------------------------------------------------------- 1 | mask = 000000000000000000000000000000X1001X 2 | mem[42] = 100 3 | mask = 00000000000000000000000000000000X0XX 4 | mem[26] = 1 -------------------------------------------------------------------------------- /2021/inputs/03-test.txt: -------------------------------------------------------------------------------- 1 | 00100 2 | 11110 3 | 10110 4 | 10111 5 | 10101 6 | 01111 7 | 00111 8 | 11100 9 | 10000 10 | 11001 11 | 00010 12 | 01010 -------------------------------------------------------------------------------- /2021/inputs/25-test.txt: -------------------------------------------------------------------------------- 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.> -------------------------------------------------------------------------------- /2023/inputs/10-t4.txt: -------------------------------------------------------------------------------- 1 | .......... 2 | .S------7. 3 | .|F----7|. 4 | .||OOOO||. 5 | .||OOOO||. 6 | .|L-7F-J|. 7 | .|II||II|. 8 | .L--JL--J. 9 | .......... -------------------------------------------------------------------------------- /2019/inputs/18g.txt: -------------------------------------------------------------------------------- 1 | ############### 2 | #d.ABC.#.....a# 3 | ######@#@###### 4 | ############### 5 | ######@#@###### 6 | #b.....#.....c# 7 | ############### -------------------------------------------------------------------------------- /2021/inputs/22-test-01.txt: -------------------------------------------------------------------------------- 1 | on x=10..12,y=10..12,z=10..12 2 | on x=11..13,y=11..13,z=11..13 3 | off x=9..11,y=9..11,z=9..11 4 | on x=10..10,y=10..10,z=10..10 -------------------------------------------------------------------------------- /2023/inputs/24-t1.txt: -------------------------------------------------------------------------------- 1 | 19, 13, 30 @ -2, 1, -2 2 | 18, 19, 22 @ -1, -1, -2 3 | 20, 25, 34 @ -2, -2, -4 4 | 12, 31, 28 @ -1, -2, -1 5 | 20, 19, 15 @ 1, -5, -3 -------------------------------------------------------------------------------- /2018/inputs/25-test2.txt: -------------------------------------------------------------------------------- 1 | -1,2,2,0 2 | 0,0,2,-2 3 | 0,0,0,-2 4 | -1,2,0,0 5 | -2,-2,-2,2 6 | 3,0,2,-1 7 | -1,3,2,2 8 | -1,0,-1,0 9 | 0,2,1,-2 10 | 3,0,0,0 -------------------------------------------------------------------------------- /2018/inputs/25-test3.txt: -------------------------------------------------------------------------------- 1 | 1,-1,0,1 2 | 2,0,-1,0 3 | 3,2,-1,0 4 | 0,0,3,1 5 | 0,0,-1,-1 6 | 2,3,-2,0 7 | -2,2,0,0 8 | 2,-2,0,-1 9 | 1,-1,0,-1 10 | 3,2,0,2 -------------------------------------------------------------------------------- /2019/inputs/14b.txt: -------------------------------------------------------------------------------- 1 | 9 ORE => 2 A 2 | 8 ORE => 3 B 3 | 7 ORE => 5 C 4 | 3 A, 4 B => 1 AB 5 | 5 B, 7 C => 1 BC 6 | 4 C, 1 A => 1 CA 7 | 2 AB, 3 BC, 4 CA => 1 FUEL -------------------------------------------------------------------------------- /2019/inputs/18b.txt: -------------------------------------------------------------------------------- 1 | ######################## 2 | #f.D.E.e.C.b.A.@.a.B.c.# 3 | ######################.# 4 | #d.....................# 5 | ######################## -------------------------------------------------------------------------------- /2019/inputs/18c.txt: -------------------------------------------------------------------------------- 1 | ######################## 2 | #...............b.C.D.f# 3 | #.###################### 4 | #.....@.a.B.c.d.A.e.F.g# 5 | ######################## -------------------------------------------------------------------------------- /2020/ts/prettier.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | module.exports = { 3 | singleQuote: true, 4 | tabWidth: 4, 5 | arrowParens : "avoid" 6 | }; 7 | -------------------------------------------------------------------------------- /2021/ts/prettier.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | module.exports = { 3 | singleQuote: true, 4 | tabWidth: 4, 5 | arrowParens : "avoid" 6 | }; 7 | -------------------------------------------------------------------------------- /2022/inputs/18-test.txt: -------------------------------------------------------------------------------- 1 | 2,2,2 2 | 1,2,2 3 | 3,2,2 4 | 2,1,2 5 | 2,3,2 6 | 2,2,1 7 | 2,2,3 8 | 2,2,4 9 | 2,2,6 10 | 1,2,5 11 | 3,2,5 12 | 2,1,5 13 | 2,3,5 -------------------------------------------------------------------------------- /2022/ts/prettier.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | module.exports = { 3 | singleQuote: true, 4 | tabWidth: 4, 5 | arrowParens : "avoid" 6 | }; 7 | -------------------------------------------------------------------------------- /2023/inputs/10-t3.txt: -------------------------------------------------------------------------------- 1 | ........... 2 | .S-------7. 3 | .|F-----7|. 4 | .||.....||. 5 | .||.....||. 6 | .|L-7.F-J|. 7 | .|..|.|..|. 8 | .L--J.L--J. 9 | ........... -------------------------------------------------------------------------------- /2023/ts/prettier.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | module.exports = { 3 | singleQuote: true, 4 | tabWidth: 4, 5 | arrowParens : "avoid" 6 | }; 7 | -------------------------------------------------------------------------------- /2018/inputs/23-test2.txt: -------------------------------------------------------------------------------- 1 | pos=<10,12,12>, r=2 2 | pos=<12,14,12>, r=2 3 | pos=<16,12,12>, r=4 4 | pos=<14,14,14>, r=6 5 | pos=<50,50,50>, r=200 6 | pos=<10,10,10>, r=5 -------------------------------------------------------------------------------- /2018/inputs/25-test4.txt: -------------------------------------------------------------------------------- 1 | 1,-1,-1,-2 2 | -2,-2,0,1 3 | 0,2,1,3 4 | -2,3,-2,1 5 | 0,2,3,-2 6 | -1,-1,1,-2 7 | 0,-2,-1,0 8 | -2,2,3,-1 9 | 1,2,2,0 10 | -1,-2,0,-2 -------------------------------------------------------------------------------- /2023/inputs/12-t1.txt: -------------------------------------------------------------------------------- 1 | ???.### 1,1,3 2 | .??..??...?##. 1,1,3 3 | ?#?#?#?#?#?#?#? 1,3,1,6 4 | ????.#...#... 4,1,1 5 | ????.######..#####. 1,6,5 6 | ?###???????? 3,2,1 -------------------------------------------------------------------------------- /2018/inputs/17-test1.txt: -------------------------------------------------------------------------------- 1 | x=495, y=2..7 2 | y=7, x=495..501 3 | x=501, y=3..7 4 | x=498, y=2..4 5 | x=506, y=1..2 6 | x=498, y=10..13 7 | x=504, y=10..13 8 | y=13, x=498..504 -------------------------------------------------------------------------------- /2021/inputs/11.txt: -------------------------------------------------------------------------------- 1 | 2264552475 2 | 7681287325 3 | 3878781441 4 | 6868471776 5 | 7175255555 6 | 7517441253 7 | 3513418848 8 | 4628736747 9 | 1133155762 10 | 8816621663 -------------------------------------------------------------------------------- /2019/inputs/10b.txt: -------------------------------------------------------------------------------- 1 | ......#.#. 2 | #..#.#.... 3 | ..#######. 4 | .#.#.###.. 5 | .#..#..... 6 | ..#....#.# 7 | #..#....#. 8 | .##.#..### 9 | ##...#..#. 10 | .#....#### -------------------------------------------------------------------------------- /2019/inputs/10c.txt: -------------------------------------------------------------------------------- 1 | #.#...#.#. 2 | .###....#. 3 | .#....#... 4 | ##.#.#.#.# 5 | ....#.#.#. 6 | .##..###.# 7 | ..#...##.. 8 | ..##....## 9 | ......#... 10 | .####.###. -------------------------------------------------------------------------------- /2019/inputs/10d.txt: -------------------------------------------------------------------------------- 1 | .#..#..### 2 | ####.###.# 3 | ....###.#. 4 | ..###.##.# 5 | ##.##.#.#. 6 | ....###..# 7 | ..#.#..#.# 8 | #..#.#.### 9 | .##...##.# 10 | .....#.#.. -------------------------------------------------------------------------------- /2019/inputs/18i.txt: -------------------------------------------------------------------------------- 1 | ############# 2 | #g#f.D#..h#l# 3 | #F###e#E###.# 4 | #dCba@#@BcIJ# 5 | ############# 6 | #nK.L@#@G...# 7 | #M###N#H###.# 8 | #o#m..#i#jk.# 9 | ############# -------------------------------------------------------------------------------- /2020/inputs/11-test.txt: -------------------------------------------------------------------------------- 1 | L.LL.LL.LL 2 | LLLLLLL.LL 3 | L.L.L..L.. 4 | LLLL.LL.LL 5 | L.LL.LL.LL 6 | L.LLLLL.LL 7 | ..L.L..... 8 | LLLLLLLLLL 9 | L.LLLLLL.L 10 | L.LLLLL.LL -------------------------------------------------------------------------------- /2021/inputs/05-test.txt: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /2021/inputs/11-test.txt: -------------------------------------------------------------------------------- 1 | 5483143223 2 | 2745854711 3 | 5264556173 4 | 6141336146 5 | 6357385478 6 | 4167524645 7 | 2176841721 8 | 6882881134 9 | 4846848554 10 | 5283751526 -------------------------------------------------------------------------------- /2021/inputs/15-test.txt: -------------------------------------------------------------------------------- 1 | 1163751742 2 | 1381373672 3 | 2136511328 4 | 3694931569 5 | 7463417111 6 | 1319128137 7 | 1359912421 8 | 3125421639 9 | 1293138521 10 | 2311944581 -------------------------------------------------------------------------------- /2023/inputs/03-t1.txt: -------------------------------------------------------------------------------- 1 | 467..114.. 2 | ...*...... 3 | ..35..633. 4 | ......#... 5 | 617*...... 6 | .....+.58. 7 | ..592..... 8 | ......755. 9 | ...$.*.... 10 | .664.598.. -------------------------------------------------------------------------------- /2023/inputs/08-t1.txt: -------------------------------------------------------------------------------- 1 | RL 2 | 3 | AAA = (BBB, CCC) 4 | BBB = (DDD, EEE) 5 | CCC = (ZZZ, GGG) 6 | DDD = (DDD, DDD) 7 | EEE = (EEE, EEE) 8 | GGG = (GGG, GGG) 9 | ZZZ = (ZZZ, ZZZ) -------------------------------------------------------------------------------- /2023/inputs/11-t1.txt: -------------------------------------------------------------------------------- 1 | ...#...... 2 | .......#.. 3 | #......... 4 | .......... 5 | ......#... 6 | .#........ 7 | .........# 8 | .......... 9 | .......#.. 10 | #...#..... -------------------------------------------------------------------------------- /2023/inputs/14-t1.txt: -------------------------------------------------------------------------------- 1 | O....#.... 2 | O.OO#....# 3 | .....##... 4 | OO.#O....O 5 | .O.....O#. 6 | O.#..O.#.# 7 | ..O..#O..O 8 | .......O.. 9 | #....###.. 10 | #OO..#.... -------------------------------------------------------------------------------- /2023/inputs/16-t1.txt: -------------------------------------------------------------------------------- 1 | .|...\.... 2 | |.-.\..... 3 | .....|-... 4 | ........|. 5 | .......... 6 | .........\ 7 | ..../.\\.. 8 | .-.-/..|.. 9 | .|....-|.\ 10 | ..//.|.... -------------------------------------------------------------------------------- /2018/inputs/18-test1.txt: -------------------------------------------------------------------------------- 1 | .#.#...|#. 2 | .....#|##| 3 | .|..|...#. 4 | ..|#.....# 5 | #.#|||#|#| 6 | ...#.||... 7 | .|....|... 8 | ||...#|.#| 9 | |.||||..|. 10 | ...#.|..|. -------------------------------------------------------------------------------- /2022/inputs/05-test.txt: -------------------------------------------------------------------------------- 1 | [D] 2 | [N] [C] 3 | [Z] [M] [P] 4 | 1 2 3 5 | 6 | move 1 from 2 to 1 7 | move 3 from 1 to 3 8 | move 2 from 2 to 1 9 | move 1 from 1 to 2 -------------------------------------------------------------------------------- /2019/inputs/18e.txt: -------------------------------------------------------------------------------- 1 | ######################## 2 | #@..............ac.GI.b# 3 | ###d#e#f################ 4 | ###A#B#C################ 5 | ###g#h#i################ 6 | ######################## -------------------------------------------------------------------------------- /2020/inputs/09-test.txt: -------------------------------------------------------------------------------- 1 | 35 2 | 20 3 | 15 4 | 25 5 | 47 6 | 40 7 | 62 8 | 55 9 | 65 10 | 95 11 | 102 12 | 117 13 | 150 14 | 182 15 | 127 16 | 219 17 | 299 18 | 277 19 | 309 20 | 576 -------------------------------------------------------------------------------- /2020/inputs/21-test.txt: -------------------------------------------------------------------------------- 1 | mxmxvkd kfcds sqjhc nhms (contains dairy, fish) 2 | trh fvjkl sbzzf mxmxvkd (contains dairy) 3 | sqjhc fvjkl (contains soy) 4 | sqjhc mxmxvkd sbzzf (contains fish) -------------------------------------------------------------------------------- /2019/clj/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /classes 3 | /checkouts 4 | profiles.clj 5 | pom.xml 6 | pom.xml.asc 7 | *.jar 8 | *.class 9 | /.lein-* 10 | /.nrepl-port 11 | .hgignore 12 | .hg/ 13 | -------------------------------------------------------------------------------- /2019/inputs/07e.txt: -------------------------------------------------------------------------------- 1 | 3,52,1001,52,-5,52,3,53,1,52,56,54,1007,54,5,55,1005,55,26,1001,54,-5,54,1105,1,12,1,53,54,53,1008,54,0,55,1001,55,1,55,2,53,55,53,4,53,1001,56,-1,56,1005,56,6,99,0,0,0,0,10 -------------------------------------------------------------------------------- /2022/inputs/03-test.txt: -------------------------------------------------------------------------------- 1 | vJrwpWtwJgWrhcsFMMfFFhFp 2 | jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL 3 | PmmdzqPrVvPwwTWBwg 4 | wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn 5 | ttgJtRGJQctTZtZT 6 | CrZsJsPPZsGzwwsLwLmpwMDw -------------------------------------------------------------------------------- /2021/ts/jest.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 3 | module.exports = { 4 | preset: 'ts-jest', 5 | testEnvironment: 'node', 6 | }; -------------------------------------------------------------------------------- /2022/ts/jest.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 3 | module.exports = { 4 | preset: 'ts-jest', 5 | testEnvironment: 'node', 6 | }; -------------------------------------------------------------------------------- /2023/ts/jest.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 3 | module.exports = { 4 | preset: 'ts-jest', 5 | testEnvironment: 'node', 6 | }; -------------------------------------------------------------------------------- /2020/inputs/18-test-01.txt: -------------------------------------------------------------------------------- 1 | 1 + (2 * 3) + (4 * (5 + 6)) 2 | 2 * 3 + (4 * 5) 3 | 5 + (8 * 3 + 9 + 3 * 4 * 3) 4 | 5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4)) 5 | ((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2 -------------------------------------------------------------------------------- /2020/inputs/18-test-02.txt: -------------------------------------------------------------------------------- 1 | 1 + (2 * 3) + (4 * (5 + 6)) 2 | 2 * 3 + (4 * 5) 3 | 5 + (8 * 3 + 9 + 3 * 4 * 3) 4 | 5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4)) 5 | ((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2 -------------------------------------------------------------------------------- /2023/inputs/21-t1.txt: -------------------------------------------------------------------------------- 1 | ........... 2 | .....###.#. 3 | .###.##..#. 4 | ..#.#...#.. 5 | ....#.#.... 6 | .##..S####. 7 | .##..#...#. 8 | .......##.. 9 | .##.#.####. 10 | .##..##.##. 11 | ........... -------------------------------------------------------------------------------- /2018/inputs/23-test1.txt: -------------------------------------------------------------------------------- 1 | pos=<0,0,0>, r=4 2 | pos=<1,0,0>, r=1 3 | pos=<4,0,0>, r=3 4 | pos=<0,2,0>, r=1 5 | pos=<0,5,0>, r=3 6 | pos=<0,0,3>, r=1 7 | pos=<1,1,1>, r=1 8 | pos=<1,1,2>, r=1 9 | pos=<1,3,1>, r=1 -------------------------------------------------------------------------------- /2020/inputs/03-test.txt: -------------------------------------------------------------------------------- 1 | ..##....... 2 | #...#...#.. 3 | .#....#..#. 4 | ..#.#...#.# 5 | .#...##..#. 6 | ..#.##..... 7 | .#.#.#....# 8 | .#........# 9 | #.##...#... 10 | #...##....# 11 | .#..#...#.# -------------------------------------------------------------------------------- /2023/inputs/08-t3.txt: -------------------------------------------------------------------------------- 1 | LR 2 | 3 | 11A = (11B, XXX) 4 | 11B = (XXX, 11Z) 5 | 11Z = (11B, XXX) 6 | 22A = (22B, XXX) 7 | 22B = (22C, 22C) 8 | 22C = (22Z, 22Z) 9 | 22Z = (22B, 22B) 10 | XXX = (XXX, XXX) -------------------------------------------------------------------------------- /2019/inputs/18d.txt: -------------------------------------------------------------------------------- 1 | ################# 2 | #i.G..c...e..H.p# 3 | ########.######## 4 | #j.A..b...f..D.o# 5 | ########@######## 6 | #k.E..a...g..B.n# 7 | ########.######## 8 | #l.F..d...h..C.m# 9 | ################# -------------------------------------------------------------------------------- /2019/clj/README.md: -------------------------------------------------------------------------------- 1 | Clojure AOC 2019 2 | ================ 3 | 4 | 1. To run all tests 5 | ``` 6 | lein test 7 | ``` 8 | 9 | 2. To run a particular day 10 | ``` 11 | lein test :only d01 12 | ``` 13 | -------------------------------------------------------------------------------- /2021/inputs/12-test-2.txt: -------------------------------------------------------------------------------- 1 | fs-end 2 | he-DX 3 | fs-he 4 | start-DX 5 | pj-DX 6 | end-zg 7 | zg-sl 8 | zg-pj 9 | pj-he 10 | RW-he 11 | fs-DX 12 | pj-RW 13 | zg-RW 14 | start-pj 15 | he-WI 16 | zg-he 17 | pj-fs 18 | start-RW -------------------------------------------------------------------------------- /2023/inputs/13-t1.txt: -------------------------------------------------------------------------------- 1 | #.##..##. 2 | ..#.##.#. 3 | ##......# 4 | ##......# 5 | ..#.##.#. 6 | ..##..##. 7 | #.#.##.#. 8 | 9 | #...##..# 10 | #....#..# 11 | ..##..### 12 | #####.##. 13 | #####.##. 14 | ..##..### 15 | #....#..# -------------------------------------------------------------------------------- /2020/inputs/13.txt: -------------------------------------------------------------------------------- 1 | 1000001 2 | 29,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,41,x,x,x,x,x,x,x,x,x,577,x,x,x,x,x,x,x,x,x,x,x,x,13,17,x,x,x,x,19,x,x,x,23,x,x,x,x,x,x,x,601,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,37 -------------------------------------------------------------------------------- /2021/inputs/12.txt: -------------------------------------------------------------------------------- 1 | lg-GW 2 | pt-start 3 | pt-uq 4 | nx-lg 5 | ve-GW 6 | start-nx 7 | GW-start 8 | GW-nx 9 | pt-SM 10 | sx-GW 11 | lg-end 12 | nx-SM 13 | lg-SM 14 | pt-nx 15 | end-ve 16 | ve-SM 17 | TG-uq 18 | end-SM 19 | SM-uq -------------------------------------------------------------------------------- /2021/inputs/13-test.txt: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /2021/inputs/14-test.txt: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /2019/clj/project.clj: -------------------------------------------------------------------------------- 1 | (defproject aoc-2019 "0.1.0-SNAPSHOT" 2 | :description "AOC 2019" 3 | :dependencies [[org.clojure/clojure "1.10.0"]] 4 | :main ^:skip-aot aoc-2019.core 5 | :target-path "target/%s" 6 | :profiles {:uberjar {:aot :all}}) 7 | -------------------------------------------------------------------------------- /2020/inputs/10-test-02.txt: -------------------------------------------------------------------------------- 1 | 28 2 | 33 3 | 18 4 | 42 5 | 31 6 | 14 7 | 46 8 | 20 9 | 48 10 | 47 11 | 24 12 | 23 13 | 49 14 | 45 15 | 19 16 | 38 17 | 39 18 | 11 19 | 1 20 | 32 21 | 25 22 | 35 23 | 8 24 | 17 25 | 7 26 | 9 27 | 4 28 | 2 29 | 34 30 | 10 31 | 3 -------------------------------------------------------------------------------- /2023/inputs/17-t1.txt: -------------------------------------------------------------------------------- 1 | 2413432311323 2 | 3215453535623 3 | 3255245654254 4 | 3446585845452 5 | 4546657867536 6 | 1438598798454 7 | 4457876987766 8 | 3637877979653 9 | 4654967986887 10 | 4564679986453 11 | 1224686865563 12 | 2546548887735 13 | 4322674655533 -------------------------------------------------------------------------------- /2017/src/19-input.ts: -------------------------------------------------------------------------------- 1 | // tslint:disable:no-trailing-whitespace 2 | import fs = require("fs"); 3 | export const ip1901 = fs.readFileSync("../2017/src/19-input.01.txt").toString(); 4 | export const ip1902 = fs.readFileSync("../2017/src/19-input.02.txt").toString(); 5 | -------------------------------------------------------------------------------- /2022/inputs/22-test.txt: -------------------------------------------------------------------------------- 1 | ...# 2 | .#.. 3 | #... 4 | .... 5 | ...#.......# 6 | ........#... 7 | ..#....#.... 8 | ..........#. 9 | ...#.... 10 | .....#.. 11 | .#...... 12 | ......#. 13 | 14 | 10R5L5R10L4R5L5 -------------------------------------------------------------------------------- /2023/inputs/10-t5.txt: -------------------------------------------------------------------------------- 1 | .F----7F7F7F7F-7.... 2 | .|F--7||||||||FJ.... 3 | .||.FJ||||||||L7.... 4 | FJL7L7LJLJ||LJ.L-7.. 5 | L--J.L7...LJS7F-7L7. 6 | ....F-J..F7FJ|L7L7L7 7 | ....L7.F7||L7|.L7L7| 8 | .....|FJLJ|FJ|F7|.LJ 9 | ....FJL-7.||.||||... 10 | ....L---J.LJ.LJLJ... -------------------------------------------------------------------------------- /2023/inputs/10-t6.txt: -------------------------------------------------------------------------------- 1 | FF7FSF7F7F7F7F7F---7 2 | L|LJ||||||||||||F--J 3 | FL-7LJLJ||||||LJL-77 4 | F--JF--7||LJLJ7F7FJ- 5 | L---JF-JLJ.||-FJLJJ7 6 | |F|F-JF---7F7-L7L|7| 7 | |FFJF7L7F-JF7|JL---7 8 | 7-L-JL7||F7|L7F-7F7| 9 | L.L7LFJ|||||FJL7||LJ 10 | L7JLJL-JLJLJL--JLJ.L -------------------------------------------------------------------------------- /2023/inputs/18-t1.txt: -------------------------------------------------------------------------------- 1 | R 6 (#70c710) 2 | D 5 (#0dc571) 3 | L 2 (#5713f0) 4 | D 2 (#d2c081) 5 | R 2 (#59c680) 6 | D 2 (#411b91) 7 | L 5 (#8ceee2) 8 | U 2 (#caa173) 9 | L 1 (#1b58a2) 10 | U 2 (#caa171) 11 | R 2 (#7807d2) 12 | U 3 (#a77fa3) 13 | L 2 (#015232) 14 | U 2 (#7a21e3) -------------------------------------------------------------------------------- /2022/inputs/21-test.txt: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /2018/inputs/12-test.txt: -------------------------------------------------------------------------------- 1 | initial state: #..#.#..##......###...### 2 | 3 | ...## => # 4 | ..#.. => # 5 | .#... => # 6 | .#.#. => # 7 | .#.## => # 8 | .##.. => # 9 | .#### => # 10 | #.#.# => # 11 | #.### => # 12 | ##.#. => # 13 | ##.## => # 14 | ###.. => # 15 | ###.# => # 16 | ####. => # -------------------------------------------------------------------------------- /2021/inputs/10-test.txt: -------------------------------------------------------------------------------- 1 | [({(<(())[]>[[{[]{<()<>> 2 | [(()[<>])]({[<{<<[]>>( 3 | {([(<{}[<>[]}>{[]{[(<()> 4 | (((({<>}<{<{<>}{[]{[]{} 5 | [[<[([]))<([[{}[[()]]] 6 | [{[{({}]{}}([{[{{{}}([] 7 | {<[[]]>}<{[{[{[]{()[[[] 8 | [<(<(<(<{}))><([]([]() 9 | <{([([[(<>()){}]>(<<{{ 10 | <{([{{}}[<[[[<>{}]]]>[]] -------------------------------------------------------------------------------- /2019/inputs/14c.txt: -------------------------------------------------------------------------------- 1 | 157 ORE => 5 NZVS 2 | 165 ORE => 6 DCFZ 3 | 44 XJWVT, 5 KHKGT, 1 QDVJ, 29 NZVS, 9 GPVTF, 48 HKGWZ => 1 FUEL 4 | 12 HKGWZ, 1 GPVTF, 8 PSHF => 9 QDVJ 5 | 179 ORE => 7 PSHF 6 | 177 ORE => 5 HKGWZ 7 | 7 DCFZ, 7 PSHF => 2 XJWVT 8 | 165 ORE => 2 GPVTF 9 | 3 DCFZ, 7 NZVS, 5 HKGWZ, 10 PSHF => 8 KHKGT -------------------------------------------------------------------------------- /2022/inputs/13-test.txt: -------------------------------------------------------------------------------- 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] -------------------------------------------------------------------------------- /2022/inputs/07-test.txt: -------------------------------------------------------------------------------- 1 | $ cd / 2 | $ ls 3 | dir a 4 | 14848514 b.txt 5 | 8504156 c.dat 6 | dir d 7 | $ cd a 8 | $ ls 9 | dir e 10 | 29116 f 11 | 2557 g 12 | 62596 h.lst 13 | $ cd e 14 | $ ls 15 | 584 i 16 | $ cd .. 17 | $ cd .. 18 | $ cd d 19 | $ ls 20 | 4060174 j 21 | 8033020 d.log 22 | 5626152 d.ext 23 | 7214296 k -------------------------------------------------------------------------------- /2023/inputs/04-t1.txt: -------------------------------------------------------------------------------- 1 | Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53 2 | Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19 3 | Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1 4 | Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83 5 | Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36 6 | Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11 -------------------------------------------------------------------------------- /2020/inputs/07-test-02.txt: -------------------------------------------------------------------------------- 1 | shiny gold bags contain 2 dark red bags. 2 | dark red bags contain 2 dark orange bags. 3 | dark orange bags contain 2 dark yellow bags. 4 | dark yellow bags contain 2 dark green bags. 5 | dark green bags contain 2 dark blue bags. 6 | dark blue bags contain 2 dark violet bags. 7 | dark violet bags contain no other bags. -------------------------------------------------------------------------------- /2022/inputs/19-test.txt: -------------------------------------------------------------------------------- 1 | Blueprint 1: Each ore robot costs 4 ore. Each clay robot costs 2 ore. Each obsidian robot costs 3 ore and 14 clay. Each geode robot costs 2 ore and 7 obsidian. 2 | Blueprint 2: Each ore robot costs 2 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 8 clay. Each geode robot costs 3 ore and 12 obsidian. -------------------------------------------------------------------------------- /2020/fsharp/aoc2020-test/Common.fs: -------------------------------------------------------------------------------- 1 | module Common 2 | 3 | open System.IO 4 | 5 | let basePath = @"D:\Ajay\Projects\adventofcode\2020\inputs"; 6 | 7 | let readLines fileName = Path.Combine(basePath, $"{fileName}.txt") |> File.ReadAllLines; 8 | 9 | let mapLinesToNumber : string -> int list = readLines >> Array.map int >> Array.toList 10 | 11 | -------------------------------------------------------------------------------- /2023/inputs/02-t1.txt: -------------------------------------------------------------------------------- 1 | Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green 2 | Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue 3 | Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red 4 | Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red 5 | Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green -------------------------------------------------------------------------------- /2020/inputs/04-test-01.txt: -------------------------------------------------------------------------------- 1 | ecl:gry pid:860033327 eyr:2020 hcl:#fffffd 2 | byr:1937 iyr:2017 cid:147 hgt:183cm 3 | 4 | iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884 5 | hcl:#cfa07d byr:1929 6 | 7 | hcl:#ae17e1 iyr:2013 8 | eyr:2024 9 | ecl:brn pid:760753108 byr:1931 10 | hgt:179cm 11 | 12 | hcl:#cfa07d eyr:2025 pid:166559648 13 | iyr:2011 ecl:brn hgt:59in -------------------------------------------------------------------------------- /2020/inputs/04-test-02.txt: -------------------------------------------------------------------------------- 1 | eyr:1972 cid:100 2 | hcl:#18171d ecl:amb hgt:170 pid:186cm iyr:2018 byr:1926 3 | 4 | iyr:2019 5 | hcl:#602927 eyr:1967 hgt:170cm 6 | ecl:grn pid:012533040 byr:1946 7 | 8 | hcl:dab227 iyr:2012 9 | ecl:brn hgt:182cm pid:021572410 eyr:2020 byr:1992 cid:277 10 | 11 | hgt:59cm ecl:zzz 12 | eyr:2038 hcl:74454a iyr:2023 13 | pid:3556412378 byr:2007 -------------------------------------------------------------------------------- /2020/inputs/04-test-03.txt: -------------------------------------------------------------------------------- 1 | pid:087499704 hgt:74in ecl:grn iyr:2012 eyr:2030 byr:1980 2 | hcl:#623a2f 3 | 4 | eyr:2029 ecl:blu cid:129 byr:1989 5 | iyr:2014 pid:896056539 hcl:#a97842 hgt:165cm 6 | 7 | hcl:#888785 8 | hgt:164cm byr:2001 iyr:2015 cid:88 9 | pid:545766238 ecl:hzl 10 | eyr:2022 11 | 12 | iyr:2010 hgt:158cm hcl:#b6652a ecl:blu byr:1944 eyr:2021 pid:093154719 -------------------------------------------------------------------------------- /2018/inputs/07-test.txt: -------------------------------------------------------------------------------- 1 | Step C must be finished before step A can begin. 2 | Step C must be finished before step F can begin. 3 | Step A must be finished before step B can begin. 4 | Step A must be finished before step D can begin. 5 | Step B must be finished before step E can begin. 6 | Step D must be finished before step E can begin. 7 | Step F must be finished before step E can begin. -------------------------------------------------------------------------------- /2016/src/15-input.ts: -------------------------------------------------------------------------------- 1 | export const ip1501 = `Disc #1 has 17 positions; at time=0, it is at position 1. 2 | Disc #2 has 7 positions; at time=0, it is at position 0. 3 | Disc #3 has 19 positions; at time=0, it is at position 2. 4 | Disc #4 has 5 positions; at time=0, it is at position 0. 5 | Disc #5 has 3 positions; at time=0, it is at position 0. 6 | Disc #6 has 13 positions; at time=0, it is at position 5.`; 7 | -------------------------------------------------------------------------------- /2021/inputs/04-test.txt: -------------------------------------------------------------------------------- 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/inputs/18-test.txt: -------------------------------------------------------------------------------- 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]]] -------------------------------------------------------------------------------- /2016/src/12-input.ts: -------------------------------------------------------------------------------- 1 | export const ip1201 = `cpy 41 a 2 | inc a 3 | inc a 4 | dec a 5 | jnz a 2 6 | dec a`; 7 | export const ip1202 = `cpy 1 a 8 | cpy 1 b 9 | cpy 26 d 10 | jnz c 2 11 | jnz 1 5 12 | cpy 7 c 13 | inc d 14 | dec c 15 | jnz c -2 16 | cpy a c 17 | inc a 18 | dec b 19 | jnz b -2 20 | cpy c b 21 | dec d 22 | jnz d -6 23 | cpy 18 c 24 | cpy 11 d 25 | inc a 26 | dec d 27 | jnz d -2 28 | dec c 29 | jnz c -5`; 30 | -------------------------------------------------------------------------------- /2016/src/25-input.ts: -------------------------------------------------------------------------------- 1 | export const ip2501 = `cpy a d 2 | cpy 7 c 3 | cpy 362 b 4 | inc d 5 | dec b 6 | jnz b -2 7 | dec c 8 | jnz c -5 9 | cpy d a 10 | jnz 0 0 11 | cpy a b 12 | cpy 0 a 13 | cpy 2 c 14 | jnz b 2 15 | jnz 1 6 16 | dec b 17 | dec c 18 | jnz c -4 19 | inc a 20 | jnz 1 -7 21 | cpy 2 b 22 | jnz c 2 23 | jnz 1 4 24 | dec b 25 | dec c 26 | jnz 1 -4 27 | jnz 0 0 28 | out b 29 | jnz a -19 30 | jnz 1 -21`; 31 | -------------------------------------------------------------------------------- /2017/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "type": "npm", 8 | "script": "build", 9 | "group": { 10 | "kind": "build", 11 | "isDefault": true 12 | } 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /2020/inputs/22.txt: -------------------------------------------------------------------------------- 1 | Player 1: 2 | 28 3 | 3 4 | 35 5 | 27 6 | 19 7 | 40 8 | 14 9 | 15 10 | 17 11 | 22 12 | 45 13 | 47 14 | 26 15 | 13 16 | 32 17 | 38 18 | 43 19 | 24 20 | 29 21 | 5 22 | 31 23 | 48 24 | 49 25 | 41 26 | 25 27 | 28 | Player 2: 29 | 34 30 | 12 31 | 2 32 | 50 33 | 16 34 | 1 35 | 44 36 | 11 37 | 36 38 | 6 39 | 10 40 | 42 41 | 20 42 | 8 43 | 46 44 | 9 45 | 37 46 | 4 47 | 7 48 | 18 49 | 23 50 | 39 51 | 30 52 | 33 53 | 21 -------------------------------------------------------------------------------- /2016/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "emitDecoratorMetadata": true, 5 | "experimentalDecorators": true, 6 | "module": "commonjs", 7 | "moduleResolution": "node", 8 | "noEmitOnError": true, 9 | "noImplicitAny": false, 10 | "removeComments": true, 11 | "sourceMap": true, 12 | "target": "es6" 13 | }, 14 | "exclude": [ 15 | "node_modules" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /2023/inputs/19-t1.txt: -------------------------------------------------------------------------------- 1 | px{a<2006:qkq,m>2090:A,rfg} 2 | pv{a>1716:R,A} 3 | lnx{m>1548:A,A} 4 | rfg{s<537:gd,x>2440:R,A} 5 | qs{s>3448:A,lnx} 6 | qkq{x<1416:A,crn} 7 | crn{x>2662:A,R} 8 | in{s<1351:px,qqz} 9 | qqz{s>2770:qs,m<1801:hdj,R} 10 | gd{a>3333:R,R} 11 | hdj{m>838:A,pv} 12 | 13 | {x=787,m=2655,a=1222,s=2876} 14 | {x=1679,m=44,a=2067,s=496} 15 | {x=2036,m=264,a=79,s=2244} 16 | {x=2461,m=1339,a=466,s=291} 17 | {x=2127,m=1623,a=2188,s=1013} -------------------------------------------------------------------------------- /2019/inputs/14d.txt: -------------------------------------------------------------------------------- 1 | 2 VPVL, 7 FWMGM, 2 CXFTF, 11 MNCFX => 1 STKFG 2 | 17 NVRVD, 3 JNWZP => 8 VPVL 3 | 53 STKFG, 6 MNCFX, 46 VJHF, 81 HVMC, 68 CXFTF, 25 GNMV => 1 FUEL 4 | 22 VJHF, 37 MNCFX => 5 FWMGM 5 | 139 ORE => 4 NVRVD 6 | 144 ORE => 7 JNWZP 7 | 5 MNCFX, 7 RFSQX, 2 FWMGM, 2 VPVL, 19 CXFTF => 3 HVMC 8 | 5 VJHF, 7 MNCFX, 9 VPVL, 37 CXFTF => 6 GNMV 9 | 145 ORE => 6 MNCFX 10 | 1 NVRVD => 8 CXFTF 11 | 1 VJHF, 6 MNCFX => 4 RFSQX 12 | 176 ORE => 6 VJHF -------------------------------------------------------------------------------- /2016/src/23-input.ts: -------------------------------------------------------------------------------- 1 | export const ip2301 = `cpy 2 a 2 | tgl a 3 | tgl a 4 | tgl a 5 | cpy 1 a 6 | dec a 7 | dec a`; 8 | export const ip2302 = `cpy a b 9 | dec b 10 | cpy a d 11 | cpy 0 a 12 | cpy b c 13 | inc a 14 | dec c 15 | jnz c -2 16 | dec d 17 | jnz d -5 18 | dec b 19 | cpy b c 20 | cpy c d 21 | dec d 22 | inc c 23 | jnz d -2 24 | tgl c 25 | cpy -16 c 26 | jnz 1 c 27 | cpy 89 c 28 | jnz 84 d 29 | inc a 30 | inc d 31 | jnz d -2 32 | inc c 33 | jnz c -5`; 34 | -------------------------------------------------------------------------------- /2019/inputs/02.txt: -------------------------------------------------------------------------------- 1 | 1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,13,1,19,1,6,19,23,2,6,23,27,1,5,27,31,2,31,9,35,1,35,5,39,1,39,5,43,1,43,10,47,2,6,47,51,1,51,5,55,2,55,6,59,1,5,59,63,2,63,6,67,1,5,67,71,1,71,6,75,2,75,10,79,1,79,5,83,2,83,6,87,1,87,5,91,2,9,91,95,1,95,6,99,2,9,99,103,2,9,103,107,1,5,107,111,1,111,5,115,1,115,13,119,1,13,119,123,2,6,123,127,1,5,127,131,1,9,131,135,1,135,9,139,2,139,6,143,1,143,5,147,2,147,6,151,1,5,151,155,2,6,155,159,1,159,2,163,1,9,163,0,99,2,0,14,0 -------------------------------------------------------------------------------- /2017/src/23-input.ts: -------------------------------------------------------------------------------- 1 | export const ip2301 = `set b 81 2 | set c b 3 | jnz a 2 4 | jnz 1 5 5 | mul b 100 6 | sub b -100000 7 | set c b 8 | sub c -17000 9 | set f 1 10 | set d 2 11 | set e 2 12 | set g d 13 | mul g e 14 | sub g b 15 | jnz g 2 16 | set f 0 17 | sub e -1 18 | set g e 19 | sub g b 20 | jnz g -8 21 | sub d -1 22 | set g d 23 | sub g b 24 | jnz g -13 25 | jnz f 2 26 | sub h -1 27 | set g b 28 | sub g c 29 | jnz g 2 30 | jnz 1 3 31 | sub b -17 32 | jnz 1 -23`; 33 | -------------------------------------------------------------------------------- /2017/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "no-trailing-whitespace": true, 5 | "trailing-comma": [ false ], 6 | "object-literal-sort-keys": false, 7 | "object-literal-key-quotes": [false], 8 | "no-reference": false, 9 | "max-line-length": [ false, 120 ], 10 | "align": [ true ], 11 | "no-console": [ false ], 12 | "no-string-literal": false, 13 | "no-bitwise": false, 14 | "arrow-parens": false 15 | } 16 | } -------------------------------------------------------------------------------- /2023/inputs/05-t1.txt: -------------------------------------------------------------------------------- 1 | seeds: 79 14 55 13 2 | 3 | seed-to-soil map: 4 | 50 98 2 5 | 52 50 48 6 | 7 | soil-to-fertilizer map: 8 | 0 15 37 9 | 37 52 2 10 | 39 0 15 11 | 12 | fertilizer-to-water map: 13 | 49 53 8 14 | 0 11 42 15 | 42 0 7 16 | 57 7 4 17 | 18 | water-to-light map: 19 | 88 18 7 20 | 18 25 70 21 | 22 | light-to-temperature map: 23 | 45 77 23 24 | 81 45 19 25 | 68 64 13 26 | 27 | temperature-to-humidity map: 28 | 0 69 1 29 | 1 0 69 30 | 31 | humidity-to-location map: 32 | 60 56 37 33 | 56 93 4 -------------------------------------------------------------------------------- /2019/inputs/20a.txt: -------------------------------------------------------------------------------- 1 | A 2 | A 3 | #######.######### 4 | #######.........# 5 | #######.#######.# 6 | #######.#######.# 7 | #######.#######.# 8 | ##### B ###.# 9 | BC...## C ###.# 10 | ##.## ###.# 11 | ##...DE F ###.# 12 | ##### G ###.# 13 | #########.#####.# 14 | DE..#######...###.# 15 | #.#########.###.# 16 | FG..#########.....# 17 | ###########.##### 18 | Z 19 | Z -------------------------------------------------------------------------------- /2017/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "emitDecoratorMetadata": true, 5 | "experimentalDecorators": true, 6 | "module": "commonjs", 7 | "moduleResolution": "node", 8 | "noEmitOnError": true, 9 | "noImplicitAny": false, 10 | "removeComments": true, 11 | "sourceMap": true, 12 | "target": "es6", 13 | "typeRoots": [ "../node_modules/@types" ], 14 | "types" : [ "node"] 15 | }, 16 | "exclude": [ 17 | "node_modules" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /2018/ts/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "no-trailing-whitespace": true, 5 | "trailing-comma": [ false ], 6 | "object-literal-sort-keys": false, 7 | "object-literal-key-quotes": [false], 8 | "no-reference": false, 9 | "max-line-length": [ false, 120 ], 10 | "align": [ true ], 11 | "no-console": [ false ], 12 | "no-string-literal": false, 13 | "no-bitwise": false, 14 | "arrow-parens": false, 15 | "interface-name": false 16 | } 17 | } -------------------------------------------------------------------------------- /2019/inputs/10e.txt: -------------------------------------------------------------------------------- 1 | .#..##.###...####### 2 | ##.############..##. 3 | .#.######.########.# 4 | .###.#######.####.#. 5 | #####.##.#.##.###.## 6 | ..#####..#.######### 7 | #################### 8 | #.####....###.#.#.## 9 | ##.################# 10 | #####.##.###..####.. 11 | ..######..##.####### 12 | ####.##.####...##..# 13 | .#####..#.######.### 14 | ##...#.##########... 15 | #.##########.####### 16 | .####.#.###.###.#.## 17 | ....##.##.###..##### 18 | .#.#.###########.### 19 | #.#.#.#####.####.### 20 | ###.##.####.##.#..## -------------------------------------------------------------------------------- /2021/fs/Common.fs: -------------------------------------------------------------------------------- 1 | module Common 2 | 3 | open System.IO 4 | 5 | let basePath = 6 | @"D:\Ajay\Projects\adventofcode\2021\inputs" 7 | 8 | let readLines fileName = 9 | Path.Combine(basePath, $"{fileName}.txt") 10 | |> File.ReadAllLines 11 | 12 | let mapLinesToNumber: string -> int [] = readLines >> Array.map int 13 | 14 | let mapLines mapper fileName = 15 | fileName |> readLines |> Array.map mapper 16 | 17 | let readText fileName = 18 | Path.Combine(basePath, $"{fileName}.txt") 19 | |> File.ReadAllText; 20 | -------------------------------------------------------------------------------- /2016/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "no-trailing-whitespace": true, 5 | "trailing-comma": [ false ], 6 | "object-literal-sort-keys": false, 7 | "object-literal-key-quotes": [false], 8 | "no-reference": false, 9 | "max-line-length": [ false, 120 ], 10 | "align": [ true ], 11 | "no-console": [ false ], 12 | "no-string-literal": false, 13 | "no-bitwise": false, 14 | "no-unused-variable": [true, {"ignore-pattern": "^_"}], 15 | "arrow-parens": false 16 | } 17 | } -------------------------------------------------------------------------------- /2018/inputs/21.txt: -------------------------------------------------------------------------------- 1 | #ip 1 2 | seti 123 0 3 3 | bani 3 456 3 4 | eqri 3 72 3 5 | addr 3 1 1 6 | seti 0 0 1 7 | seti 0 1 3 8 | bori 3 65536 2 9 | seti 1505483 6 3 10 | bani 2 255 4 11 | addr 3 4 3 12 | bani 3 16777215 3 13 | muli 3 65899 3 14 | bani 3 16777215 3 15 | gtir 256 2 4 16 | addr 4 1 1 17 | addi 1 1 1 18 | seti 27 6 1 19 | seti 0 3 4 20 | addi 4 1 5 21 | muli 5 256 5 22 | gtrr 5 2 5 23 | addr 5 1 1 24 | addi 1 1 1 25 | seti 25 4 1 26 | addi 4 1 4 27 | seti 17 3 1 28 | setr 4 1 2 29 | seti 7 4 1 30 | eqrr 3 0 4 31 | addr 4 1 1 32 | seti 5 9 1 -------------------------------------------------------------------------------- /2020/inputs/07-test-01.txt: -------------------------------------------------------------------------------- 1 | light red bags contain 1 bright white bag, 2 muted yellow bags. 2 | dark orange bags contain 3 bright white bags, 4 muted yellow bags. 3 | bright white bags contain 1 shiny gold bag. 4 | muted yellow bags contain 2 shiny gold bags, 9 faded blue bags. 5 | shiny gold bags contain 1 dark olive bag, 2 vibrant plum bags. 6 | dark olive bags contain 3 faded blue bags, 4 dotted black bags. 7 | vibrant plum bags contain 5 faded blue bags, 6 dotted black bags. 8 | faded blue bags contain no other bags. 9 | dotted black bags contain no other bags. -------------------------------------------------------------------------------- /2019/inputs/10.txt: -------------------------------------------------------------------------------- 1 | ...###.#########.#### 2 | .######.###.###.##... 3 | ####.########.#####.# 4 | ########.####.##.###. 5 | ####..#.####.#.#.##.. 6 | #.################.## 7 | ..######.##.##.#####. 8 | #.####.#####.###.#.## 9 | #####.#########.##### 10 | #####.##..##..#.##### 11 | ##.######....######## 12 | .#######.#.#########. 13 | .#.##.#.#.#.##.###.## 14 | ######...####.#.#.### 15 | ###############.#.### 16 | #.#####.##..###.##.#. 17 | ##..##..###.#.####### 18 | #..#..########.#.##.. 19 | #.#.######.##.##...## 20 | .#.##.#####.#..#####. 21 | #.#.##########..#.##. -------------------------------------------------------------------------------- /2021/inputs/20-test.txt: -------------------------------------------------------------------------------- 1 | ..#.#..#####.#.#.#.###.##.....###.##.#..###.####..#####..#....#..#..##..###..######.###...####..#..#####..##..#.#####...##.#.#..#.##..#.#......#.###.######.###.####...#.##.##..#..#..#####.....#.#....###..#.##......#.....#..#..#..##..#...##.######.####.####.#.#...#.......#..#.#.#...####.##.#......#..#...##.#.##..#...##.#.##..###.#......#.#.......#.#.#.####.###.##...#.....####.#..#..#.##.#....##..#.####....##...##..#...#......#.#.......#.......##..####..#...#.#.#...##..#.#..###..#####........#..####......#..# 2 | 3 | #..#. 4 | #.... 5 | ##..# 6 | ..#.. 7 | ..### -------------------------------------------------------------------------------- /2018/inputs/19.txt: -------------------------------------------------------------------------------- 1 | #ip 4 2 | addi 4 16 4 3 | seti 1 7 2 4 | seti 1 1 5 5 | mulr 2 5 3 6 | eqrr 3 1 3 7 | addr 3 4 4 8 | addi 4 1 4 9 | addr 2 0 0 10 | addi 5 1 5 11 | gtrr 5 1 3 12 | addr 4 3 4 13 | seti 2 7 4 14 | addi 2 1 2 15 | gtrr 2 1 3 16 | addr 3 4 4 17 | seti 1 3 4 18 | mulr 4 4 4 19 | addi 1 2 1 20 | mulr 1 1 1 21 | mulr 4 1 1 22 | muli 1 11 1 23 | addi 3 3 3 24 | mulr 3 4 3 25 | addi 3 9 3 26 | addr 1 3 1 27 | addr 4 0 4 28 | seti 0 1 4 29 | setr 4 9 3 30 | mulr 3 4 3 31 | addr 4 3 3 32 | mulr 4 3 3 33 | muli 3 14 3 34 | mulr 3 4 3 35 | addr 1 3 1 36 | seti 0 6 0 37 | seti 0 7 4 -------------------------------------------------------------------------------- /2018/inputs/24-test1.txt: -------------------------------------------------------------------------------- 1 | Immune System: 2 | 17 units each with 5390 hit points (weak to radiation, bludgeoning) with an attack that does 4507 fire damage at initiative 2 3 | 989 units each with 1274 hit points (immune to fire; weak to bludgeoning, slashing) with an attack that does 25 slashing damage at initiative 3 4 | 5 | Infection: 6 | 801 units each with 4706 hit points (weak to radiation) with an attack that does 116 bludgeoning damage at initiative 1 7 | 4485 units each with 2961 hit points (immune to radiation; weak to fire, cold) with an attack that does 12 slashing damage at initiative 4 -------------------------------------------------------------------------------- /2022/ts/D01.test.ts: -------------------------------------------------------------------------------- 1 | import { descendingBy } from 'dotless'; 2 | import { mapLine } from './util'; 3 | 4 | const sumElfCal = (l: string) => l.split('\n').reduce((acc, l) => acc + +l, 0); 5 | const parse = (ip: string) => mapLine(ip, sumElfCal, '\n\n'); 6 | const solve = (ip: string) => { 7 | const [a, b, c, ..._] = parse(ip).sort(descendingBy()); 8 | return [a, a + b + c]; 9 | }; 10 | 11 | test('01', () => { 12 | const t = solve('01-test'); 13 | const a = solve('01'); 14 | expect(t).toEqual([24000, 45000]); 15 | expect(a).toEqual([68467, 203420]); 16 | }); 17 | -------------------------------------------------------------------------------- /2017/src/13-input.ts: -------------------------------------------------------------------------------- 1 | export const ip1301 = `0: 3 2 | 1: 2 3 | 4: 4 4 | 6: 4`; 5 | export const ip1302 = `0: 4 6 | 1: 2 7 | 2: 3 8 | 4: 4 9 | 6: 6 10 | 8: 5 11 | 10: 6 12 | 12: 6 13 | 14: 6 14 | 16: 8 15 | 18: 8 16 | 20: 9 17 | 22: 12 18 | 24: 8 19 | 26: 8 20 | 28: 8 21 | 30: 12 22 | 32: 12 23 | 34: 8 24 | 36: 12 25 | 38: 10 26 | 40: 12 27 | 42: 12 28 | 44: 10 29 | 46: 12 30 | 48: 14 31 | 50: 12 32 | 52: 14 33 | 54: 14 34 | 56: 12 35 | 58: 14 36 | 60: 12 37 | 62: 14 38 | 64: 18 39 | 66: 14 40 | 68: 14 41 | 72: 14 42 | 76: 14 43 | 82: 14 44 | 86: 14 45 | 88: 18 46 | 90: 14 47 | 92: 17`; 48 | -------------------------------------------------------------------------------- /2021/inputs/06.txt: -------------------------------------------------------------------------------- 1 | 3,5,3,1,4,4,5,5,2,1,4,3,5,1,3,5,3,2,4,3,5,3,1,1,2,1,4,5,3,1,4,5,4,3,3,4,3,1,1,2,2,4,1,1,4,3,4,4,2,4,3,1,5,1,2,3,2,4,4,1,1,1,3,3,5,1,4,5,5,2,5,3,3,1,1,2,3,3,3,1,4,1,5,1,5,3,3,1,5,3,4,3,1,4,1,1,1,2,1,2,3,2,2,4,3,5,5,4,5,3,1,4,4,2,4,4,5,1,5,3,3,5,5,4,4,1,3,2,3,1,2,4,5,3,3,5,4,1,1,5,2,5,1,5,5,4,1,1,1,1,5,3,3,4,4,2,2,1,5,1,1,1,4,4,2,2,2,2,2,5,5,2,4,4,4,1,2,5,4,5,2,5,4,3,1,1,5,4,5,3,2,3,4,1,4,1,1,3,5,1,2,5,1,1,1,5,1,1,4,2,3,4,1,3,3,2,3,1,1,4,4,3,2,1,2,1,4,2,5,4,2,5,3,2,3,3,4,1,3,5,5,1,3,4,5,1,1,3,1,2,1,1,1,1,5,1,1,2,1,4,5,2,1,5,4,2,2,5,5,1,5,1,2,1,5,2,4,3,2,3,1,1,1,2,3,1,4,3,1,2,3,2,1,3,3,2,1,2,5,2 -------------------------------------------------------------------------------- /2017/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "adventofcode-2017", 3 | "version": "1.0.0", 4 | "description": "", 5 | "engines": { 6 | "node": ">=10.9.0" 7 | }, 8 | "scripts": { 9 | "build": "webpack && node dist/run", 10 | "lint" : "tslint './src/*.ts'" 11 | }, 12 | "author": "Ajay Bhosale", 13 | "license": "ISC", 14 | "devDependencies": { 15 | "@types/node": "^10.9.4", 16 | "awesome-typescript-loader": "^5.2.1", 17 | "tslint": "^5.11.0", 18 | "typescript": "^3.0.3", 19 | "webpack": "^4.17.2", 20 | "webpack-cli": "^3.1.0" 21 | }, 22 | "dependencies": {} 23 | } 24 | -------------------------------------------------------------------------------- /2019/go/01_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/stretchr/testify/assert" 5 | "testing" 6 | ) 7 | 8 | func Test01(t *testing.T) { 9 | ip := fetchNumbers("01") 10 | assert.Equal(t, 3334297, calFuel(ip), "01 01") 11 | assert.Equal(t, 4998565, calFuelForFuel(ip), "01 02") 12 | } 13 | 14 | func calFuel(ms []int) (fn int) { 15 | for _, m := range ms { 16 | fn = fn + (m / 3) - 2 17 | } 18 | return 19 | } 20 | 21 | func calFuelForFuel(ms []int) (fn int) { 22 | for _, m := range ms { 23 | for m > 8 { 24 | m = (m / 3) - 2 25 | fn = fn + m 26 | } 27 | } 28 | return 29 | } 30 | -------------------------------------------------------------------------------- /2021/ts/D01.test.ts: -------------------------------------------------------------------------------- 1 | import { mapLineToNumber } from './util'; 2 | 3 | const countIncrements = (ms: number[], indexToCompare = 1) => 4 | ms.reduce( 5 | (c, m, i) => 6 | i >= indexToCompare && m > ms[i - indexToCompare] ? c + 1 : c, 7 | 0 8 | ); 9 | 10 | test('01', () => { 11 | const ti = mapLineToNumber('01-test'); 12 | const ai = mapLineToNumber('01'); 13 | expect(countIncrements(ti)).toEqual(7); 14 | expect(countIncrements(ai)).toEqual(1791); 15 | expect(countIncrements(ti, 3)).toEqual(5); 16 | expect(countIncrements(ai, 3)).toEqual(1822); 17 | }); 18 | -------------------------------------------------------------------------------- /2022/inputs/16-test.txt: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /2018/inputs/12.txt: -------------------------------------------------------------------------------- 1 | initial state: ..##.#######...##.###...#..#.#.#..#.##.#.##....####..........#..#.######..####.#.#..###.##..##..#..# 2 | 3 | #..#. => . 4 | ..#.. => . 5 | ..#.# => # 6 | ##.#. => . 7 | .#... => # 8 | #.... => . 9 | ##### => # 10 | .#.## => . 11 | #.#.. => . 12 | #.### => # 13 | .##.. => # 14 | ##... => . 15 | #...# => # 16 | ####. => # 17 | #.#.# => . 18 | #..## => . 19 | .#### => . 20 | ...## => . 21 | ..### => # 22 | .#..# => . 23 | ##..# => # 24 | .#.#. => . 25 | ..##. => . 26 | ###.. => . 27 | ###.# => # 28 | #.##. => # 29 | ..... => . 30 | .##.# => # 31 | ....# => . 32 | ##.## => # 33 | ...#. => # 34 | .###. => . -------------------------------------------------------------------------------- /2019/ts/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | plugins: ['@typescript-eslint'], 4 | extends: [ 5 | 'eslint:recommended', 6 | 'plugin:@typescript-eslint/eslint-recommended', 7 | 'plugin:@typescript-eslint/recommended', 8 | 'prettier', 9 | 'prettier/@typescript-eslint' 10 | ], 11 | rules: { 12 | '@typescript-eslint/explicit-function-return-type': 'off', 13 | '@typescript-eslint/no-explicit-any': 'off', 14 | '@typescript-eslint/no-unused-vars': [ 15 | 'error', 16 | { argsIgnorePattern: '^_', varsIgnorePattern: '^_' } 17 | ] 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /2016/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "0.1.0", 5 | "command": "gulp", 6 | "isShellCommand": true, 7 | "args": [ 8 | "" 9 | ], 10 | "tasks": [ 11 | { 12 | "taskName": "default", 13 | "args": [], 14 | "isBuildCommand": true, 15 | "isWatching": false, 16 | "problemMatcher": [ 17 | "$lessCompile", 18 | "$tsc", 19 | "$jshint" 20 | ] 21 | } 22 | ] 23 | } -------------------------------------------------------------------------------- /2016/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "adventofcode-2016-ts", 3 | "version": "1.0.0", 4 | "description": "", 5 | "scripts": {}, 6 | "author": "Ajay Bhosale", 7 | "license": "ISC", 8 | "devDependencies": { 9 | "babel-plugin-transform-es2015-destructuring": "^6.19.0", 10 | "babel-plugin-transform-es2015-parameters": "^6.18.0", 11 | "babel-plugin-transform-es2015-spread": "^6.8.0", 12 | "gulp": "^3.9.1", 13 | "gulp-babel": "^6.1.2", 14 | "gulp-sourcemaps": "^1.9.1", 15 | "gulp-typescript": "^3.1.3", 16 | "tslint": "^4.0.2", 17 | "typescript": "^2.0.10" 18 | }, 19 | "dependencies": {} 20 | } 21 | -------------------------------------------------------------------------------- /2019/inputs/16.txt: -------------------------------------------------------------------------------- 1 | 59704176224151213770484189932636989396016853707543672704688031159981571127975101449262562108536062222616286393177775420275833561490214618092338108958319534766917790598728831388012618201701341130599267905059417956666371111749252733037090364984971914108277005170417001289652084308389839318318592713462923155468396822247189750655575623017333088246364350280299985979331660143758996484413769438651303748536351772868104792161361952505811489060546839032499706132682563962136170941039904873411038529684473891392104152677551989278815089949043159200373061921992851799948057507078358356630228490883482290389217471790233756775862302710944760078623023456856105493 -------------------------------------------------------------------------------- /2018/inputs/04-test.txt: -------------------------------------------------------------------------------- 1 | [1518-11-01 00:00] Guard #10 begins shift 2 | [1518-11-01 00:05] falls asleep 3 | [1518-11-01 00:25] wakes up 4 | [1518-11-01 00:30] falls asleep 5 | [1518-11-01 00:55] wakes up 6 | [1518-11-01 23:58] Guard #99 begins shift 7 | [1518-11-02 00:40] falls asleep 8 | [1518-11-02 00:50] wakes up 9 | [1518-11-03 00:05] Guard #10 begins shift 10 | [1518-11-03 00:24] falls asleep 11 | [1518-11-03 00:29] wakes up 12 | [1518-11-04 00:02] Guard #99 begins shift 13 | [1518-11-04 00:36] falls asleep 14 | [1518-11-04 00:46] wakes up 15 | [1518-11-05 00:03] Guard #99 begins shift 16 | [1518-11-05 00:45] falls asleep 17 | [1518-11-05 00:55] wakes up -------------------------------------------------------------------------------- /2019/inputs/14e.txt: -------------------------------------------------------------------------------- 1 | 171 ORE => 8 CNZTR 2 | 7 ZLQW, 3 BMBT, 9 XCVML, 26 XMNCP, 1 WPTQ, 2 MZWV, 1 RJRHP => 4 PLWSL 3 | 114 ORE => 4 BHXH 4 | 14 VRPVC => 6 BMBT 5 | 6 BHXH, 18 KTJDG, 12 WPTQ, 7 PLWSL, 31 FHTLT, 37 ZDVW => 1 FUEL 6 | 6 WPTQ, 2 BMBT, 8 ZLQW, 18 KTJDG, 1 XMNCP, 6 MZWV, 1 RJRHP => 6 FHTLT 7 | 15 XDBXC, 2 LTCX, 1 VRPVC => 6 ZLQW 8 | 13 WPTQ, 10 LTCX, 3 RJRHP, 14 XMNCP, 2 MZWV, 1 ZLQW => 1 ZDVW 9 | 5 BMBT => 4 WPTQ 10 | 189 ORE => 9 KTJDG 11 | 1 MZWV, 17 XDBXC, 3 XCVML => 2 XMNCP 12 | 12 VRPVC, 27 CNZTR => 2 XDBXC 13 | 15 KTJDG, 12 BHXH => 5 XCVML 14 | 3 BHXH, 2 VRPVC => 7 MZWV 15 | 121 ORE => 7 VRPVC 16 | 7 XCVML => 6 RJRHP 17 | 5 BHXH, 4 VRPVC => 5 LTCX -------------------------------------------------------------------------------- /2023/inputs/23-t1.txt: -------------------------------------------------------------------------------- 1 | #.##################### 2 | #.......#########...### 3 | #######.#########.#.### 4 | ###.....#.>.>.###.#.### 5 | ###v#####.#v#.###.#.### 6 | ###.>...#.#.#.....#...# 7 | ###v###.#.#.#########.# 8 | ###...#.#.#.......#...# 9 | #####.#.#.#######.#.### 10 | #.....#.#.#.......#...# 11 | #.#####.#.#.#########v# 12 | #.#...#...#...###...>.# 13 | #.#.#v#######v###.###v# 14 | #...#.>.#...>.>.#.###.# 15 | #####v#.#.###v#.#.###.# 16 | #.....#...#...#.#.#...# 17 | #.#########.###.#.#.### 18 | #...###...#...#...#.### 19 | ###.###.#.###v#####v### 20 | #...#...#.#.>.>.#.>.### 21 | #.###.###.#.###.#.#v### 22 | #.....###...###...#...# 23 | #####################.# -------------------------------------------------------------------------------- /2018/inputs/06.txt: -------------------------------------------------------------------------------- 1 | 292, 73 2 | 204, 176 3 | 106, 197 4 | 155, 265 5 | 195, 59 6 | 185, 136 7 | 54, 82 8 | 209, 149 9 | 298, 209 10 | 274, 157 11 | 349, 196 12 | 168, 353 13 | 193, 129 14 | 94, 137 15 | 177, 143 16 | 196, 357 17 | 272, 312 18 | 351, 340 19 | 253, 115 20 | 109, 183 21 | 252, 232 22 | 193, 258 23 | 242, 151 24 | 220, 345 25 | 336, 348 26 | 196, 203 27 | 122, 245 28 | 265, 189 29 | 124, 57 30 | 276, 204 31 | 309, 125 32 | 46, 324 33 | 345, 228 34 | 251, 134 35 | 231, 117 36 | 88, 112 37 | 256, 229 38 | 49, 201 39 | 142, 108 40 | 150, 337 41 | 134, 109 42 | 288, 67 43 | 297, 231 44 | 310, 131 45 | 208, 255 46 | 246, 132 47 | 232, 45 48 | 356, 93 49 | 356, 207 50 | 83, 97 -------------------------------------------------------------------------------- /2017/src/24-input.ts: -------------------------------------------------------------------------------- 1 | export const ip2401 = `0/2 2 | 2/2 3 | 2/3 4 | 3/4 5 | 3/5 6 | 0/1 7 | 10/1 8 | 9/10`; 9 | export const ip2402 = `50/41 10 | 19/43 11 | 17/50 12 | 32/32 13 | 22/44 14 | 9/39 15 | 49/49 16 | 50/39 17 | 49/10 18 | 37/28 19 | 33/44 20 | 14/14 21 | 14/40 22 | 8/40 23 | 10/25 24 | 38/26 25 | 23/6 26 | 4/16 27 | 49/25 28 | 6/39 29 | 0/50 30 | 19/36 31 | 37/37 32 | 42/26 33 | 17/0 34 | 24/4 35 | 0/36 36 | 6/9 37 | 41/3 38 | 13/3 39 | 49/21 40 | 19/34 41 | 16/46 42 | 22/33 43 | 11/6 44 | 22/26 45 | 16/40 46 | 27/21 47 | 31/46 48 | 13/2 49 | 24/7 50 | 37/45 51 | 49/2 52 | 32/11 53 | 3/10 54 | 32/49 55 | 36/21 56 | 47/47 57 | 43/43 58 | 27/19 59 | 14/22 60 | 13/43 61 | 29/0 62 | 33/36 63 | 2/6`; 64 | -------------------------------------------------------------------------------- /2023/ts/.eslintrc.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | module.exports = { 3 | parser: '@typescript-eslint/parser', 4 | plugins: ['@typescript-eslint'], 5 | extends: [ 6 | 'eslint:recommended', 7 | 'plugin:@typescript-eslint/eslint-recommended', 8 | 'plugin:@typescript-eslint/recommended', 9 | 'prettier' 10 | ], 11 | rules: { 12 | '@typescript-eslint/explicit-function-return-type': 'off', 13 | '@typescript-eslint/no-explicit-any': 'off', 14 | '@typescript-eslint/no-unused-vars': [ 15 | 'error', 16 | { argsIgnorePattern: '^_', varsIgnorePattern: '^_' } 17 | ], 18 | 'arrow-parens': [2, 'as-needed', { 'requireForBlockBody': true }] 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /2020/inputs/24-test.txt: -------------------------------------------------------------------------------- 1 | sesenwnenenewseeswwswswwnenewsewsw 2 | neeenesenwnwwswnenewnwwsewnenwseswesw 3 | seswneswswsenwwnwse 4 | nwnwneseeswswnenewneswwnewseswneseene 5 | swweswneswnenwsewnwneneseenw 6 | eesenwseswswnenwswnwnwsewwnwsene 7 | sewnenenenesenwsewnenwwwse 8 | wenwwweseeeweswwwnwwe 9 | wsweesenenewnwwnwsenewsenwwsesesenwne 10 | neeswseenwwswnwswswnw 11 | nenwswwsewswnenenewsenwsenwnesesenew 12 | enewnwewneswsewnwswenweswnenwsenwsw 13 | sweneswneswneneenwnewenewwneswswnese 14 | swwesenesewenwneswnwwneseswwne 15 | enesenwswwswneneswsenwnewswseenwsese 16 | wnwnesenesenenwwnenwsewesewsesesew 17 | nenewswnwewswnenesenwnesewesw 18 | eneswnwswnwsenenwnwnwwseeswneewsenese 19 | neswnwewnwnwseenwseesewsenwsweewe 20 | wseweeenwnesenwwwswnew -------------------------------------------------------------------------------- /2018/ts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "advent-of-code-2018-typescript", 3 | "version": "1.0.0", 4 | "description": "Advent of code 2018 solutions with typescript", 5 | "main": "index.js", 6 | "author": "Ajay Bhosale", 7 | "license": "MIT", 8 | "scripts": { 9 | "test": "jest --env=node --colors --detectOpenHandles", 10 | "lint": "tslint './*/*.ts'", 11 | "ts": "ts-node" 12 | }, 13 | "devDependencies": { 14 | "@types/jest": "^23.3.10", 15 | "@types/node": "^10.12.11", 16 | "jest": "^23.6.0", 17 | "ts-jest": "^23.10.5", 18 | "ts-node": "^7.0.1", 19 | "tslint": "^5.11.0", 20 | "typescript": "^3.7.2" 21 | }, 22 | "dependencies": { 23 | "dotless": "^1.0.0-beta.12" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /2019/ts/D09.test.ts: -------------------------------------------------------------------------------- 1 | import { getInput } from './util'; 2 | import { IntCodeComputer, SignalType } from './intcode'; 3 | 4 | const puzzleInput = getInput('09'); 5 | 6 | const findDiagnosticCode = (input: number) => { 7 | const computer = IntCodeComputer(puzzleInput); 8 | // eslint-disable-next-line no-constant-condition 9 | while (true) { 10 | const { value } = computer.next(input); 11 | if (value.type === SignalType.OUTPUT) { 12 | return value.number; 13 | } else if (value.type === SignalType.COMPLETE) { 14 | break; 15 | } 16 | } 17 | return 0; 18 | }; 19 | 20 | test('09', () => { 21 | expect(findDiagnosticCode(1)).toEqual(3460311188); 22 | expect(findDiagnosticCode(2)).toEqual(42202); 23 | }); 24 | -------------------------------------------------------------------------------- /2022/inputs/11-test.txt: -------------------------------------------------------------------------------- 1 | Monkey 0: 2 | Starting items: 79, 98 3 | Operation: new = old * 19 4 | Test: divisible by 23 5 | If true: throw to monkey 2 6 | If false: throw to monkey 3 7 | 8 | Monkey 1: 9 | Starting items: 54, 65, 75, 74 10 | Operation: new = old + 6 11 | Test: divisible by 19 12 | If true: throw to monkey 2 13 | If false: throw to monkey 0 14 | 15 | Monkey 2: 16 | Starting items: 79, 60, 97 17 | Operation: new = old * old 18 | Test: divisible by 13 19 | If true: throw to monkey 1 20 | If false: throw to monkey 3 21 | 22 | Monkey 3: 23 | Starting items: 74 24 | Operation: new = old + 3 25 | Test: divisible by 17 26 | If true: throw to monkey 0 27 | If false: throw to monkey 1 -------------------------------------------------------------------------------- /2021/ts/.eslintrc.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | module.exports = { 3 | parser: '@typescript-eslint/parser', 4 | plugins: ['@typescript-eslint'], 5 | extends: [ 6 | 'eslint:recommended', 7 | 'plugin:@typescript-eslint/eslint-recommended', 8 | 'plugin:@typescript-eslint/recommended', 9 | 'prettier' 10 | ], 11 | rules: { 12 | '@typescript-eslint/explicit-function-return-type': 'off', 13 | '@typescript-eslint/no-explicit-any': 'off', 14 | '@typescript-eslint/no-unused-vars': [ 15 | 'error', 16 | { argsIgnorePattern: '^_', varsIgnorePattern: '^_' } 17 | ], 18 | 'arrow-parens': [2, 'as-needed', { 'requireForBlockBody': true }] 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /2022/ts/.eslintrc.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | module.exports = { 3 | parser: '@typescript-eslint/parser', 4 | plugins: ['@typescript-eslint'], 5 | extends: [ 6 | 'eslint:recommended', 7 | 'plugin:@typescript-eslint/eslint-recommended', 8 | 'plugin:@typescript-eslint/recommended', 9 | 'prettier' 10 | ], 11 | rules: { 12 | '@typescript-eslint/explicit-function-return-type': 'off', 13 | '@typescript-eslint/no-explicit-any': 'off', 14 | '@typescript-eslint/no-unused-vars': [ 15 | 'error', 16 | { argsIgnorePattern: '^_', varsIgnorePattern: '^_' } 17 | ], 18 | 'arrow-parens': [2, 'as-needed', { 'requireForBlockBody': true }] 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /2022/fs/D01.fs: -------------------------------------------------------------------------------- 1 | module D01 2 | 3 | open Common 4 | open Xunit 5 | 6 | let pickTop3 c (m1, m2, m3) = 7 | if m3 > c then (m1, m2, m3) 8 | else if m2 > c then (m1, m2, c) 9 | else if m1 > c then (m1, c, m2) 10 | else (c, m1, m2) 11 | 12 | let folder (c , m) = function 13 | | Integer n -> (c + n, m) 14 | | _ -> (0, pickTop3 c m) 15 | 16 | let solve fileName = 17 | let (_, (m1, m2, m3)) = 18 | fileName 19 | |> seqOfLinesWEE 20 | |> Seq.fold folder (0, (0,0,0)) 21 | (m1, m1 + m2 + m3) 22 | 23 | [] 24 | [] 25 | [] 26 | let test01 fn ep1 ep2 = 27 | let (ap1, ap2) = solve fn 28 | Assert.Equal(ep1, ap1) 29 | Assert.Equal(ep2, ap2) -------------------------------------------------------------------------------- /2016/src/20.ts: -------------------------------------------------------------------------------- 1 | import * as inputSets from "./20-input"; 2 | import { assert } from "./util"; 3 | 4 | const lines = inputSets.ip2001.split("\n"); 5 | const parseRange = l => l.split("-").map(n => +n); 6 | const range: any = lines.map(parseRange).sort((a, b) => a[0] - b[0]); 7 | let allowedInRange = 0; 8 | let firstValid = -1; 9 | let lastTo = 0; 10 | for (const [from, to] of range) { 11 | if (from - lastTo > 1) { 12 | if (firstValid === -1) { 13 | firstValid = lastTo + 1; 14 | } 15 | allowedInRange += from - lastTo - 1; 16 | } 17 | lastTo = Math.max(lastTo, to); 18 | } 19 | const allowed = 4294967295 - lastTo + allowedInRange; 20 | assert(firstValid, 19449262, "Day 20 - Set 1"); 21 | assert(allowed, 119, "Day 20 - Set 1"); 22 | -------------------------------------------------------------------------------- /2020/ts/.eslintrc.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | module.exports = { 3 | parser: '@typescript-eslint/parser', 4 | plugins: ['@typescript-eslint'], 5 | extends: [ 6 | 'eslint:recommended', 7 | 'plugin:@typescript-eslint/eslint-recommended', 8 | 'plugin:@typescript-eslint/recommended', 9 | 'prettier', 10 | 'prettier/@typescript-eslint' 11 | ], 12 | rules: { 13 | '@typescript-eslint/explicit-function-return-type': 'off', 14 | '@typescript-eslint/no-explicit-any': 'off', 15 | '@typescript-eslint/no-unused-vars': [ 16 | 'error', 17 | { argsIgnorePattern: '^_', varsIgnorePattern: '^_' } 18 | ], 19 | 'arrow-parens': [2, "as-needed", { "requireForBlockBody": true }] 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /2016/src/01-input.ts: -------------------------------------------------------------------------------- 1 | export const ip0101 = "R2, L3"; 2 | export const ip0102 = "R2, R2, R2"; 3 | export const ip0103 = "R5, L5, R5, R3"; 4 | export const ip0104 = "R8, R4, R4, R8"; 5 | export const ip0105 = `R4, R1, L2, R1, L1, L1, R1, L5, R1, R5, L2, R3, L3, L4, R4, R4, R3, L5, L1, R5, R3, L4, R1, R5, L1, R3, L2, R3, R1, L4, L1, R1, L1, L5, R1, L2, R2, L3, L5, R1, R5, L1, R188, L3, R2, R52, R5, L3, R79, L1, R5, R186, R2, R1, L3, L5, L2, R2, R4, R5, R5, L5, L4, R5, R3, L4, R4, L4, L4, R5, L4, L3, L1, L4, R1, R2, L5, R3, L4, R3, L3, L5, R1, R1, L3, R2, R1, R2, R2, L4, R5, R1, R3, R2, L2, L2, L1, R2, L1, L3, R5, R1, R4, R5, R2, R2, R4, R4, R1, L3, R4, L2, R2, R1, R3, L5, R5, R2, R5, L1, R2, R4, L1, R5, L3, L3, R1, L4, R2, L2, R1, L1, R4, R3, L2, L3, R3, L2, R1, L4, R5, L1, R5, L2, L1, L5, L2, L5, L2, L4, L2, R3`; 6 | -------------------------------------------------------------------------------- /2019/clj/test/d01.clj: -------------------------------------------------------------------------------- 1 | (ns d01 2 | (:require [clojure.test :refer [deftest testing is]])) 3 | 4 | (def input (->> "../inputs/01.txt" 5 | (slurp) 6 | (clojure.string/split-lines) 7 | (map #(Integer/parseInt %)))) 8 | 9 | (defn calfuel [m] (->> m 10 | (#(quot % 3)) 11 | (#(- % 2)) 12 | (max 0))) 13 | 14 | (defn calfuelrecur 15 | [m] 16 | (let [f (calfuel m)] 17 | (if (<= f 0) 18 | 0 19 | (+ f (calfuelrecur f))))) 20 | 21 | (defn solve [ms f] (->> ms (map f) (reduce +))) 22 | 23 | (deftest part-1 24 | (testing "Day 01 01" (is (= 3334297 (solve input calfuel))))) 25 | 26 | (deftest part-2 27 | (testing "Day 01 02" (is (= 4998565 (solve input calfuelrecur))))) 28 | -------------------------------------------------------------------------------- /2022/inputs/15-test.txt: -------------------------------------------------------------------------------- 1 | Sensor at x=2, y=18: closest beacon is at x=-2, y=15 2 | Sensor at x=9, y=16: closest beacon is at x=10, y=16 3 | Sensor at x=13, y=2: closest beacon is at x=15, y=3 4 | Sensor at x=12, y=14: closest beacon is at x=10, y=16 5 | Sensor at x=10, y=20: closest beacon is at x=10, y=16 6 | Sensor at x=14, y=17: closest beacon is at x=10, y=16 7 | Sensor at x=8, y=7: closest beacon is at x=2, y=10 8 | Sensor at x=2, y=0: closest beacon is at x=2, y=10 9 | Sensor at x=0, y=11: closest beacon is at x=2, y=10 10 | Sensor at x=20, y=14: closest beacon is at x=25, y=17 11 | Sensor at x=17, y=20: closest beacon is at x=21, y=22 12 | Sensor at x=16, y=7: closest beacon is at x=15, y=3 13 | Sensor at x=14, y=3: closest beacon is at x=15, y=3 14 | Sensor at x=20, y=1: closest beacon is at x=15, y=3 -------------------------------------------------------------------------------- /2019/ts/D01.test.ts: -------------------------------------------------------------------------------- 1 | import { map, query } from 'dotless'; 2 | import { getInput, sumIt } from './util'; 3 | 4 | const puzzleInput = getInput('01') 5 | .split('\n') 6 | .map(n => +n); 7 | 8 | const calFuel = (m: number) => Math.max(Math.floor(m / 3) - 2, 0); 9 | 10 | const calAllFuel = (m: number): number => { 11 | const f = calFuel(m); 12 | if (f > 0) { 13 | return f + calAllFuel(f); 14 | } 15 | return 0; 16 | }; 17 | 18 | test('01, Part 1', () => { 19 | expect(query(puzzleInput, map(calFuel), sumIt)).toEqual(3334297); 20 | }); 21 | 22 | test('01, Part 2', () => { 23 | expect(calAllFuel(14)).toEqual(2); 24 | expect(calAllFuel(1969)).toEqual(966); 25 | expect(calAllFuel(100756)).toEqual(50346); 26 | expect(query(puzzleInput, map(calAllFuel), sumIt)).toEqual(4998565); 27 | }); 28 | -------------------------------------------------------------------------------- /2017/src/18-input.ts: -------------------------------------------------------------------------------- 1 | export const ip1801 = `set a 1 2 | add a 2 3 | mul a a 4 | mod a 5 5 | snd a 6 | set a 0 7 | rcv a 8 | jgz a -1 9 | set a 1 10 | jgz a -2`; 11 | export const ip1802 = `set i 31 12 | set a 1 13 | mul p 17 14 | jgz p p 15 | mul a 2 16 | add i -1 17 | jgz i -2 18 | add a -1 19 | set i 127 20 | set p 464 21 | mul p 8505 22 | mod p a 23 | mul p 129749 24 | add p 12345 25 | mod p a 26 | set b p 27 | mod b 10000 28 | snd b 29 | add i -1 30 | jgz i -9 31 | jgz a 3 32 | rcv b 33 | jgz b -1 34 | set f 0 35 | set i 126 36 | rcv a 37 | rcv b 38 | set p a 39 | mul p -1 40 | add p b 41 | jgz p 4 42 | snd a 43 | set a b 44 | jgz 1 3 45 | snd b 46 | set f 1 47 | add i -1 48 | jgz i -11 49 | snd a 50 | jgz f -16 51 | jgz a -19`; 52 | export const ip1803 = `snd 1 53 | snd 2 54 | snd p 55 | rcv a 56 | rcv b 57 | rcv c 58 | rcv d`; 59 | -------------------------------------------------------------------------------- /2015/04.js: -------------------------------------------------------------------------------- 1 | //http://www.myersdaily.org/joseph/javascript/md5.js 2 | 3 | //Goto page 4 | //http://www.myersdaily.org/joseph/javascript/md5-text.html 5 | 6 | var md5 = require("./lib/md5.js"); 7 | 8 | var input = "yzbqklnj"; 9 | 10 | function findNumber(input, guessFrom, guessTo, startsWith) { 11 | var found = false; 12 | var number = 0; 13 | for (number = guessFrom; number < guessTo; number++) { 14 | var hash = md5(input + number); 15 | if (hash.startsWith(startsWith)) { 16 | found = true; 17 | break; 18 | } 19 | } 20 | console.log(found ? number : -1); 21 | } 22 | 23 | //282749 24 | findNumber(input, 280000, 320000, "00000"); 25 | //9962624 26 | findNumber(input, 8888888, 9999999, "000000"); 27 | //if you are getting -1 or an incorrect answer, increase the span of guess -------------------------------------------------------------------------------- /2017/src/22-input.ts: -------------------------------------------------------------------------------- 1 | export const ip2201 = `..# 2 | #.. 3 | ...`; 4 | export const ip2202 = `#.##.###.#.#.##.###.##.## 5 | .##.#.#.#..####.###.....# 6 | ...##.....#..###.#..#.##. 7 | ##.###.#...###.#.##..##.# 8 | ###.#.###..#.#.##.#.###.# 9 | .###..#.#.####..##..#..## 10 | ..###.##..###.#..#...###. 11 | ........##..##..###...... 12 | ######...###...###...#... 13 | .######.##.###.#.#...###. 14 | ###.##.###..##..#..##.##. 15 | .#.....#.#.#.#.##........ 16 | #..#..#.#...##......#.### 17 | #######.#...#..###..#..## 18 | #..#.###...#.#.#.#.#....# 19 | #.#####...#.##.##..###.## 20 | ..#..#..#.....#...#.#...# 21 | ###.###.#...###.#.##.#### 22 | .....###.#..##.##.#.###.# 23 | #..#...######.....##.##.# 24 | ###.#.#.#.#.###.##..###.# 25 | ..####.###.##.#.###..#.## 26 | #.#....###....##...#.##.# 27 | ###..##.##.#.#.##..##...# 28 | #.####.###.#...#.#.....##`; 29 | -------------------------------------------------------------------------------- /2017/webpack.config.js: -------------------------------------------------------------------------------- 1 | const { resolve } = require("path"); 2 | const { CheckerPlugin } = require("awesome-typescript-loader"); 3 | 4 | module.exports = { 5 | mode: "development", 6 | target: "node", 7 | entry: { 8 | run: "./src/run.ts" 9 | }, 10 | output: { 11 | filename: "[name].js", 12 | path: resolve(__dirname, "dist") 13 | }, 14 | devtool: "eval", 15 | resolve: { 16 | extensions: [".ts", ".js"] 17 | }, 18 | module: { 19 | rules: [ 20 | { 21 | test: /\.ts/, 22 | use: [ 23 | { 24 | loader: "awesome-typescript-loader", 25 | options: { 26 | configFileName: resolve(__dirname, "./tsconfig.json") 27 | } 28 | } 29 | ] 30 | } 31 | ] 32 | }, 33 | plugins: [ 34 | new CheckerPlugin() 35 | ] 36 | }; 37 | -------------------------------------------------------------------------------- /2021/inputs/22-test-02.txt: -------------------------------------------------------------------------------- 1 | on x=-20..26,y=-36..17,z=-47..7 2 | on x=-20..33,y=-21..23,z=-26..28 3 | on x=-22..28,y=-29..23,z=-38..16 4 | on x=-46..7,y=-6..46,z=-50..-1 5 | on x=-49..1,y=-3..46,z=-24..28 6 | on x=2..47,y=-22..22,z=-23..27 7 | on x=-27..23,y=-28..26,z=-21..29 8 | on x=-39..5,y=-6..47,z=-3..44 9 | on x=-30..21,y=-8..43,z=-13..34 10 | on x=-22..26,y=-27..20,z=-29..19 11 | off x=-48..-32,y=26..41,z=-47..-37 12 | on x=-12..35,y=6..50,z=-50..-2 13 | off x=-48..-32,y=-32..-16,z=-15..-5 14 | on x=-18..26,y=-33..15,z=-7..46 15 | off x=-40..-22,y=-38..-28,z=23..41 16 | on x=-16..35,y=-41..10,z=-47..6 17 | off x=-32..-23,y=11..30,z=-14..3 18 | on x=-49..-5,y=-3..45,z=-29..18 19 | off x=18..30,y=-20..-8,z=-3..13 20 | on x=-41..9,y=-7..43,z=-33..15 21 | on x=-54112..-39298,y=-85059..-49293,z=-27449..7877 22 | on x=967..23432,y=45373..81175,z=27513..53682 -------------------------------------------------------------------------------- /2022/fs/D25.fs: -------------------------------------------------------------------------------- 1 | module D25 2 | 3 | open Common 4 | open Xunit 5 | 6 | let valueMap = 7 | Map [ 8 | '2', 2L 9 | '1', 1L 10 | '0', 0L 11 | '-', -1L 12 | '=', -2L 13 | ] 14 | 15 | let charMap = [|"="; "-"; "0"; "1"; "2"|] 16 | 17 | let s2n s = 18 | s 19 | |> Seq.fold (fun n c -> 5L * n + valueMap[c]) 0L 20 | 21 | let n2s n = 22 | let rec loop s = function 23 | | 0L -> s 24 | | n -> 25 | let r = int ((n + 2L) % 5L) 26 | let d = (n + 2L) / 5L 27 | loop (charMap[r] + s) d 28 | loop "" n 29 | 30 | let solve fn = 31 | fn 32 | |> seqOfLines 33 | |> Seq.sumBy s2n 34 | |> n2s 35 | 36 | [] 37 | [] 38 | [] 39 | let test24 fn ep1 = 40 | Assert.Equal(ep1, solve fn) 41 | -------------------------------------------------------------------------------- /2021/inputs/08-test.txt: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /2017/src/04.ts: -------------------------------------------------------------------------------- 1 | import * as inputSets from "./04-input"; 2 | import { any, findPairs, query } from "./linq"; 3 | import { assert } from "./util"; 4 | 5 | const parseInput = input => input.split("\n").map(line => line.split(" ")); 6 | const duplicate = (a, b) => a === b; 7 | const anagram = (a, b) => a.split("").sort().join("") === b.split("").sort().join(""); 8 | const apartFrom = predicate => pharse => query([pharse, findPairs(predicate), any()]) === false; 9 | const findValidPassphrases = (input, predicate) => parseInput(input).filter(apartFrom(predicate)).length; 10 | 11 | assert(findValidPassphrases(inputSets.ip0401, duplicate), 2, "04.1, Test 01"); 12 | assert(findValidPassphrases(inputSets.ip0402, duplicate), 383, "04.1"); 13 | assert(findValidPassphrases(inputSets.ip0403, anagram), 3, "04.2, Test 01"); 14 | assert(findValidPassphrases(inputSets.ip0402, anagram), 265, "04.2"); 15 | -------------------------------------------------------------------------------- /2016/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible Node.js debug attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Launch Program", 11 | "program": "${workspaceRoot}\\dist\\11", 12 | "cwd": "${workspaceRoot}", 13 | "outFiles": ["dist\\11.js"], 14 | "sourceMaps": true 15 | }, 16 | { 17 | "type": "node", 18 | "request": "attach", 19 | "name": "Attach to Process", 20 | "port": 5858, 21 | "outFiles": ["dist\\11.js"], 22 | "sourceMaps": true 23 | } 24 | ] 25 | } -------------------------------------------------------------------------------- /2019/ts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "advent-of-code-2019", 3 | "version": "1.0.0", 4 | "description": "Advent of code 2019 solutions with typescript", 5 | "main": "index.js", 6 | "author": "Ajay Bhosale", 7 | "license": "MIT", 8 | "scripts": { 9 | "test": "jest --env=node --colors --detectOpenHandles", 10 | "ts": "ts-node", 11 | "tsc": "tsc", 12 | "lint": "eslint *.ts && prettier -c \"*.ts\"" 13 | }, 14 | "devDependencies": { 15 | "@types/jest": "^24.0.23", 16 | "@types/node": "^12.12.14", 17 | "@typescript-eslint/eslint-plugin": "2.9.0", 18 | "@typescript-eslint/parser": "2.9.0", 19 | "eslint": "^6.7.2", 20 | "eslint-config-prettier": "^6.7.0", 21 | "jest": "^24.9.0", 22 | "ts-jest": "^24.2.0", 23 | "ts-node": "^8.5.4", 24 | "typescript": "^3.7.2" 25 | }, 26 | "dependencies": { 27 | "dotless": "^1.0.0-beta.12" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /2022/ts/D25.test.ts: -------------------------------------------------------------------------------- 1 | import { mapLine } from './util'; 2 | 3 | const value: any = { 4 | 1: 1, 5 | 2: 2, 6 | '=': -2, 7 | '-': -1, 8 | 0: 0, 9 | }; 10 | const s2n = (s: string) => { 11 | let p = 0; 12 | let v = 0; 13 | for (let i = s.length - 1; i >= 0; i--) { 14 | v = v + Math.pow(5, p) * value[s[i]]; 15 | p = p + 1; 16 | } 17 | return v; 18 | }; 19 | 20 | const unit = ['=', '-', '0', '1', '2']; 21 | const n2s = (n: number): string => { 22 | if (n === 0) { 23 | return ''; 24 | } 25 | const d = Math.floor((n + 2) / 5); 26 | const m = (n + 2) % 5; 27 | return n2s(d) + unit[m]; 28 | }; 29 | 30 | const solve = (fn: string) => n2s(mapLine(fn, s2n).reduce((a, b) => a + b, 0)); 31 | 32 | test('25', () => { 33 | expect(solve('25-test')).toEqual('2=-1=0'); 34 | expect(solve('25')).toEqual('2=10---0===-1--01-20'); 35 | }); 36 | -------------------------------------------------------------------------------- /2016/gulpfile.js: -------------------------------------------------------------------------------- 1 | // tslint:disable:no-console 2 | var gulp = require("gulp"); 3 | var sourcemaps = require("gulp-sourcemaps"); 4 | var ts = require("gulp-typescript"); 5 | var babel = require("gulp-babel"); 6 | var exec = require("child_process").exec; 7 | var tsProject = ts.createProject("./tsconfig.json"); 8 | 9 | gulp.task("build", function() { 10 | return gulp.src("src/**/*.ts") 11 | .pipe(sourcemaps.init()) 12 | .pipe(tsProject()) 13 | .pipe(babel({ 14 | plugins: ["transform-es2015-destructuring", "transform-es2015-parameters", "transform-es2015-spread"], 15 | })) 16 | .pipe(sourcemaps.write(".")) 17 | .pipe(gulp.dest("dist")); 18 | }); 19 | 20 | gulp.task("default", ["build"], function() { 21 | return exec("node dist/run", function (err, stdout, stderr) { 22 | console.log(stdout); 23 | console.log(stderr); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /2016/src/15.ts: -------------------------------------------------------------------------------- 1 | import * as inputSets from "./15-input"; 2 | import { assert } from "./util"; 3 | 4 | const findTicks = (input, addExtraDish = false) => { 5 | const regex = /Disc #\d+ has (\d+) positions; at time=0, it is at position (\d+)/; 6 | const parseLine = m => [+(m[1]), +(m[2])]; 7 | const discs = input.split("\n").map(l => l.match(regex)).map(parseLine); 8 | const willPassDisc = ([positions, offset], diskIndex, tick) => (tick + diskIndex + 1 + offset) % positions === 0; 9 | const willPass = (tick) => discs.every((disc, diskIndex) => willPassDisc(disc, diskIndex, tick)); 10 | if (addExtraDish) { 11 | discs.push([11, 0]); 12 | } 13 | let tick = 0; 14 | while (!willPass(tick)) { 15 | tick++; 16 | } 17 | return tick; 18 | }; 19 | assert(findTicks(inputSets.ip1501), 317371, "Day 15 - Set 1"); 20 | assert(findTicks(inputSets.ip1501, true), 2080951, "Day 15 - Set 1"); 21 | -------------------------------------------------------------------------------- /2019/go/04_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/stretchr/testify/assert" 5 | "strconv" 6 | "testing" 7 | ) 8 | 9 | func Test04(t *testing.T) { 10 | assert.Equal(t, []int{1154, 750}, countValidPasswords(240920, 789857), "04") 11 | } 12 | 13 | func countValidPasswords(from int, to int) []int { 14 | p1, p2 := 0, 0 15 | 16 | outer: 17 | for i := from; i <= to; i++ { 18 | last, doublecount, count, repeats := '0', 0, 0, false 19 | for _, c := range strconv.Itoa(i) { 20 | if last > c { 21 | continue outer 22 | } 23 | if last == c { 24 | repeats = true 25 | count++ 26 | if count == 1 { 27 | doublecount++ 28 | } else if count == 2 { 29 | doublecount-- 30 | } 31 | } else { 32 | count = 0 33 | } 34 | last = c 35 | } 36 | if repeats { 37 | p1++ 38 | } 39 | if doublecount > 0 { 40 | p2++ 41 | } 42 | } 43 | return []int{p1, p2} 44 | } 45 | -------------------------------------------------------------------------------- /2022/fs/D02.fs: -------------------------------------------------------------------------------- 1 | module D02 2 | 3 | open Common 4 | open Xunit 5 | 6 | // for a more programming kind solution 7 | // check typescript version 8 | let folder (p1, p2) = function 9 | | "A X" -> (p1 + 1 + 3, p2 + 3 + 0) 10 | | "A Y" -> (p1 + 2 + 6, p2 + 1 + 3) 11 | | "A Z" -> (p1 + 3 + 0, p2 + 2 + 6) 12 | | "B X" -> (p1 + 1 + 0, p2 + 1 + 0) 13 | | "B Y" -> (p1 + 2 + 3, p2 + 2 + 3) 14 | | "B Z" -> (p1 + 3 + 6, p2 + 3 + 6) 15 | | "C X" -> (p1 + 1 + 6, p2 + 2 + 0) 16 | | "C Y" -> (p1 + 2 + 0, p2 + 3 + 3) 17 | | "C Z" -> (p1 + 3 + 3, p2 + 1 + 6) 18 | | _ -> (p1, p2) 19 | 20 | let solve fileName = 21 | fileName 22 | |> seqOfLines 23 | |> Seq.fold folder (0, 0) 24 | 25 | [] 26 | [] 27 | [] 28 | let test02 fn ep1 ep2 = 29 | let (ap1, ap2) = solve fn 30 | Assert.Equal(ep1, ap1) 31 | Assert.Equal(ep2, ap2) -------------------------------------------------------------------------------- /2019/go/02_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/stretchr/testify/assert" 5 | "testing" 6 | ) 7 | 8 | func Test02(t *testing.T) { 9 | assert.Equal(t, 10566835, tryNounAndVerb(12, 2), "02 01") 10 | assert.Equal(t, 2347, findNounAndVerbToLand(), "02 02") 11 | } 12 | 13 | func tryNounAndVerb(noun int, verb int) int { 14 | p := fetchNumbersWS("02", ",") 15 | p[1], p[2] = noun, verb 16 | for ip := 0; ; ip = ip + 4 { 17 | opCode := p[ip] 18 | if opCode == 1 { 19 | p[p[ip+3]] = p[p[ip+1]] + p[p[ip+2]] 20 | } else if opCode == 2 { 21 | p[p[ip+3]] = p[p[ip+1]] * p[p[ip+2]] 22 | } else if opCode == 99 { 23 | return p[0] 24 | } else { 25 | return 0 26 | } 27 | } 28 | } 29 | 30 | func findNounAndVerbToLand() int { 31 | for n := 13; n <= 99; n++ { 32 | for v := 0; v <= 99; v++ { 33 | if tryNounAndVerb(n, v) == 19690720 { 34 | return n*100 + v 35 | } 36 | } 37 | } 38 | return 0 39 | } 40 | -------------------------------------------------------------------------------- /2022/fs/Common.fs: -------------------------------------------------------------------------------- 1 | module Common 2 | 3 | open System.IO 4 | 5 | let basePath = 6 | @"D:\Ajay\Projects\adventofcode\2022\inputs" 7 | 8 | let seqOfLinesWEE fileName = 9 | seq { 10 | yield! Path.Combine(basePath, $"{fileName}.txt") 11 | |> File.ReadLines 12 | yield ""; 13 | } 14 | 15 | let seqOfLines fileName = 16 | Path.Combine(basePath, $"{fileName}.txt") 17 | |> File.ReadLines 18 | 19 | let (|Integer|_|) (l : string) = 20 | match System.Int32.TryParse l with 21 | | (true, number) -> Some number 22 | | (false, _) -> None 23 | 24 | let readFile fileName = 25 | Path.Combine(basePath, $"{fileName}.txt") 26 | |> File.ReadAllText 27 | |> fun t -> t.Replace("\r", "") 28 | 29 | let splitFile (splitBy: string) fileName = 30 | fileName 31 | |> readFile 32 | |> fun s -> s.Split(splitBy) 33 | 34 | let repeat f times = 35 | [1..times] 36 | |> Seq.iter (fun _ -> f()) -------------------------------------------------------------------------------- /2017/src/05.ts: -------------------------------------------------------------------------------- 1 | import * as inputSets from "./05-input"; 2 | import { assert } from "./util"; 3 | 4 | const parseInput = input => input.split("\n").map(n => +n); 5 | const findStepsToExit = (input, incrementor = _ => 1) => { 6 | let steps = 0; 7 | let index = 0; 8 | while (0 <= index && index < input.length) { 9 | const nextIndex = index + input[index]; 10 | input[index] = input[index] + incrementor(input[index]); 11 | index = nextIndex; 12 | steps = steps + 1; 13 | } 14 | return steps; 15 | }; 16 | const strangeIncrementor = offset => offset >= 3 ? -1 : 1; 17 | assert(findStepsToExit(parseInput(inputSets.ip0501)), 5, "05.1, Test 01"); 18 | assert(findStepsToExit(parseInput(inputSets.ip0502)), 394829, "05.1"); 19 | assert(findStepsToExit(parseInput(inputSets.ip0501), strangeIncrementor), 10, "05.2, Test 01"); 20 | assert(findStepsToExit(parseInput(inputSets.ip0502), strangeIncrementor), 31150702, "05.2"); 21 | -------------------------------------------------------------------------------- /2022/ts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "advent-of-code-2022", 3 | "version": "1.0.0", 4 | "description": "Advent of code 2022 solutions with typescript", 5 | "main": "index.js", 6 | "author": "Ajay Bhosale", 7 | "license": "MIT", 8 | "scripts": { 9 | "test": "jest --env=node --colors --detectOpenHandles", 10 | "ts": "ts-node", 11 | "lint": "prettier --write **/**.ts & eslint *.ts" 12 | }, 13 | "devDependencies": { 14 | "@types/jest": "^29.2.3", 15 | "@types/node": "^18.11.10", 16 | "@typescript-eslint/eslint-plugin": "^5.45.0", 17 | "@typescript-eslint/parser": "^5.45.0", 18 | "dotless": "^1.2.0", 19 | "eslint": "^8.28.0", 20 | "eslint-config-prettier": "^8.5.0", 21 | "jest": "^29.3.1", 22 | "prettier": "^2.8.0", 23 | "ts-jest": "^29.0.3", 24 | "ts-node": "^10.9.1", 25 | "typescript": "^4.9.3" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /2023/ts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "advent-of-code-2033", 3 | "version": "1.0.0", 4 | "description": "Advent of code 2033 solutions with typescript", 5 | "main": "index.js", 6 | "author": "Ajay Bhosale", 7 | "license": "MIT", 8 | "scripts": { 9 | "test": "jest --env=node --colors --detectOpenHandles", 10 | "ts": "ts-node", 11 | "lint": "prettier --write **/**.ts & eslint *.ts" 12 | }, 13 | "devDependencies": { 14 | "@types/jest": "^29.5.11", 15 | "@types/node": "^20.10.3", 16 | "@typescript-eslint/eslint-plugin": "^6.13.2", 17 | "@typescript-eslint/parser": "^6.13.2", 18 | "dotless": "^1.2.0", 19 | "eslint": "^8.55.0", 20 | "eslint-config-prettier": "^9.1.0", 21 | "jest": "^29.7.0", 22 | "prettier": "^3.1.0", 23 | "ts-jest": "^29.1.1", 24 | "ts-node": "^10.9.1", 25 | "typescript": "^5.3.2" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /2022/fs/D10.fs: -------------------------------------------------------------------------------- 1 | module D10 2 | 3 | open Common 4 | open Xunit 5 | 6 | type State = int * int * int * int * string 7 | 8 | let cycleSeq (l: string) = 9 | [ 10 | 0 11 | if l.StartsWith("a") then int l[4..] 12 | ] 13 | 14 | let printPixel crt x p = 15 | crt + 16 | (if x - 1 <= p && p <= x + 1 then "#" else " ") + 17 | (if p = 39 then "\n" else "") 18 | 19 | let cycle ((c, i, x, p, crt) : State) v : State = 20 | c + 1, 21 | (if (c - 19) % 40 = 0 then i + ((c + 1) * x) else i), 22 | x + v, 23 | (p + 1) % 40, 24 | printPixel crt x p 25 | 26 | let solve fn = 27 | let (_, i, _, _, crt) = 28 | fn 29 | |> seqOfLines 30 | |> Seq.collect cycleSeq 31 | |> Seq.fold cycle (0, 0, 1, 0, "") 32 | i, crt 33 | 34 | [] 35 | [] 36 | [] 37 | let test10 fn ep1 = 38 | let ap1, _ = solve fn 39 | Assert.Equal(ep1, ap1) 40 | -------------------------------------------------------------------------------- /2017/src/15.ts: -------------------------------------------------------------------------------- 1 | import { assert } from "./util"; 2 | 3 | const generator = (seed, factor, multipleOf) => { 4 | let sequence = seed; 5 | return () => { 6 | do { 7 | sequence = (sequence * factor) % 2147483647; 8 | } while (sequence & multipleOf); 9 | return sequence & 0xFFFF; 10 | }; 11 | }; 12 | 13 | const countMatches = (seedA, seedB, wait = 40000000, mulA = 0, mulB = 0) => { 14 | const genA = generator(seedA, 16807, mulA); 15 | const genB = generator(seedB, 48271, mulB); 16 | let matches = 0; 17 | for (let i = 0; i < wait; i++) { 18 | if (genA() === genB()) { 19 | matches = matches + 1; 20 | } 21 | } 22 | return matches; 23 | }; 24 | 25 | const count = countMatches(873, 583); 26 | // instead of checking x % 4 or x % 8, x & 3 or x & 7 27 | const countPicky = countMatches(873, 583, 5000000, 3, 7); 28 | assert(count, 631, "15.1"); 29 | assert(countPicky, 279, "15.2"); 30 | -------------------------------------------------------------------------------- /2018/elixir/05.exs: -------------------------------------------------------------------------------- 1 | get_content = fn path -> 2 | with {:ok, file} = File.open(path), 3 | content = IO.read(file, :all), 4 | :ok = File.close(file) do 5 | content 6 | end 7 | end 8 | 9 | parse = fn s -> 10 | s 11 | |> to_charlist() 12 | end 13 | 14 | reduce_polymer = fn units, ignore -> 15 | units 16 | |> Enum.reduce([], fn 17 | u, acc when u == ignore or u == ignore + 32 -> acc 18 | u, [un | rest] when abs(u - un) == 32 -> rest 19 | u, acc -> [u | acc] 20 | end) 21 | |> Enum.count() 22 | end 23 | 24 | optimal_solution = fn units -> 25 | Enum.to_list(65..90) 26 | |> Enum.map(&(reduce_polymer.(units, &1))) 27 | |> Enum.min() 28 | end 29 | 30 | test_01 = parse.("dabAcCaCBAcCcaDA") 31 | 10 = reduce_polymer.(test_01, 0) 32 | 4 = optimal_solution.(test_01) 33 | puzzle_input = parse.(get_content.("../inputs/05.txt")) 34 | 9808 = reduce_polymer.(puzzle_input, 0) 35 | 6484 = optimal_solution.(puzzle_input) 36 | 37 | IO.puts("Done") 38 | -------------------------------------------------------------------------------- /2015/25.js: -------------------------------------------------------------------------------- 1 | var row = 3010; 2 | var column = 3019; 3 | var numberInFirstCell = 20151125; 4 | var multiplyBy = 252533; 5 | var divideBy = 33554393; 6 | 7 | function sumOf(number) { 8 | return number * (number + 1) / 2; 9 | } 10 | 11 | function getCellPosition(row, column) { 12 | return sumOf(column + row - 1) - row + 1; 13 | } 14 | 15 | function mPowereModn(m, e, n) { 16 | var result = 1 17 | while (e > 0) { 18 | if ((e & 1) != 0) { 19 | result = (result * m) % n; 20 | } 21 | m = (m * m) % n; 22 | e = e >> 1; 23 | } 24 | return result; 25 | } 26 | 27 | function getNumber(row, column) { 28 | var exp = getCellPosition(row, column) - 1; 29 | return (mPowereModn(multiplyBy, exp, divideBy) * numberInFirstCell) % divideBy; 30 | } 31 | 32 | //console.log(getNumber(2, 3) == 16929656); 33 | //console.log(getNumber(6, 5) == 1534922); 34 | //console.log(getNumber(4, 4) == 9380097); 35 | console.log(getNumber(row, column)); -------------------------------------------------------------------------------- /2022/ts/D04.test.ts: -------------------------------------------------------------------------------- 1 | import { mapLine } from './util'; 2 | import { matchesToArray } from 'dotless'; 3 | 4 | type Pairs = [number, number, number, number]; 5 | const exp = /\d+/g; 6 | const parseLine = (l: string) => matchesToArray(l, exp, m => +m[0]) as Pairs; 7 | const parse = (fn: string) => mapLine(fn, parseLine); 8 | 9 | const isFullyContain = ([s1, e1, s2, e2]: Pairs) => 10 | (s1 <= s2 && e2 <= e1) || (s2 <= s1 && e1 <= e2); 11 | 12 | const isOverLap = ([s1, e1, s2, e2]: Pairs) => 13 | (s1 <= s2 && s2 <= e1) || (s2 <= s1 && s1 <= e2); 14 | 15 | const solve = (ip: string) => 16 | parse(ip).reduce( 17 | ([p1, p2], pairs) => [ 18 | p1 + (isFullyContain(pairs) ? 1 : 0), 19 | p2 + (isOverLap(pairs) ? 1 : 0), 20 | ], 21 | [0, 0] 22 | ); 23 | 24 | test('04', () => { 25 | const t = solve('04-test'); 26 | const a = solve('04'); 27 | expect(t).toEqual([2, 4]); 28 | expect(a).toEqual([453, 919]); 29 | }); 30 | -------------------------------------------------------------------------------- /2020/inputs/10.txt: -------------------------------------------------------------------------------- 1 | 59 2 | 134 3 | 159 4 | 125 5 | 95 6 | 92 7 | 169 8 | 43 9 | 154 10 | 46 11 | 110 12 | 79 13 | 117 14 | 151 15 | 141 16 | 56 17 | 87 18 | 10 19 | 65 20 | 170 21 | 89 22 | 32 23 | 40 24 | 118 25 | 36 26 | 94 27 | 124 28 | 173 29 | 164 30 | 166 31 | 113 32 | 67 33 | 76 34 | 102 35 | 107 36 | 52 37 | 144 38 | 119 39 | 2 40 | 72 41 | 86 42 | 73 43 | 66 44 | 13 45 | 15 46 | 38 47 | 47 48 | 109 49 | 103 50 | 128 51 | 165 52 | 148 53 | 116 54 | 146 55 | 18 56 | 135 57 | 68 58 | 83 59 | 133 60 | 171 61 | 145 62 | 48 63 | 31 64 | 106 65 | 161 66 | 6 67 | 21 68 | 22 69 | 77 70 | 172 71 | 28 72 | 78 73 | 96 74 | 55 75 | 132 76 | 39 77 | 100 78 | 108 79 | 33 80 | 23 81 | 54 82 | 157 83 | 80 84 | 153 85 | 9 86 | 62 87 | 26 88 | 147 89 | 1 90 | 27 91 | 131 92 | 88 93 | 138 94 | 93 95 | 14 96 | 123 97 | 122 98 | 158 99 | 152 100 | 71 101 | 49 102 | 101 103 | 37 104 | 99 105 | 160 106 | 53 107 | 3 -------------------------------------------------------------------------------- /2020/ts/D06.test.ts: -------------------------------------------------------------------------------- 1 | import { countBy, count } from 'dotless'; 2 | import { getLines } from './util'; 3 | 4 | const countQuestions = countBy(q => q); 5 | const checkGroup = ( 6 | [accUQ, accAllYes]: [number, number], 7 | group: string 8 | ): [number, number] => { 9 | const questions = countQuestions(group); 10 | const participants = (questions['\n'] || 0) + 1; 11 | delete questions['\n']; 12 | const uniqueQuestions = Object.keys(questions).length; 13 | const countIfAllAgrees = count(c => c === participants); 14 | const allYes = 15 | participants === 1 16 | ? uniqueQuestions 17 | : countIfAllAgrees(Object.values(questions)); 18 | return [accUQ + uniqueQuestions, accAllYes + allYes]; 19 | }; 20 | const solve = (ip: string) => getLines(ip, '\n\n').reduce(checkGroup, [0, 0]); 21 | 22 | test('06', () => { 23 | expect(solve('06-test')).toEqual([11, 6]); 24 | expect(solve('06')).toEqual([6170, 2947]); 25 | }); 26 | -------------------------------------------------------------------------------- /2021/ts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "advent-of-code-2021", 3 | "version": "1.0.0", 4 | "description": "Advent of code 2021 solutions with typescript", 5 | "main": "index.js", 6 | "author": "Ajay Bhosale", 7 | "license": "MIT", 8 | "scripts": { 9 | "test": "jest --env=node --colors --detectOpenHandles", 10 | "ts": "ts-node", 11 | "lint": "prettier --write **/**.ts & eslint *.ts" 12 | }, 13 | "devDependencies": { 14 | "@types/jest": "^27.0.3", 15 | "@types/node": "^16.11.11", 16 | "@typescript-eslint/eslint-plugin": "^5.5.0", 17 | "@typescript-eslint/parser": "^5.5.0", 18 | "eslint": "^8.3.0", 19 | "eslint-config-prettier": "^8.3.0", 20 | "jest": "^27.4.2", 21 | "prettier": "^2.5.0", 22 | "ts-jest": "^27.0.7", 23 | "ts-node": "^10.4.0", 24 | "typescript": "^4.5.2" 25 | }, 26 | "dependencies": { 27 | "dotless": "^1.2.0" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /2017/src/09.ts: -------------------------------------------------------------------------------- 1 | import * as inputSets from "./09-input"; 2 | import { assert } from "./util"; 3 | 4 | const clean = input => { 5 | let insideGarbage = false; 6 | let score = 0; 7 | let level = 1; 8 | let nonCanceled = 0; 9 | 10 | for (let i = 0; i < input.length; i++) { 11 | const char = input[i]; 12 | if (char === "!") { 13 | i = i + 1; 14 | } else if (char === ">") { 15 | insideGarbage = false; 16 | } else if (insideGarbage) { 17 | nonCanceled = nonCanceled + 1; 18 | } else if (char === "<") { 19 | insideGarbage = true; 20 | } else if (char === "{") { 21 | score = score + level; 22 | level = level + 1; 23 | } else if (char === "}") { 24 | level = level - 1; 25 | } 26 | } 27 | return [score, nonCanceled]; 28 | }; 29 | 30 | const [s, nc] = clean(inputSets.ip0901); 31 | assert(s, 10616, "09.1"); 32 | assert(nc, 5101, "09.2"); 33 | -------------------------------------------------------------------------------- /2020/ts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "advent-of-code-2020", 3 | "version": "1.0.0", 4 | "description": "Advent of code 2020 solutions with typescript", 5 | "main": "index.js", 6 | "author": "Ajay Bhosale", 7 | "license": "MIT", 8 | "scripts": { 9 | "test": "jest --env=node --colors --detectOpenHandles", 10 | "ts": "ts-node", 11 | "lint": "prettier --write **/**.ts & eslint *.ts" 12 | }, 13 | "devDependencies": { 14 | "@types/jest": "^26.0.15", 15 | "@types/node": "^14.14.10", 16 | "@typescript-eslint/eslint-plugin": "^4.9.0", 17 | "@typescript-eslint/parser": "^4.9.0", 18 | "eslint": "^7.14.0", 19 | "eslint-config-prettier": "^6.15.0", 20 | "jest": "^26.6.3", 21 | "prettier": "^2.2.1", 22 | "ts-jest": "^26.4.4", 23 | "ts-node": "^9.0.0", 24 | "typescript": "^4.1.2" 25 | }, 26 | "dependencies": { 27 | "dotless": "^1.2.0" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /2017/src/02.ts: -------------------------------------------------------------------------------- 1 | import * as inputSets from "./02-input"; 2 | import { findPairs, first, map, query, where } from "./linq"; 3 | import { assert } from "./util"; 4 | 5 | const parseInput = input => input.split("\n").map(line => line.split(/\s/g).map(n => +n)); 6 | const diffOfMaxAndMin = line => Math.max(...line) - Math.min(...line); 7 | const sum = (acc = 0, lc) => acc + lc; 8 | const aCanDivideB = (a, b) => b > a && a !== 0 && b % a === 0; 9 | const divide = ([a, b]) => b / a; 10 | const rowChecksum = line => query([line, findPairs(aCanDivideB), map(divide), first]); 11 | const calculateChecksum = (input, mapper) => parseInput(input).map(mapper).reduce(sum); 12 | 13 | assert(calculateChecksum(inputSets.ip0201, diffOfMaxAndMin), 18, "02.1, Test 01"); 14 | assert(calculateChecksum(inputSets.ip0202, diffOfMaxAndMin), 53460, "02.1"); 15 | assert(calculateChecksum(inputSets.ip0203, rowChecksum), 9, "02.2, Test 01"); 16 | assert(calculateChecksum(inputSets.ip0202, rowChecksum), 282, "02.2"); 17 | -------------------------------------------------------------------------------- /2017/src/13.ts: -------------------------------------------------------------------------------- 1 | import * as inputSets from "./13-input"; 2 | import { assert } from "./util"; 3 | 4 | const buildLayers = i => i.split("\n").map(l => l.match(/\d+/g).map(n => +n)); 5 | const layerCanCaught = delay => ([d, r]) => (delay + d) % (2 * (r - 1)) === 0; 6 | const calculateSeverity = (layers, delay = 0) => layers.filter(layerCanCaught(delay)) 7 | .reduce((s, [d, r]) => s + (d * r), 0); 8 | const passThrough = i => { 9 | const layers = buildLayers(i); 10 | const severity = calculateSeverity(layers); 11 | let bestChance = 2; 12 | while (layers.some(layerCanCaught(bestChance))) { 13 | bestChance = bestChance + 2; 14 | } 15 | return [severity, bestChance]; 16 | }; 17 | 18 | const [tSev, tbc ] = passThrough(inputSets.ip1301); 19 | const [sev, bc] = passThrough(inputSets.ip1302); 20 | 21 | assert(tSev, 24, "13.1, Test 01"); 22 | assert(sev, 1316, "13.1"); 23 | assert(tbc, 10, "13.2, Test 01"); 24 | assert(bc, 3840052, "13.2"); 25 | -------------------------------------------------------------------------------- /2021/ts/D06.test.ts: -------------------------------------------------------------------------------- 1 | import { mapLineToNumber } from './util'; 2 | 3 | const countFish = (fs: number[]) => fs.reduce((c, f) => c + f); 4 | const solve = (fn: string): [number, number] => { 5 | const dayWiseFishCount = Array(9).fill(0); 6 | const school = mapLineToNumber(fn, ','); 7 | school.forEach(f => dayWiseFishCount[f]++); 8 | let [p1, p2] = [0, 0]; 9 | for (let day = 1; day <= 256; day++) { 10 | const fishReadyToCreate = dayWiseFishCount.shift() as number; 11 | // new born 12 | dayWiseFishCount[8] = fishReadyToCreate; 13 | // adult join back to cycle 14 | dayWiseFishCount[6] = dayWiseFishCount[6] + fishReadyToCreate; 15 | if (day === 80) { 16 | p1 = countFish(dayWiseFishCount); 17 | } 18 | } 19 | p2 = countFish(dayWiseFishCount); 20 | return [p1, p2]; 21 | }; 22 | 23 | test('06', () => { 24 | expect(solve('06-test')).toEqual([5934, 26984457539]); 25 | expect(solve('06')).toEqual([351092, 1595330616005]); 26 | }); 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Advent of Code - Solutions 2 | 3 | 2015 - JavaScript and ES6 4 | 5 | 2016 - JavaScript via TypeScript and ES6 6 | - Runs only with node 7 | - Use Gulp tasks to convert .ts code to .js 8 | - TypeScript targets ES6, while Babel transforms ES6 features not supported by Node. 9 | - Exploring 2016 solutions 10 | 1. Open 2016 folder on command prompt 11 | 2. Run `npm install` 12 | 3. Open 2016 folder with Visual Studio Code 13 | 4. Press Ctrl + Shift + B, which will run the default tasks/ Or simply run `gulp` from command prompt 14 | 5. Compiled files are copied to "dist" folder 15 | 6. To test a particular day from command prompt, run `node dist\{{day}}`, for example - `node dist\01` 16 | 7. All days are written like test cases with utility method "Assert" 17 | 8. Run.ts has references to all the days and executes them excluding day 05, day 11 (Part II), day 14 (Part II), day 16 (Part II) and day 18 (part II) 18 | 9. Code heavily uses functional programming, and new ES6 features like destructuring, and tuple like syntax -------------------------------------------------------------------------------- /2023/inputs/20.txt: -------------------------------------------------------------------------------- 1 | &kv -> qb 2 | %px -> qz, tk 3 | %xk -> sv, zv 4 | %rj -> lx, qz 5 | %ks -> fc 6 | %dx -> gt, dr 7 | %lz -> qz, df 8 | %dz -> fr 9 | broadcaster -> cn, xk, rj, gf 10 | %ct -> ks 11 | %hq -> bz 12 | %qv -> cx 13 | &qz -> vk, qm, rj, kv, hq, tk 14 | &jg -> qb 15 | %cf -> sv, tz 16 | &dr -> cn, jz, tq, ks, mr, ct 17 | %mx -> bn 18 | %bv -> sk, kf 19 | %cn -> dr, mq 20 | %vk -> lz 21 | %jd -> qz 22 | &qb -> rx 23 | %tp -> sv, lm 24 | %jz -> ct 25 | %tq -> tj 26 | %bn -> sv, cf 27 | %br -> sk, hc 28 | %gt -> dr, nd 29 | %nd -> dr, nk 30 | &rz -> qb 31 | %lx -> qm, qz 32 | &sk -> qv, kf, rd, qh, jg, gf 33 | %mq -> jz, dr 34 | %rl -> bv, sk 35 | %tz -> sv, ng 36 | %df -> qz, jd 37 | %tk -> hq 38 | &mr -> qb 39 | %gf -> rl, sk 40 | %qm -> nt 41 | &sv -> xk, rz, zv, dz, mx 42 | %hc -> sk, nf 43 | %xp -> br, sk 44 | %bc -> sv, tp 45 | %fc -> dr, tq 46 | %nf -> sk 47 | %cx -> sk, qh 48 | %bz -> vk, qz 49 | %zv -> dz 50 | %kf -> rd 51 | %tj -> dr, dx 52 | %fr -> mx, sv 53 | %ng -> bc, sv 54 | %lm -> sv 55 | %nk -> dr 56 | %nt -> qz, px 57 | %qh -> xp 58 | %rd -> qv -------------------------------------------------------------------------------- /2022/fs/D06.fs: -------------------------------------------------------------------------------- 1 | module D06 2 | 3 | open Common 4 | open Xunit 5 | 6 | let findDuplicateIndex (m: string) = 7 | [m.Length - 2 .. -1 .. 0] 8 | |> Seq.tryFind (fun i -> m[i + 1 .. ].Contains(m[i])) 9 | 10 | let solve (buffer: string) size = 11 | let rec find p = 12 | if p >= buffer.Length then -1 13 | else 14 | match findDuplicateIndex buffer[p - size .. p - 1] with 15 | | None -> p 16 | | Some di -> find (p + 1 + di) 17 | find size 18 | 19 | [] 20 | [] 21 | [] 22 | [] 23 | [] 24 | [] 25 | [] 26 | let test06 (data: string) ep1 ep2 = 27 | let buffer = if data.Length = 2 then (readFile data) else data 28 | let ap1 = solve buffer 4 29 | Assert.Equal(ep1, ap1) 30 | let ap2 = solve buffer 14 31 | Assert.Equal(ep2, ap2) -------------------------------------------------------------------------------- /2018/ts/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible Node.js debug attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Debug Jest Tests", 11 | "cwd": "${workspaceFolder}", 12 | "args": [ 13 | "--inspect-brk", 14 | "${workspaceRoot}/node_modules/.bin/jest", 15 | "--runInBand", 16 | "--config", 17 | "${workspaceRoot}/jest.config.js" 18 | ], 19 | "windows": { 20 | "args": [ 21 | "--inspect-brk", 22 | "${workspaceRoot}/node_modules/jest/bin/jest.js", 23 | "--runInBand", 24 | "--config", 25 | "${workspaceRoot}/jest.config.js" 26 | ], 27 | }, 28 | "console": "integratedTerminal", 29 | "internalConsoleOptions": "neverOpen" 30 | }, 31 | ] 32 | } -------------------------------------------------------------------------------- /2023/fs/D04.fs: -------------------------------------------------------------------------------- 1 | module D04 2 | 3 | open System 4 | open Common 5 | open Xunit 6 | open System.Linq 7 | 8 | let parse (line: string) = 9 | line[line.IndexOf(":") + 1 ..] 10 | |> splitByString "|" 11 | |> Seq.map (fun l -> splitByString " " l |> Seq.ofArray) 12 | |> Seq.reduce (fun a b -> a.Intersect b) 13 | |> Seq.length 14 | 15 | let power m = 16 | if m > 0 then Math.Pow(2, float (m - 1)) else 0 17 | 18 | let updateCount (cards: int array) i m = 19 | [ 1..m ] |> Seq.iter (fun ci -> cards.[i + ci] <- cards.[i + ci] + cards.[i]) 20 | 21 | let solve fn = 22 | let matches = fn |> seqOfLines |> Seq.map parse 23 | let cardCount = matches |> Seq.length 24 | let p1 = matches |> Seq.sumBy power 25 | let cards = Array.init cardCount (fun _ -> 1) 26 | matches |> Seq.iteri (updateCount cards) 27 | let p2 = cards |> Array.sum 28 | (p1, p2) 29 | 30 | [] 31 | [] 32 | [] 33 | let test04 fn ep1 ep2 = 34 | let (ap1, ap2) = solve fn 35 | Assert.Equal(ep1, ap1) 36 | Assert.Equal(ep2, ap2) 37 | -------------------------------------------------------------------------------- /2020/ts/D03.test.ts: -------------------------------------------------------------------------------- 1 | import { getLines } from './util'; 2 | 3 | const TREE = '#'; 4 | const slopes = [ 5 | [1, 1], 6 | [3, 1], 7 | [5, 1], 8 | [7, 1], 9 | [1, 2], 10 | ]; 11 | 12 | const countTrees = (area: string[], right = 3, down = 1) => { 13 | const patternLength = area[0].length; 14 | let col = 0; 15 | let count = 0; 16 | for (let row = 0; row < area.length; row = row + down) { 17 | if (area[row][col] === TREE) { 18 | count++; 19 | } 20 | col = (col + right) % patternLength; 21 | } 22 | return count; 23 | }; 24 | 25 | const productOfSlopes = (input: string[]) => 26 | slopes.reduce( 27 | (product, [right, down]) => product * countTrees(input, right, down), 28 | 1 29 | ); 30 | 31 | test('03', () => { 32 | const testInput = getLines('03-test'); 33 | const input = getLines('03'); 34 | expect(countTrees(testInput)).toEqual(7); 35 | expect(countTrees(input)).toEqual(173); 36 | expect(productOfSlopes(testInput)).toEqual(336); 37 | expect(productOfSlopes(input)).toEqual(4385176320); 38 | }); 39 | -------------------------------------------------------------------------------- /2020/ts/D15.test.ts: -------------------------------------------------------------------------------- 1 | const play = (ip: string, times = 2020) => { 2 | const numbers = ip.split(',').map(n => +n); 3 | const memory = new Map(); 4 | numbers.forEach((n, i) => memory.set(n, i + 1)); 5 | let current = 0; 6 | for (let turn = numbers.length + 1; turn < times; turn++) { 7 | if (memory.has(current)) { 8 | const lt = memory.get(current) as number; 9 | memory.set(current, turn); 10 | current = turn - lt; 11 | } else { 12 | memory.set(current, turn); 13 | current = 0; 14 | } 15 | } 16 | return current; 17 | }; 18 | 19 | test('15', () => { 20 | expect(play('0,3,6')).toEqual(436); 21 | // expect(play('1,3,2')).toEqual(1); 22 | // expect(play('2,1,3')).toEqual(10); 23 | // expect(play('1,2,3')).toEqual(27); 24 | // expect(play('2,3,1')).toEqual(78); 25 | // expect(play('3,2,1')).toEqual(438); 26 | // expect(play('3,1,2')).toEqual(1836); 27 | expect(play('10,16,6,0,1,17')).toEqual(412); 28 | // expect(play('10,16,6,0,1,17', 30000000)).toEqual(243); 29 | }); 30 | -------------------------------------------------------------------------------- /2023/ts/D09.test.ts: -------------------------------------------------------------------------------- 1 | import { mapLine, toNumber } from './util'; 2 | 3 | const getDiff = ( 4 | acc: number[], 5 | c: number, 6 | i: number, 7 | arr: number[], 8 | ): number[] => { 9 | if (i === 0) { 10 | return acc; 11 | } 12 | acc.push(c - arr[i - 1]); 13 | return acc; 14 | }; 15 | 16 | const predictValue = (history: number[]) => { 17 | const seq: number[][] = []; 18 | let current = history; 19 | while (current.length > 1) { 20 | seq.push(current); 21 | current = current.reduce(getDiff, []); 22 | if (current.every(c => c === 0)) { 23 | break; 24 | } 25 | } 26 | return seq.reduceRight(([f, p], hd) => [hd.at(-1)! + f, hd[0] - p], [0, 0]); 27 | }; 28 | 29 | const solve = (fn: string) => { 30 | const historyLines = mapLine(fn, l => l.split(' ').map(toNumber)); 31 | return historyLines 32 | .map(predictValue) 33 | .reduce((a, b) => [a[0] + b[0], a[1] + b[1]]); 34 | }; 35 | 36 | test('09', () => { 37 | expect(solve('09-t1')).toEqual([114, 2]); 38 | expect(solve('09')).toEqual([2008960228, 1097]); 39 | }); 40 | -------------------------------------------------------------------------------- /2019/ts/D08.test.ts: -------------------------------------------------------------------------------- 1 | import { getInput } from './util'; 2 | import { countBy } from 'dotless'; 3 | 4 | const [B, W, T] = ['0', '1', '2']; 5 | // prettier-ignore 6 | const puzzleInput = (getInput('08').match(/.{1,150}/g) as RegExpMatchArray).map(l => l.split('')); 7 | 8 | const checkImageValidity = () => { 9 | const layerWithFewest0 = puzzleInput 10 | .map(countBy()) 11 | .reduce((acc, l) => (l[B] < acc[B] ? l : acc)); 12 | return layerWithFewest0[W] * layerWithFewest0[T]; 13 | }; 14 | 15 | const displayMessage = () => { 16 | const finalLayer = puzzleInput[0]; 17 | for (let li = 1; li < puzzleInput.length; li++) { 18 | const current = puzzleInput[li]; 19 | for (let pi = 0; pi < current.length; pi++) { 20 | if (finalLayer[pi] === T && current[pi] !== T) { 21 | finalLayer[pi] = current[pi]; 22 | } 23 | } 24 | } 25 | const m = finalLayer.join('').match(/.{1,25}/g) as RegExpMatchArray; 26 | // prettier-ignore 27 | console.log(m.join('\n').replace(/0/g, ' ').replace(/1/g, '|')); 28 | }; 29 | 30 | test('08 Part 1', () => { 31 | expect(checkImageValidity()).toEqual(2684); 32 | displayMessage(); 33 | }); 34 | -------------------------------------------------------------------------------- /2017/src/17.ts: -------------------------------------------------------------------------------- 1 | import { assert, LinkedList } from "./util"; 2 | 3 | const nextPosition = (p, s, i) => ((p + s) % i) + 1; 4 | const findShortCircuitValue = steps => { 5 | const spinlock = [0]; 6 | let position = 0; 7 | for (let i = 0; i <= 2017; i++) { 8 | const item = i + 1; 9 | position = nextPosition(position, steps, item); 10 | spinlock.splice(position, 0, item); 11 | } 12 | return spinlock[spinlock.indexOf(2017) + 1]; 13 | }; 14 | const findValueAfterZero = steps => { 15 | let nextToZero = 0; 16 | let position = 0; 17 | for (let i = 0; i <= 50000000; i++) { 18 | const item = i + 1; 19 | position = nextPosition(position, steps, item); 20 | if ((position - 1) === 0) { 21 | nextToZero = item; 22 | } 23 | } 24 | return nextToZero; 25 | }; 26 | 27 | const testSteps = 3; 28 | const puzzleSteps = 356; 29 | const a = findShortCircuitValue(testSteps); 30 | const b = findShortCircuitValue(puzzleSteps); 31 | const c = findValueAfterZero(puzzleSteps); 32 | 33 | assert(a, 638, "17.1, Test 01"); 34 | assert(b, 808, "17.1"); 35 | assert(c, 47465686, "17.2"); 36 | -------------------------------------------------------------------------------- /2019/ts/D02.test.ts: -------------------------------------------------------------------------------- 1 | import { getInput } from './util'; 2 | 3 | const parse = (s: string) => s.split(',').map(n => +n); 4 | const puzzleInput = getInput('02'); 5 | 6 | const tryNounAndVerb = (data: string, noun: number, verb: number) => { 7 | const p = parse(data); 8 | p[1] = noun; 9 | p[2] = verb; 10 | for (let ip = 0; ; ip = ip + 4) { 11 | const opCode = p[ip]; 12 | if (opCode === 1) { 13 | p[p[ip + 3]] = p[p[ip + 1]] + p[p[ip + 2]]; 14 | } else if (opCode === 2) { 15 | p[p[ip + 3]] = p[p[ip + 1]] * p[p[ip + 2]]; 16 | } else if (opCode === 99) { 17 | return p[0]; 18 | } else { 19 | return 0; 20 | } 21 | } 22 | }; 23 | 24 | const findNounAndVerbToLand = () => { 25 | for (let n = 13; n <= 99; n++) { 26 | for (let v = 0; v <= 99; v++) { 27 | if (tryNounAndVerb(puzzleInput, n, v) === 19690720) { 28 | return n * 100 + v; 29 | } 30 | } 31 | } 32 | return 0; 33 | }; 34 | 35 | test('02, Part 1', () => { 36 | expect(tryNounAndVerb(puzzleInput, 12, 2)).toEqual(10566835); 37 | }); 38 | 39 | test('02, Part 2', () => { 40 | expect(findNounAndVerbToLand()).toEqual(2347); 41 | }); 42 | -------------------------------------------------------------------------------- /2023/fs/Common.fs: -------------------------------------------------------------------------------- 1 | module Common 2 | 3 | open System 4 | open System.IO 5 | 6 | let basePath = @"D:\Ajay\Projects\adventofcode\2023\inputs" 7 | 8 | let seqOfLinesWEE fileName = 9 | seq { 10 | yield! Path.Combine(basePath, $"{fileName}.txt") |> File.ReadLines 11 | yield "" 12 | } 13 | 14 | let seqOfLines fileName = 15 | Path.Combine(basePath, $"{fileName}.txt") |> File.ReadLines 16 | 17 | let (|Integer|_|) (l: string) = 18 | match Int32.TryParse l with 19 | | (true, number) -> Some number 20 | | (false, _) -> None 21 | 22 | let readFile fileName = 23 | Path.Combine(basePath, $"{fileName}.txt") 24 | |> File.ReadAllText 25 | |> fun t -> t.Replace("\r", "") 26 | 27 | let splitFile (splitBy: string) fileName = 28 | fileName |> readFile |> (fun s -> s.Split(splitBy)) 29 | 30 | let repeat f times = 31 | [ 1..times ] |> Seq.iter (fun _ -> f ()) 32 | 33 | let splitByCharArray (seperator: char array) (line: string) = 34 | line.Split(seperator, StringSplitOptions.RemoveEmptyEntries) 35 | 36 | let splitByString (seperator: string) (line: string) = 37 | line.Split(seperator, StringSplitOptions.RemoveEmptyEntries) 38 | -------------------------------------------------------------------------------- /2021/fs/D06.fs: -------------------------------------------------------------------------------- 1 | module D06 2 | 3 | open Common 4 | open Xunit 5 | 6 | let countFishByDay (dw: int64[]) (f:int) = 7 | dw[f] <- dw[f] + 1L 8 | dw 9 | 10 | let getSea (fn: string) = 11 | fn 12 | |> readText 13 | |> (fun s -> s.Split ',') 14 | |> Array.map int 15 | |> Array.fold countFishByDay (Array.create 9 0L) 16 | 17 | let simulate (dw: int64[]) (days: int) = 18 | for i in 1 .. days do 19 | let adultsReady = dw[0] 20 | dw[0] <- dw[1] 21 | dw[1] <- dw[2] 22 | dw[2] <- dw[3] 23 | dw[3] <- dw[4] 24 | dw[4] <- dw[5] 25 | dw[5] <- dw[6] 26 | dw[6] <- dw[7] + adultsReady 27 | dw[7] <- dw[8] 28 | dw[8] <- adultsReady 29 | 30 | let solve fn = 31 | let sea = getSea fn 32 | simulate sea 80 33 | let p1 = Array.sum sea 34 | simulate sea (256 - 80) 35 | let p2 = Array.sum sea 36 | (p1, p2) 37 | 38 | [] 39 | [] 40 | [] 41 | let test fn (ep1: int64) (ep2:int64) = 42 | let (ap1, ap2) = solve fn 43 | Assert.Equal(ep1, ap1) 44 | Assert.Equal(ep2, ap2) 45 | -------------------------------------------------------------------------------- /2015/10.js: -------------------------------------------------------------------------------- 1 | function* takeDuplicates(source) { 2 | var currentLocation = 0; 3 | var sourceLength = source.Length; 4 | var result = []; 5 | while (currentLocation < source.length) { 6 | var item = source[currentLocation]; 7 | result.push(item); 8 | currentLocation = currentLocation + 1; 9 | if (currentLocation == sourceLength || item != source[currentLocation]) { 10 | yield result; 11 | result = []; 12 | } 13 | } 14 | } 15 | 16 | function lookAndSay(source) { 17 | var result = []; 18 | for (var dc of takeDuplicates(source.split(""))) { 19 | result.push(dc.length); 20 | result.push(dc[0]); 21 | } 22 | return result.join(""); 23 | } 24 | 25 | function repeatLookAndSay(input, times) { 26 | var result = input; 27 | for (var counter = 0; counter < times; counter++) { 28 | result = lookAndSay(result); 29 | } 30 | return result; 31 | } 32 | 33 | //360154 34 | var after40Times = repeatLookAndSay("1113122113", 40); 35 | console.log(after40Times.length); 36 | //5103798 37 | var after50Times = repeatLookAndSay(after40Times, 10); 38 | console.log(after50Times.length); -------------------------------------------------------------------------------- /2019/inputs/07.txt: -------------------------------------------------------------------------------- 1 | 3,8,1001,8,10,8,105,1,0,0,21,30,39,64,81,102,183,264,345,426,99999,3,9,1001,9,2,9,4,9,99,3,9,1002,9,4,9,4,9,99,3,9,1002,9,5,9,101,2,9,9,102,3,9,9,1001,9,2,9,1002,9,2,9,4,9,99,3,9,1002,9,3,9,1001,9,5,9,1002,9,3,9,4,9,99,3,9,102,4,9,9,1001,9,3,9,102,4,9,9,1001,9,5,9,4,9,99,3,9,101,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,1,9,4,9,99,3,9,1002,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,99,3,9,101,1,9,9,4,9,3,9,101,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,1,9,9,4,9,99,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,101,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,101,1,9,9,4,9,99 -------------------------------------------------------------------------------- /2018/inputs/15.txt: -------------------------------------------------------------------------------- 1 | ################################ 2 | ####################..#..####### 3 | ####################.......##### 4 | ####################..##...###.# 5 | ####################...........# 6 | ###########G.....###..##.......# 7 | ############..##.G###....G.....# 8 | ############G..#..###.........## 9 | ##########..G..#.####.#G.......# 10 | ##########.#.....####..........# 11 | ##########.G.......#....E...#### 12 | ##########GG................#### 13 | ########..G..G#####..........### 14 | ######.......#######.....#.##### 15 | #####GG..G..#########....#..#### 16 | #####.......#########.......#### 17 | ####....G...#########...###.#### 18 | ####...G....#########..E###.#### 19 | ##....G.....#########.G.##..#..# 20 | #.....#......#######E..##......# 21 | ##...###......#####...###......# 22 | ####..................#.....E### 23 | ####.######..G......#.......#### 24 | #######.........E.....###...#### 25 | #######..............E####.##### 26 | ##########..G........########### 27 | ##########............########## 28 | ###########..E....#.E.########## 29 | #########...............######## 30 | #########..E......##.....####### 31 | #########.#####.E.###.....###### 32 | ################################ -------------------------------------------------------------------------------- /2018/inputs/15-test7.txt: -------------------------------------------------------------------------------- 1 | ################################ 2 | #################.....########## 3 | #################..#.########### 4 | #################.........###### 5 | ##################......######## 6 | #################G.GG########### 7 | ###############...#..########### 8 | ###############......G..######## 9 | ############..G.........######## 10 | ##########.G.....G......######## 11 | ##########......#.........#..### 12 | ##########...................### 13 | #########G..G.#####....E.G.E..## 14 | ######..G....#######...........# 15 | #######.....#########.........## 16 | #######..#..#########.....#.#### 17 | ##########..#########..G.##..### 18 | ###########G#########...E...E.## 19 | #########.G.#########..........# 20 | #########GG..#######.......##.E# 21 | ######.G......#####...########## 22 | #...##..G..............######### 23 | #...#...........###..E.######### 24 | #.G.............###...########## 25 | #................############### 26 | ##.........E.....############### 27 | ###.#..............############# 28 | ###..G........E.....############ 29 | ###......E..........############ 30 | ###......#....#E#...############ 31 | ###....####.#...##.############# 32 | ################################ -------------------------------------------------------------------------------- /2018/inputs/15-test9.txt: -------------------------------------------------------------------------------- 1 | ################################ 2 | ###########################..### 3 | ##########################...### 4 | #########################..##### 5 | ####...##################.###### 6 | #####..################...#.#### 7 | #..G...G#########.####G.....#### 8 | #.......########.....G.......### 9 | #.....G....###G....#....E.....## 10 | ####...##......##.............## 11 | ####G...#.G...###.G...........## 12 | ####G.......................#### 13 | ####.........G#####.........#### 14 | ####...GG#...#######.......##### 15 | ###.........#########G....###### 16 | ###.G.......#########G...####### 17 | ###.G.......#########......##### 18 | ####.....G..#########....E..#### 19 | #####.......#########..E....#### 20 | ######...##G.#######........#### 21 | ######.#.#.G..#####.....##..#### 22 | ########....E...........##..#### 23 | ########....E#######........#### 24 | ########......######E....##..E.# 25 | ########......#####.....#......# 26 | ########.....######............# 27 | ##################...#.E...E...# 28 | ##################.............# 29 | ###################.......E##### 30 | ####################....#...#### 31 | ####################.########### 32 | ################################ -------------------------------------------------------------------------------- /2018/elixir/08.exs: -------------------------------------------------------------------------------- 1 | get_nodes = fn path -> 2 | with {:ok, file} = File.open(path), 3 | content = IO.read(file, :all), 4 | :ok = File.close(file) do 5 | content 6 | |> String.split(" ") 7 | |> Enum.map(&String.to_integer/1) 8 | end 9 | end 10 | 11 | defmodule D08 do 12 | def traverse_nodes([0, mc | rest]) do 13 | with s = rest |> Enum.take(mc) |> Enum.sum() do 14 | [Enum.drop(rest, mc), s, s] 15 | end 16 | end 17 | def traverse_nodes([cc, mc | rest]) do 18 | with [rest, sum_cm, child_vns] = 1..cc |> Enum.reduce([rest, 0, []], fn _, [r, sum_cm, child_vns] -> 19 | [r, cm, vn] = traverse_nodes(r) 20 | [r, sum_cm + cm, child_vns ++ [vn]] 21 | end), 22 | meta = Enum.take(rest, mc) 23 | do 24 | [ 25 | Enum.drop(rest, mc), 26 | sum_cm + Enum.sum(meta), 27 | Enum.reduce(meta, 0, fn m, vn -> 28 | vn + if m > cc, do: 0, else: Enum.at(child_vns, m - 1) 29 | end) 30 | ] 31 | end 32 | end 33 | end 34 | 35 | [[], 138, 66] = D08.traverse_nodes(get_nodes.("../inputs/08-test.txt")) 36 | [[], 36307, 25154] = D08.traverse_nodes(get_nodes.("../inputs/08.txt")) 37 | 38 | IO.puts("Done") 39 | -------------------------------------------------------------------------------- /2021/fs/aoc-2021.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.31919.166 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "aoc-2021", "aoc-2021.fsproj", "{E37ED979-98D7-4A4B-B961-4F0C99C26B93}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {E37ED979-98D7-4A4B-B961-4F0C99C26B93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {E37ED979-98D7-4A4B-B961-4F0C99C26B93}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {E37ED979-98D7-4A4B-B961-4F0C99C26B93}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {E37ED979-98D7-4A4B-B961-4F0C99C26B93}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {F87142EB-B678-4377-B92F-257E8C190F5C} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /2022/fs/aoc-2022.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.31919.166 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "aoc-2022", "aoc-2022.fsproj", "{E37ED979-98D7-4A4B-B961-4F0C99C26B93}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {E37ED979-98D7-4A4B-B961-4F0C99C26B93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {E37ED979-98D7-4A4B-B961-4F0C99C26B93}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {E37ED979-98D7-4A4B-B961-4F0C99C26B93}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {E37ED979-98D7-4A4B-B961-4F0C99C26B93}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {F87142EB-B678-4377-B92F-257E8C190F5C} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /2023/fs/aoc-2023.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.31919.166 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "aoc-2023", "aoc-2023.fsproj", "{E37ED979-98D7-4A4B-B961-4F0C99C26B93}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {E37ED979-98D7-4A4B-B961-4F0C99C26B93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {E37ED979-98D7-4A4B-B961-4F0C99C26B93}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {E37ED979-98D7-4A4B-B961-4F0C99C26B93}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {E37ED979-98D7-4A4B-B961-4F0C99C26B93}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {F87142EB-B678-4377-B92F-257E8C190F5C} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /2023/ts/D14.P1.test.ts: -------------------------------------------------------------------------------- 1 | import { descendingBy } from 'dotless'; 2 | import { getLines } from './util'; 3 | 4 | const descending = descendingBy(); 5 | 6 | const rotate = (lines: string[]) => { 7 | const rocks: string[] = []; 8 | const verticalLength = lines.length; 9 | for (let i = 0; i < verticalLength; i++) { 10 | rocks.push(lines.reduce((acc, h) => acc + h[i], '')); 11 | } 12 | return rocks; 13 | }; 14 | 15 | const tilt = (line: string) => { 16 | return line 17 | .split('#') 18 | .map(s => s.split('').sort(descending).join('')) 19 | .join('#'); 20 | }; 21 | 22 | const calculateLoad = (line: string) => { 23 | const ll = line.length; 24 | let load = 0; 25 | for (let i = 0; i <= ll; i++) { 26 | if (line[i] === 'O') { 27 | load = load + (ll - i); 28 | } 29 | } 30 | return load; 31 | }; 32 | 33 | const sumIt = (a: number, b: number) => a + b; 34 | 35 | const solve = (fn: string) => { 36 | return rotate(getLines(fn)).map(tilt).map(calculateLoad).reduce(sumIt); 37 | }; 38 | 39 | test('14-P1', () => { 40 | expect(solve('14-t1')).toEqual(136); 41 | expect(solve('14')).toEqual(109654); 42 | }); 43 | -------------------------------------------------------------------------------- /2019/clj/test/d02.clj: -------------------------------------------------------------------------------- 1 | (ns d02 2 | (:require [clojure.test :refer [deftest testing is]])) 3 | 4 | (def input (->> "../inputs/02.txt" 5 | (slurp) 6 | (#(clojure.string/split % #",")) 7 | (map #(Integer/parseInt %)) 8 | (vec))) 9 | 10 | (defn setnounandverb 11 | [n v] 12 | (assoc (assoc input 1 n) 2 v)) 13 | 14 | (defn execute 15 | [opcode p] 16 | (let [a (nth p (nth opcode 1)) 17 | b (nth p (nth opcode 2)) 18 | l (nth opcode 3)] 19 | (case (first opcode) 20 | 1 (assoc p l (+ a b)) 21 | 2 (assoc p l (* a b))))) 22 | 23 | (defn trynounandverb 24 | [n v] 25 | (loop [i 0 p (setnounandverb n v)] 26 | (let [opcode (subvec p i)] 27 | (if (= 99 (first opcode)) 28 | (first p) 29 | (recur (+ i 4) (execute opcode p)))))) 30 | 31 | (defn findnounandverbtoland 32 | [] 33 | (first (for [n (range 13 99) v (range 0 99) 34 | :when (= 19690720 (trynounandverb n v))] 35 | (+ (* n 100) v)))) 36 | 37 | (deftest part-1 38 | (testing "Day 02 01" (is (= 10566835 (trynounandverb 12 2))))) 39 | 40 | (deftest part-2 41 | (testing "Day 02 02" (is (= 2347 (findnounandverbtoland))))) -------------------------------------------------------------------------------- /2023/ts/D04.test.ts: -------------------------------------------------------------------------------- 1 | import { mapLine } from './util'; 2 | 3 | const parseNumbers = (nl: string) => nl.split(' ').filter(l => l.length); 4 | const parseLine = (l: string): number => { 5 | const [winning, candidates] = l.split(':')[1].split('|').map(parseNumbers); 6 | let hits = 0; 7 | for (const wn of winning) { 8 | if (candidates.includes(wn)) { 9 | hits = hits + 1; 10 | } 11 | } 12 | return hits; 13 | }; 14 | 15 | const solve = (fn: string): [number, number] => { 16 | const cards = mapLine(fn, parseLine); 17 | let p1 = 0; 18 | const copies = cards.map(_ => 1); 19 | const cardCount = cards.length; 20 | for (let i = 0; i < cardCount; i++) { 21 | const matching = cards[i]; 22 | if (matching > 0) { 23 | p1 = p1 + Math.pow(2, matching - 1); 24 | } 25 | for (let ci = 1; ci <= matching; ci++) { 26 | copies[i + ci] = copies[i + ci] + copies[i]; 27 | } 28 | } 29 | const p2 = copies.reduce((acc, cc) => acc + cc); 30 | return [p1, p2]; 31 | }; 32 | 33 | test('04', () => { 34 | expect(solve('04-t1')).toEqual([13, 30]); 35 | expect(solve('04')).toEqual([24542, 8736438]); 36 | }); 37 | -------------------------------------------------------------------------------- /2018/elixir/01.exs: -------------------------------------------------------------------------------- 1 | find_resulting_frequency = fn ip -> Enum.sum(ip) end 2 | 3 | first_frequency_reaches_twice = fn ip -> 4 | ip 5 | |> Stream.cycle() 6 | |> Enum.reduce_while({0, MapSet.new([0])}, fn i, {current, seen} -> 7 | frequency = current + i 8 | if MapSet.member?(seen, frequency) do 9 | {:halt, frequency} 10 | else 11 | {:cont, {frequency, MapSet.put(seen, frequency)}} 12 | end 13 | end) 14 | end 15 | 16 | puzzle_input = with {:ok, file} = File.open("../inputs/01.txt"), 17 | content = IO.read(file, :all), 18 | :ok = File.close(file) do 19 | content 20 | |> String.split("\n") 21 | |> Enum.map(&String.to_integer/1) 22 | end 23 | 24 | 3 = find_resulting_frequency.([+1, +1, +1]) 25 | 0 = find_resulting_frequency.([+1, +1, -2]) 26 | -6 = find_resulting_frequency.([-1, -2, -3]) 27 | 466 = find_resulting_frequency.(puzzle_input) 28 | 29 | 0 = first_frequency_reaches_twice.([+1, -1]) 30 | 10 = first_frequency_reaches_twice.([+3, +3, +4, -2, -4]) 31 | 5 = first_frequency_reaches_twice.([-6, +3, +8, +5, -6]) 32 | 14 = first_frequency_reaches_twice.([+7, +7, -2, -7, -4]) 33 | 750 = first_frequency_reaches_twice.(puzzle_input) 34 | 35 | IO.puts("Done") 36 | -------------------------------------------------------------------------------- /2020/fsharp/AOC2020_Solution.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30717.126 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "AOC2020", "aoc2020-test\AOC2020.fsproj", "{972BEA70-E398-4C4F-8BCB-F32B8D937A5B}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {972BEA70-E398-4C4F-8BCB-F32B8D937A5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {972BEA70-E398-4C4F-8BCB-F32B8D937A5B}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {972BEA70-E398-4C4F-8BCB-F32B8D937A5B}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {972BEA70-E398-4C4F-8BCB-F32B8D937A5B}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {27956333-910E-4492-8002-1CE0ED69B489} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /2019/inputs/01.txt: -------------------------------------------------------------------------------- 1 | 88623 2 | 101095 3 | 149899 4 | 89383 5 | 54755 6 | 73496 7 | 115697 8 | 99839 9 | 65903 10 | 140201 11 | 95734 12 | 144728 13 | 113534 14 | 82199 15 | 98256 16 | 107126 17 | 54686 18 | 61243 19 | 54763 20 | 119048 21 | 58863 22 | 134097 23 | 84959 24 | 130490 25 | 145813 26 | 115794 27 | 130398 28 | 69864 29 | 133973 30 | 58382 31 | 75635 32 | 77153 33 | 132645 34 | 91661 35 | 126536 36 | 118977 37 | 137568 38 | 100341 39 | 142080 40 | 63342 41 | 84557 42 | 51961 43 | 61956 44 | 87922 45 | 92488 46 | 107572 47 | 51373 48 | 70148 49 | 80672 50 | 134880 51 | 105721 52 | 100138 53 | 80394 54 | 145117 55 | 50567 56 | 122606 57 | 112408 58 | 110737 59 | 111521 60 | 144309 61 | 65761 62 | 113147 63 | 58920 64 | 96623 65 | 65479 66 | 66576 67 | 94244 68 | 64493 69 | 142334 70 | 65969 71 | 99461 72 | 143656 73 | 134661 74 | 90115 75 | 122994 76 | 66994 77 | 135658 78 | 134336 79 | 102958 80 | 111410 81 | 107930 82 | 54711 83 | 101397 84 | 111350 85 | 86453 86 | 134383 87 | 134276 88 | 130342 89 | 80522 90 | 64875 91 | 68182 92 | 83400 93 | 121302 94 | 105996 95 | 123580 96 | 130373 97 | 123987 98 | 107932 99 | 78930 100 | 132068 -------------------------------------------------------------------------------- /2018/inputs/10-test.txt: -------------------------------------------------------------------------------- 1 | position=< 9, 1> velocity=< 0, 2> 2 | position=< 7, 0> velocity=<-1, 0> 3 | position=< 3, -2> velocity=<-1, 1> 4 | position=< 6, 10> velocity=<-2, -1> 5 | position=< 2, -4> velocity=< 2, 2> 6 | position=<-6, 10> velocity=< 2, -2> 7 | position=< 1, 8> velocity=< 1, -1> 8 | position=< 1, 7> velocity=< 1, 0> 9 | position=<-3, 11> velocity=< 1, -2> 10 | position=< 7, 6> velocity=<-1, -1> 11 | position=<-2, 3> velocity=< 1, 0> 12 | position=<-4, 3> velocity=< 2, 0> 13 | position=<10, -3> velocity=<-1, 1> 14 | position=< 5, 11> velocity=< 1, -2> 15 | position=< 4, 7> velocity=< 0, -1> 16 | position=< 8, -2> velocity=< 0, 1> 17 | position=<15, 0> velocity=<-2, 0> 18 | position=< 1, 6> velocity=< 1, 0> 19 | position=< 8, 9> velocity=< 0, -1> 20 | position=< 3, 3> velocity=<-1, 1> 21 | position=< 0, 5> velocity=< 0, -1> 22 | position=<-2, 2> velocity=< 2, 0> 23 | position=< 5, -2> velocity=< 1, 2> 24 | position=< 1, 4> velocity=< 2, 1> 25 | position=<-2, 7> velocity=< 2, -2> 26 | position=< 3, 6> velocity=<-1, -1> 27 | position=< 5, 0> velocity=< 1, 0> 28 | position=<-6, 0> velocity=< 2, 0> 29 | position=< 5, 9> velocity=< 1, -2> 30 | position=<14, 7> velocity=<-2, 0> 31 | position=<-3, 6> velocity=< 2, -1> -------------------------------------------------------------------------------- /2020/ts/D05.test.ts: -------------------------------------------------------------------------------- 1 | import { ascendingBy } from 'dotless'; 2 | import { mapLine } from './util'; 3 | 4 | const expression = /F|B|L|R/g; 5 | const binaryMap = { F: 0, B: 1, L: 0, R: 1 }; 6 | const toBinary = (l: string) => 7 | l.replace(expression, c => (binaryMap as any)[c]); 8 | 9 | /* 10 | const parseBoardingPass = (line: string): number => { 11 | const binary = line.replace(expression, c => (binaryMap as any)[c]); 12 | const row = parseInt(binary.substr(0, 7), 2); 13 | const col = parseInt(binary.substr(7), 2); 14 | return binary.substr(0, 7), 2 * 8 + col]; 15 | }; 16 | */ 17 | 18 | const parseBoardingPass = (l: string) => parseInt(toBinary(l), 2); 19 | 20 | const findSeat = (): [maxSeat: number, missingSeat: number] => { 21 | const seats = mapLine('05', parseBoardingPass); 22 | seats.sort(ascendingBy()); 23 | const lastSeat = seats.length - 1; 24 | let missingSeat = -1; 25 | for (let seat = 0; seat < lastSeat; seat++) { 26 | if (seats[seat + 1] - seats[seat] === 2) { 27 | missingSeat = seats[seat] + 1; 28 | break; 29 | } 30 | } 31 | return [seats[lastSeat], missingSeat]; 32 | }; 33 | 34 | test('05', () => { 35 | expect(findSeat()).toEqual([885, 623]); 36 | }); 37 | -------------------------------------------------------------------------------- /2020/ts/D25.test.ts: -------------------------------------------------------------------------------- 1 | import { assert } from 'console'; 2 | 3 | // https://stackoverflow.com/questions/5989429/pow-and-mod-function-optimization/5989549 4 | function pow(base: number, exp: number, mod: number): number { 5 | if (exp == 0) return 1; 6 | if (exp % 2 == 0) { 7 | return Math.pow(pow(base, exp / 2, mod), 2) % mod; 8 | } else { 9 | return (base * pow(base, exp - 1, mod)) % mod; 10 | } 11 | } 12 | 13 | const MAGIC_NUMBER = 20201227; 14 | const findLoopSize = (key: number, startAt: number) => { 15 | for (let i = startAt; i < 10000000; i++) { 16 | if (pow(7, i, MAGIC_NUMBER) === key) { 17 | return i; 18 | } 19 | } 20 | assert('This should not happen'); 21 | return 0; 22 | }; 23 | 24 | // Change start at if it is not working for you 25 | const solve = (cardPK: number, doorPK: number, startAt = 1500000) => { 26 | const ek1 = pow(doorPK, findLoopSize(cardPK, startAt), MAGIC_NUMBER); 27 | const ek2 = pow(cardPK, findLoopSize(doorPK, startAt), MAGIC_NUMBER); 28 | assert(ek1 === ek2); 29 | return ek1; 30 | }; 31 | 32 | test('25', () => { 33 | expect(solve(5764801, 17807724, 0)).toEqual(14897079); 34 | expect(solve(13135480, 8821721)).toEqual(8329514); 35 | }); 36 | -------------------------------------------------------------------------------- /2022/fs/D04.fs: -------------------------------------------------------------------------------- 1 | module D04 2 | 3 | open System 4 | open Common 5 | open Xunit 6 | 7 | type Pairs = 8 | { s1: int; e1: int; s2: int; e2: int} 9 | member self.isFullyContain() = 10 | (self.s1 <= self.s2 && self.e2 <= self.e1) 11 | || 12 | (self.s2 <= self.s1 && self.e1 <= self.e2) 13 | member self.isOverlap() = 14 | (self.s1 <= self.s2 && self.s2 <= self.e1) 15 | || 16 | (self.s2 <= self.s1 && self.s1 <= self.e2); 17 | 18 | let (|Pairs|_|) (l: string) = 19 | let ps = l.Split ([|","; "-"|], StringSplitOptions.None) |> Array.map int 20 | match ps with 21 | | [|s1; e1; s2; e2|] -> Some {s1 = s1; e1 = e1; s2 = s2; e2 = e2} 22 | | _ -> None 23 | 24 | let folder (sumP1, sumP2) = function 25 | | Pairs p -> ( 26 | (if p.isFullyContain() then sumP1 + 1 else sumP1), 27 | (if p.isOverlap() then sumP2 + 1 else sumP2) 28 | ) 29 | | _ -> (sumP1, sumP2) 30 | 31 | let solve fileName = 32 | fileName 33 | |> seqOfLines 34 | |> Seq.fold folder (0, 0) 35 | 36 | [] 37 | [] 38 | [] 39 | let test04 fn ep1 ep2 = 40 | let (ap1, ap2) = solve fn 41 | Assert.Equal(ep1, ap1) 42 | Assert.Equal(ep2, ap2) -------------------------------------------------------------------------------- /2017/src/12.ts: -------------------------------------------------------------------------------- 1 | import * as inputSets from "./12-input"; 2 | import { assert } from "./util"; 3 | 4 | const parse = i => i.replace(/ /g, "").split("\n").map(l => l.split("<->")).reduce((ps, [p, cs]) => { 5 | ps[p] = cs.split(","); 6 | return ps; 7 | }, {}); 8 | 9 | const connect = (ps, p, connected) => { 10 | connected.add(p); 11 | for (const con of ps[p]) { 12 | if (connected.has(con)) { 13 | continue; 14 | } 15 | connect(ps, con, connected); 16 | } 17 | return connected; 18 | }; 19 | 20 | const findGroups = ps => { 21 | const visited = new Set(); 22 | let count = 0; 23 | // tslint:disable-next-line:forin 24 | for (const p in ps) { 25 | if (!visited.has(p)) { 26 | const group = connect(ps, p, new Set()); 27 | group.forEach(v => visited.add(v)); 28 | count = count + 1; 29 | } 30 | } 31 | return count; 32 | }; 33 | 34 | const findConnections = ps => connect(ps, "0", new Set()).size; 35 | 36 | const tC = findConnections(parse(inputSets.ip1201)); 37 | const pC = findConnections(parse(inputSets.ip1202)); 38 | const gC = findGroups(parse(inputSets.ip1202)); 39 | assert(tC, 6, "12.1, Test 01"); 40 | assert(pC, 283, "12.1"); 41 | assert(gC, 195, "12.2"); 42 | -------------------------------------------------------------------------------- /2023/fs/aoc-2023.fsproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | aoc_2023 6 | false 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | runtime; build; native; contentfiles; analyzers; buildtransitive 24 | all 25 | 26 | 27 | runtime; build; native; contentfiles; analyzers; buildtransitive 28 | all 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /2021/ts/D02.test.ts: -------------------------------------------------------------------------------- 1 | import { mapLine } from './util'; 2 | 3 | type Position = [horizontal: number, dp1: number, dp2: number, aim: number]; 4 | type Command = (p: Position, unit: number) => Position; 5 | type CommandType = 'forward' | 'down' | 'up'; 6 | type CommandMap = Record; 7 | type Instruction = [command: CommandType, unit: number]; 8 | 9 | const control: CommandMap = { 10 | forward: ([h, dp1, dp2, a], u) => [h + u, dp1, dp2 + a * u, a], 11 | down: ([h, dp1, dp2, a], u) => [h, dp1 + u, dp2, a + u], 12 | up: ([h, dp1, dp2, a], u) => [h, dp1 - u, dp2, a - u], 13 | }; 14 | 15 | const lineToInstruction = (l: string): Instruction => { 16 | const parts = l.split(' '); 17 | return [parts[0], +parts[1]] as Instruction; 18 | }; 19 | 20 | const navigate = (ins: Instruction[]) => { 21 | const seed = [0, 0, 0, 0] as Position; 22 | const [h, dp1, dp2] = ins.reduce( 23 | (acc, [command, unit]) => control[command](acc, unit), 24 | seed 25 | ); 26 | return [h * dp1, h * dp2]; 27 | }; 28 | 29 | test('02', () => { 30 | const ti = mapLine('02-test', lineToInstruction); 31 | const ai = mapLine('02', lineToInstruction); 32 | expect(navigate(ti)).toEqual([150, 900]); 33 | expect(navigate(ai)).toEqual([1250395, 1451210346]); 34 | }); 35 | -------------------------------------------------------------------------------- /2022/fs/D03.fs: -------------------------------------------------------------------------------- 1 | module D03 2 | 3 | open Common 4 | open Xunit 5 | 6 | let calculatePriority (set : Set) = 7 | match set.IsEmpty with 8 | | true -> 0 9 | | _ -> 10 | let charValue = int set.MinimumElement 11 | if charValue >= 97 then charValue - 97 + 1 12 | else charValue - 65 + 1 + 26; 13 | 14 | let lineToPriority (line : string) = 15 | let size = line.Length / 2 16 | let fc = line[0 .. size - 1] |> Set.ofSeq 17 | let sc = line[size ..] |> Set.ofSeq 18 | calculatePriority (Set.intersect fc sc) 19 | 20 | let intersect a b = 21 | Set.intersect a (b |> Set.ofSeq) 22 | 23 | let folder (sumP1, sumP2, lineNumber, pLine) line = 24 | let sumP1' = sumP1 + lineToPriority line 25 | match lineNumber with 26 | | 1 -> (sumP1', sumP2, 2, line |> Set.ofSeq) 27 | | 2 -> (sumP1', sumP2, 3, intersect pLine line) 28 | | _ -> (sumP1', sumP2 + calculatePriority (intersect pLine line), 1, Set.empty) 29 | 30 | let solve fileName = 31 | fileName 32 | |> seqOfLines 33 | |> Seq.fold folder (0, 0, 1, Set.empty) 34 | 35 | [] 36 | [] 37 | [] 38 | let test03 fn ep1 ep2 = 39 | let (ap1, ap2, _, _) = solve fn 40 | Assert.Equal(ep1, ap1) 41 | Assert.Equal(ep2, ap2) -------------------------------------------------------------------------------- /2017/src/11.02.ts: -------------------------------------------------------------------------------- 1 | import * as inputSets from "./11-input"; 2 | import { assert } from "./util"; 3 | 4 | const n = [ 0, 2]; 5 | const ne = [ 1, 1]; 6 | const se = [ 1, -1]; 7 | const s = [ 0, -2]; 8 | const nw = [-1, 1]; 9 | const sw = [-1, -1]; 10 | const directions = {n, ne, se, s, sw, nw}; 11 | const next = ([x, y], [xo, yo]) => [x + xo, y + yo]; 12 | const distance = (x, y) => x >= y ? x : ((y - x) / 2) + x; 13 | const findShortestDistance = path => { 14 | let max = 0; 15 | const [x, y] = path.split(",").reduce((from, d) => { 16 | const [tx, ty] = next(from, directions[d]); 17 | max = Math.max(max, distance(Math.abs(tx), Math.abs(ty))); 18 | return [tx, ty]; 19 | }, [0, 0]); 20 | return [distance(Math.abs(x), Math.abs(y)), max]; 21 | }; 22 | 23 | const [t1] = findShortestDistance(inputSets.ip1101); 24 | const [t2] = findShortestDistance(inputSets.ip1102); 25 | const [t3] = findShortestDistance(inputSets.ip1103); 26 | const [t4] = findShortestDistance(inputSets.ip1104); 27 | const [shortest, maxDistance] = findShortestDistance(inputSets.ip1105); 28 | 29 | assert(t1, 3, "11.1, Test 01"); 30 | assert(t2, 0, "11.1, Test 02"); 31 | assert(t3, 2, "11.1, Test 03"); 32 | assert(t4, 3, "11.1, Test 04"); 33 | assert(shortest, 705, "11.1"); 34 | assert(maxDistance, 1469, "11.2"); 35 | -------------------------------------------------------------------------------- /2017/src/run.ts: -------------------------------------------------------------------------------- 1 | // tslint:disable:no-unused-variable 2 | import * as day01 from "./01"; 3 | import * as day02 from "./02"; 4 | import * as day03 from "./03"; 5 | import * as day04 from "./04"; 6 | import * as day05 from "./05"; 7 | import * as day06 from "./06"; 8 | import * as day07 from "./07"; 9 | import * as day08 from "./08"; 10 | import * as day09 from "./09"; 11 | import * as day10 from "./10"; 12 | import * as day11 from "./11.02"; 13 | import * as day12 from "./12"; 14 | import * as day13 from "./13"; 15 | import * as day14 from "./14"; 16 | import * as day15 from "./15"; 17 | import * as day16 from "./16"; 18 | import * as day17 from "./17"; 19 | import * as day18 from "./18"; 20 | import * as day19 from "./19"; 21 | import * as day20 from "./20"; 22 | import * as day21 from "./21"; 23 | import * as day22 from "./22"; 24 | import * as day23 from "./23"; 25 | import * as day24 from "./24"; 26 | import * as day25 from "./25"; 27 | 28 | import { printSummary } from "./util"; 29 | 30 | // tslint:disable-next-line:no-unused-variable 31 | const days = [ 32 | day01, day02, day03, day04, day05, 33 | day06, day07, day08, day09, day10, 34 | day11, day12, day13, day14, day15, 35 | day16, day17, day18, day19, day20, 36 | day21, day22, day23, day24, day25 37 | ]; 38 | printSummary(); 39 | -------------------------------------------------------------------------------- /2021/inputs/16.txt: -------------------------------------------------------------------------------- 1 | 420D74C3088043390499ED709E6EB49A5CC4A3A3898B7E0F44011C4CC48AC0119D049B0C500265EB8F615900180910C88129B2F0007C61C4B7F74ED7396B20020A44A4C014D005E5A72E274B4E5C4B96CC3793410078C01D82F1DA08180351661AC1920042A3CC578BA6008F802138D93352B9CFCEF61D3009A7D2268D254925569C02A92D62BF108D52C1B3E4B257B57FAE5C54400A84840267880311D23245F1007A35C79848200C4288FF0E8C01194A4E625E00A4EFEF5F5996486C400C5002800BFA402D3D00A9C4027B98093D602231C00F001D38C009500258057E601324C00D3003D400C7003DC00A20053A6F1DBDE2D4600A6802B37C4B9E872B0E44CA5FF0BFB116C3004740119895E6F7312BCDE25EF077700725B9F2B8F131F333005740169A7F92EFEB3BC8A21998027400D2CDF30F927880B4C62D6CDFFD88EB0068D2BF019A8DAAF3245B39C9CFA1D2DF9C3DB9D3E50A0164BE2A3339436993894EC41A0D10020B329334C62016C8E7A5F27C97D0663982D8EB23C5282529CDD271E8F100AE1401AA80021119E3A4511006E1E47689323585F3AEBF900AEB2B6942BD91EE8028000874238AB0C00010B8D913220A004A73D789C4D54E24816301802538E940198880371AE15C1D1007638C43856C00954C25CD595A471FE9D90056D60094CEA61933A9854E9F3801F2BBC6131001F792F6796ACB40D036605C80348C005F64F5AC374888CA42FD99A98025319EB950025713656F202200B767AB6A30E802D278F81CBA89004CD286360094FC03A7E01640245CED5A3C010100660FC578B60008641C8B105CC017F004E597E596E633BA5AB78B9C8F840C029917C9E389B439179927A3004F003511006610C658A200084C2989D0AE67BD07000606154B70E66DC0C01E99649545950B8AB34C8401A5CDA050043D319F31CB7EBCEE14 -------------------------------------------------------------------------------- /2017/src/02-input.ts: -------------------------------------------------------------------------------- 1 | export const ip0201 = `5 1 9 5 2 | 7 5 3 3 | 2 4 6 8`; 4 | export const ip0202 = `1364 461 1438 1456 818 999 105 1065 314 99 1353 148 837 590 404 123 5 | 204 99 235 2281 2848 3307 1447 3848 3681 963 3525 525 288 278 3059 821 6 | 280 311 100 287 265 383 204 380 90 377 398 99 194 297 399 87 7 | 7698 2334 7693 218 7344 3887 3423 7287 7700 2447 7412 6147 231 1066 248 208 8 | 3740 837 4144 123 155 2494 1706 4150 183 4198 1221 4061 95 148 3460 550 9 | 1376 1462 73 968 95 1721 544 982 829 1868 1683 618 82 1660 83 1778 10 | 197 2295 5475 2886 2646 186 5925 237 3034 5897 1477 196 1778 3496 5041 3314 11 | 179 2949 3197 2745 1341 3128 1580 184 1026 147 2692 212 2487 2947 3547 1120 12 | 460 73 52 373 41 133 671 61 634 62 715 644 182 524 648 320 13 | 169 207 5529 4820 248 6210 255 6342 4366 5775 5472 3954 3791 1311 7074 5729 14 | 5965 7445 2317 196 1886 3638 266 6068 6179 6333 229 230 1791 6900 3108 5827 15 | 212 249 226 129 196 245 187 332 111 126 184 99 276 93 222 56 16 | 51 592 426 66 594 406 577 25 265 578 522 57 547 65 564 622 17 | 215 2092 1603 1001 940 2054 245 2685 206 1043 2808 208 194 2339 2028 2580 18 | 378 171 155 1100 184 937 792 1436 1734 179 1611 1349 647 1778 1723 1709 19 | 4463 4757 201 186 3812 2413 2085 4685 5294 5755 2898 200 5536 5226 1028 180`; 20 | export const ip0203 = `5 9 2 8 21 | 9 4 7 3 22 | 3 8 6 5`; 23 | -------------------------------------------------------------------------------- /2016/src/18.ts: -------------------------------------------------------------------------------- 1 | import { assert } from "./util"; 2 | 3 | const getCellStatus = (left, center, right) => { 4 | return (left && center && !right) || 5 | (!left && center && right) || 6 | (left && !center && !right) || 7 | (!left && !center && right); 8 | }; 9 | const runGrid = (input, rows) => { 10 | let currentLine = input.split("").map(c => c === "^"); 11 | let countOfSafeTiles = currentLine.reduce((acc, c) => acc + (c ? 0 : 1), 0); 12 | for (let counter = 1; counter < rows; counter++) { 13 | const nextLine = []; 14 | currentLine.forEach((_, i) => { 15 | const cell = getCellStatus(currentLine[i - 1], currentLine[i], currentLine[i + 1]); 16 | if (!cell) { 17 | countOfSafeTiles += 1; 18 | } 19 | nextLine[i] = cell; 20 | }); 21 | currentLine = nextLine; 22 | } 23 | return countOfSafeTiles; 24 | }; 25 | const input = ".^^^.^.^^^.^.......^^.^^^^.^^^^..^^^^^.^.^^^..^^.^.^^..^.^..^^...^.^^.^^^...^^.^.^^^..^^^^.....^...."; 26 | assert(runGrid(".^^.^.^^^^", 10), 38, "Day 18 - Set 1, Sample Input"); 27 | assert(runGrid(input, 40), 2013, "Day 18 - Set 1"); 28 | // slow - uncomment to run part 2 29 | // Based on Sierpinski triangle formulas 30 | // assert(runGrid(input, 400000), 20006289, "Day 18 - Set 2"); 31 | -------------------------------------------------------------------------------- /2020/ts/D02.test.ts: -------------------------------------------------------------------------------- 1 | import { count, matchesToArray } from 'dotless'; 2 | import { getInput } from './util'; 3 | 4 | type Line = [min: number, max: number, char: string, password: string]; 5 | const regex = /(\d+)-(\d+)\s+([a-z]):\s+([a-z]+)/g; 6 | const parseLine = (m: RegExpExecArray) => [+m[1], +m[2], m[3], m[4]] as Line; 7 | const parse = (ip: string) => matchesToArray(getInput(ip), regex, parseLine); 8 | const isValid = ([min, max, char, password]: Line) => { 9 | const count = (password.match(new RegExp(char, 'g')) || []).length; 10 | return min <= count && count <= max; 11 | }; 12 | const isValidCorrectPolicy = ([min, max, char, password]: Line) => { 13 | const cmi = password[min - 1]; 14 | const cmx = password[max - 1]; 15 | return (cmi === char && cmx !== char) || (cmi !== char && cmx == char); 16 | }; 17 | const countValidPasswords = (ip: Line[], validator: (l: Line) => boolean) => 18 | count(validator)(ip); 19 | 20 | test('02', () => { 21 | const testInput = parse('02-test'); 22 | const input = parse('02'); 23 | expect(countValidPasswords(testInput, isValid)).toEqual(2); 24 | expect(countValidPasswords(input, isValid)).toEqual(636); 25 | expect(countValidPasswords(testInput, isValidCorrectPolicy)).toEqual(1); 26 | expect(countValidPasswords(input, isValidCorrectPolicy)).toEqual(588); 27 | }); 28 | -------------------------------------------------------------------------------- /2022/ts/D03.test.ts: -------------------------------------------------------------------------------- 1 | import { getLines } from './util'; 2 | 3 | const calPriority = (c: string) => { 4 | const charCode = c.charCodeAt(0); 5 | if (charCode >= 97) { 6 | return charCode - 97 + 1; 7 | } else { 8 | return charCode - 65 + 1 + 26; 9 | } 10 | }; 11 | 12 | const commonChars = (a: string, b: string) => { 13 | const m = b.match(new RegExp(`[${a}]`, 'g')); 14 | return m ? m.join('') : ''; 15 | }; 16 | 17 | const lineToPriority = (l: string) => { 18 | const cs = l.length / 2; 19 | const fc = l.substring(0, cs); 20 | const sc = l.substring(cs); 21 | return calPriority(commonChars(fc, sc)); 22 | }; 23 | 24 | const solve = (ip: string) => 25 | getLines(ip).reduce( 26 | ([sumP1, sumP2, pl], l, li): [number, number, string] => { 27 | const updatedP1 = sumP1 + lineToPriority(l); 28 | if (li % 3 === 0) return [updatedP1, sumP2, l]; 29 | if (li % 3 === 1) return [updatedP1, sumP2, commonChars(pl, l)]; 30 | return [updatedP1, sumP2 + calPriority(commonChars(pl, l)), '']; 31 | }, 32 | [0, 0, ''] as [number, number, string] 33 | ); 34 | 35 | test('03', () => { 36 | const t = solve('03-test'); 37 | const a = solve('03'); 38 | expect(t).toEqual([157, 70, '']); 39 | expect(a).toEqual([7568, 2780, '']); 40 | }); 41 | -------------------------------------------------------------------------------- /2019/ts/D13.test.ts: -------------------------------------------------------------------------------- 1 | import { getInput } from './util'; 2 | import { IntCodeComputer, SignalType } from './intcode'; 3 | 4 | const puzzleInput = getInput('13'); 5 | const playGame = (): [number, number] => { 6 | const computer = IntCodeComputer(puzzleInput, { overrideZeroLocation: 2 }); 7 | let [blockTiles, score, nextInput, paddle] = [0, 0, 0, 0]; 8 | let outputs: number[] = []; 9 | // eslint-disable-next-line no-constant-condition 10 | while (true) { 11 | const { value } = computer.next(nextInput); 12 | if (value.type === SignalType.OUTPUT) { 13 | const output = value.number; 14 | outputs.push(output); 15 | if (outputs.length === 3) { 16 | const [x, y, tId] = outputs; 17 | if (x === -1 && y === 0) { 18 | score = tId; 19 | } else if (tId === 3) { 20 | paddle = x; 21 | } else if (tId === 4) { 22 | nextInput = paddle < x ? 1 : paddle === x ? 0 : -1; 23 | } else if (tId === 2) { 24 | blockTiles = blockTiles + 1; 25 | } 26 | outputs = []; 27 | } 28 | } else if (value.type === SignalType.COMPLETE) { 29 | break; 30 | } 31 | } 32 | return [blockTiles, score]; 33 | }; 34 | 35 | test('13', () => { 36 | const [blockTiles, score] = playGame(); 37 | expect(blockTiles).toEqual(372); 38 | expect(score).toEqual(19297); 39 | }); 40 | -------------------------------------------------------------------------------- /2018/go/05_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/stretchr/testify/assert" 5 | "testing" 6 | ) 7 | 8 | func Test05(t *testing.T) { 9 | pi := fetchInput("05") 10 | assert.Equal(t, 10, react("dabAcCaCBAcCcaDA"), "05 01 T01") 11 | assert.Equal(t, 0, react("aA"), "05 01 T02") 12 | assert.Equal(t, 0, react("abBA"), "05 01 T03") 13 | assert.Equal(t, 4, react("abAB"), "05 01 T04") 14 | assert.Equal(t, 6, react("aabAAB"), "05 01 T05") 15 | assert.Equal(t, 9808, react(pi), "05 01") 16 | assert.Equal(t, 4, findOptimalSolution("dabAcCaCBAcCcaDA"), "05 02 T01") 17 | assert.Equal(t, 6484, findOptimalSolution(pi), "05 02") 18 | } 19 | 20 | func react(units string) int { 21 | return reducePolymer(units, 0) 22 | } 23 | 24 | func findOptimalSolution(units string) int { 25 | ol := len(units) 26 | for _, ic := range "abcdefghijklmnopqrstuvwxyz" { 27 | l := reducePolymer(units, ic) 28 | if l < ol { 29 | ol = l 30 | } 31 | } 32 | return ol 33 | } 34 | 35 | func reducePolymer(units string, ignore rune) int { 36 | stack := []rune{} 37 | for _, u := range units { 38 | if u == ignore || u == ignore-32 { 39 | continue 40 | } 41 | li := len(stack) - 1 42 | if li >= 0 { 43 | lu := stack[li] 44 | if u == lu+32 || u == lu-32 { 45 | stack = stack[:li] 46 | continue 47 | } 48 | } 49 | stack = append(stack, u) 50 | } 51 | return len(stack) 52 | } 53 | -------------------------------------------------------------------------------- /2018/ts/D08.test.ts: -------------------------------------------------------------------------------- 1 | import { getInput } from "./util"; 2 | 3 | const parse = (ip: string) => getInput(ip).split(" ").map(m => +m); 4 | 5 | const traverseNodes = ([childNodesCount, countOfMetaDataEntries, ...rest]: number[]): [number[], number, number] => { 6 | const valuesOfChildNodes = []; 7 | let valueOfNode = 0; 8 | let sumOfMetadata = 0; 9 | for (let i = 0; i < childNodesCount; i++) { 10 | const [ remaining, childMetadata, value ] = traverseNodes(rest); 11 | sumOfMetadata = sumOfMetadata + childMetadata; 12 | valuesOfChildNodes.push(value); 13 | rest = remaining; 14 | } 15 | for (let i = 0; i < countOfMetaDataEntries; i++) { 16 | const metadata = rest.shift(); 17 | if (metadata === undefined) { 18 | break; 19 | } 20 | if (childNodesCount > 0) { 21 | if (metadata <= childNodesCount) { 22 | valueOfNode = valueOfNode + valuesOfChildNodes[metadata - 1]; 23 | } 24 | } else { 25 | valueOfNode = valueOfNode + metadata; 26 | } 27 | sumOfMetadata = sumOfMetadata + metadata; 28 | } 29 | return [rest, sumOfMetadata, valueOfNode]; 30 | }; 31 | 32 | test("08", () => { 33 | expect(traverseNodes(parse("08-test"))).toEqual([[], 138, 66]); 34 | expect(traverseNodes(parse("08"))).toEqual([[], 36307, 25154]); 35 | }); 36 | -------------------------------------------------------------------------------- /2020/fsharp/aoc2020-test/AOC2020.fsproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp5.0 5 | AOC2020 6 | 7 | false 8 | false 9 | AOC2020 10 | 11 | 12 | 13 | 5 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | runtime; build; native; contentfiles; analyzers; buildtransitive 27 | all 28 | 29 | 30 | runtime; build; native; contentfiles; analyzers; buildtransitive 31 | all 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /2021/fs/D01.fs: -------------------------------------------------------------------------------- 1 | module D01 2 | 3 | open Common 4 | open Xunit 5 | 6 | let isIncreasing (a, b) = a < b 7 | 8 | let countIfIncrements fn = 9 | fn 10 | |> mapLinesToNumber 11 | |> Array.pairwise 12 | |> Array.filter isIncreasing 13 | |> Array.length 14 | 15 | let countIfSlidingWindowIncrements fn = 16 | fn 17 | |> mapLinesToNumber 18 | |> Array.windowed 3 19 | |> Array.map Array.sum 20 | |> Array.pairwise 21 | |> Array.filter isIncreasing 22 | |> Array.length 23 | 24 | let countIfLarge acc a b = 25 | if a < b then 26 | acc + 1 27 | else 28 | acc 29 | 30 | let count (seq: int seq) dist = 31 | (0, seq, seq |> Seq.skip dist) |||> 32 | Seq.fold2 countIfLarge 33 | 34 | [] 35 | [] 36 | [] 37 | let P1 fn expected = 38 | Assert.Equal(expected, countIfIncrements fn) 39 | 40 | [] 41 | [] 42 | [] 43 | let P2 fn expected = 44 | Assert.Equal(expected, countIfSlidingWindowIncrements fn) 45 | Assert.Equal(expected, countIfSlidingWindowIncrements fn) 46 | 47 | [] 48 | [] 49 | [] 50 | let P ip ep1 ep2 = 51 | let numbers = mapLinesToNumber ip 52 | Assert.Equal(ep1, count numbers 1) 53 | Assert.Equal(ep2, count numbers 3) 54 | -------------------------------------------------------------------------------- /2021/inputs/14.txt: -------------------------------------------------------------------------------- 1 | BCHCKFFHSKPBSNVVKVSK 2 | 3 | OV -> V 4 | CO -> V 5 | CS -> O 6 | NP -> H 7 | HH -> P 8 | KO -> F 9 | VO -> B 10 | SP -> O 11 | CB -> N 12 | SB -> F 13 | CF -> S 14 | KS -> P 15 | OH -> H 16 | NN -> O 17 | SF -> K 18 | FH -> F 19 | VV -> B 20 | VH -> O 21 | BV -> V 22 | KF -> K 23 | CC -> F 24 | NF -> H 25 | VS -> O 26 | SK -> K 27 | HV -> O 28 | CK -> K 29 | VP -> F 30 | HP -> S 31 | CN -> K 32 | OB -> H 33 | NS -> F 34 | PS -> S 35 | KB -> S 36 | VF -> S 37 | FP -> H 38 | BB -> N 39 | HF -> V 40 | CH -> N 41 | BH -> F 42 | KK -> B 43 | OO -> N 44 | NO -> K 45 | BP -> K 46 | KH -> P 47 | KN -> P 48 | OF -> B 49 | VC -> F 50 | NK -> F 51 | ON -> O 52 | OC -> P 53 | VK -> O 54 | SH -> C 55 | NH -> C 56 | FB -> B 57 | FC -> K 58 | OP -> O 59 | PV -> V 60 | BN -> V 61 | PC -> K 62 | PK -> S 63 | FF -> C 64 | SV -> S 65 | HK -> H 66 | NB -> C 67 | OK -> C 68 | PH -> B 69 | SO -> O 70 | PP -> F 71 | KV -> V 72 | FO -> B 73 | FN -> H 74 | HN -> C 75 | VB -> K 76 | CV -> O 77 | BC -> C 78 | CP -> S 79 | FS -> S 80 | KP -> V 81 | BS -> V 82 | BK -> B 83 | PN -> C 84 | PF -> S 85 | HO -> V 86 | NC -> N 87 | SS -> N 88 | BO -> P 89 | BF -> N 90 | NV -> P 91 | PB -> K 92 | HB -> H 93 | VN -> H 94 | FV -> B 95 | FK -> K 96 | PO -> S 97 | SC -> S 98 | HS -> S 99 | KC -> F 100 | HC -> S 101 | OS -> K 102 | SN -> N -------------------------------------------------------------------------------- /2023/ts/D06.test.ts: -------------------------------------------------------------------------------- 1 | import { mapLine, toNumber } from './util'; 2 | 3 | type Race = { 4 | time: number; 5 | distance: number; 6 | }; 7 | 8 | const findWinningWays = (r: Race): number => { 9 | let winningWays = 0; 10 | for (let t = 1; t < r.time; t++) { 11 | const speed = t; 12 | const timeRemaining = r.time - t; 13 | const distance = speed * timeRemaining; 14 | if (distance > r.distance) { 15 | winningWays++; 16 | } 17 | } 18 | return winningWays; 19 | }; 20 | 21 | const parse = (fn: string): Race[] => { 22 | const [fl, sl] = mapLine(fn, l => l.split(/\s+/).slice(1).map(toNumber)); 23 | return fl.map((t, ti) => ({ time: t, distance: sl[ti] })); 24 | }; 25 | 26 | const solve = (fn: string): [number, number] => { 27 | const races = parse(fn); 28 | const p1 = races.map(findWinningWays).reduce((acc, wc) => acc * wc); 29 | const [ct, cd] = races 30 | .reduce( 31 | ([t, d], r) => [t + r.time.toString(), d + r.distance.toString()], 32 | ['', ''], 33 | ) 34 | .map(toNumber); 35 | const sqrt = Math.sqrt(ct ** 2 - 4 * cd); 36 | const p2 = Math.ceil((ct + sqrt) / 2) - Math.floor((ct - sqrt) / 2) - 1; 37 | return [p1, p2]; 38 | }; 39 | 40 | test('06', () => { 41 | expect(solve('06-t1')).toEqual([288, 71503]); 42 | expect(solve('06')).toEqual([293046, 35150181]); 43 | }); 44 | -------------------------------------------------------------------------------- /2017/src/25.ts: -------------------------------------------------------------------------------- 1 | import { assert } from "./util"; 2 | 3 | const findCheckSum = (bluePrint, steps) => { 4 | const tape = { }; 5 | let cursor = 0; 6 | let state = "a"; 7 | while (steps--) { 8 | const cursorKey = "c" + cursor; 9 | const currentValue = tape[cursorKey] || 0; 10 | const [value, change, nextState] = bluePrint[state][currentValue]; 11 | tape[cursorKey] = value; 12 | cursor = cursor + change; 13 | state = nextState; 14 | } 15 | let checksum = 0; 16 | // tslint:disable-next-line:forin 17 | for (const t in tape) { 18 | checksum = checksum + tape[t]; 19 | } 20 | return checksum; 21 | }; 22 | 23 | const left = -1; 24 | const right = 1; 25 | const testSteps = 6; 26 | const testBP = { 27 | a : [ [1, right, "b"], [0, left, "b" ] ], 28 | b : [ [1, left, "a"], [1, right, "a" ] ] 29 | }; 30 | const puzzleSteps = 12386363; 31 | const puzzleBP = { 32 | a : [ [1, right, "b"], [0, left, "e" ] ], 33 | b : [ [1, left, "c"], [0, right, "a" ] ], 34 | c : [ [1, left, "d"], [0, right, "c" ] ], 35 | d : [ [1, left, "e"], [0, left, "f" ] ], 36 | e : [ [1, left, "a"], [1, left, "c" ] ], 37 | f : [ [1, left, "e"], [1, right, "a" ] ] 38 | }; 39 | const a = findCheckSum(testBP, testSteps); 40 | const b = findCheckSum(puzzleBP, puzzleSteps); 41 | 42 | assert(a, 3, "25.1, Test 01"); 43 | assert(b, 4385, "25.1"); 44 | -------------------------------------------------------------------------------- /2021/ts/D07.test.ts: -------------------------------------------------------------------------------- 1 | import { mapLineToNumber } from './util'; 2 | 3 | const calCostAtConstantRate = (positions: number[], anchor: number) => 4 | positions.reduce((c, p) => c + Math.abs(p - anchor), 0); 5 | 6 | const calCostAtIncreasingRate = (positions: number[], anchor: number) => 7 | positions.reduce((c, p) => { 8 | const diff = Math.abs(p - anchor); 9 | return c + (diff * (diff + 1)) / 2; 10 | }, 0); 11 | 12 | const calAverage = (ns: number[]) => ns.reduce((a, b) => a + b) / ns.length; 13 | 14 | const solve = (fn: string) => { 15 | const positions = mapLineToNumber(fn, ',').sort((a, b) => a - b); 16 | const count = positions.length; 17 | const mi = Math.floor(count / 2); 18 | const middlePosition = 19 | count % 2 === 0 20 | ? (positions[mi - 1] + positions[mi]) / 2 21 | : positions[mi]; 22 | const fuelAtConstantRate = calCostAtConstantRate(positions, middlePosition); 23 | const averagePosition = Math.floor(calAverage(positions)); 24 | const fuelAtVaryingRate = Math.min( 25 | ...[averagePosition - 1, averagePosition, averagePosition + 1].map(p => 26 | calCostAtIncreasingRate(positions, p) 27 | ) 28 | ); 29 | return [fuelAtConstantRate, fuelAtVaryingRate]; 30 | }; 31 | 32 | test('07', () => { 33 | expect(solve('07-test')).toEqual([37, 168]); 34 | expect(solve('07')).toEqual([352997, 101571302]); 35 | }); 36 | -------------------------------------------------------------------------------- /2019/inputs/19.txt: -------------------------------------------------------------------------------- 1 | 109,424,203,1,21101,11,0,0,1105,1,282,21102,18,1,0,1106,0,259,1201,1,0,221,203,1,21102,1,31,0,1105,1,282,21101,38,0,0,1106,0,259,20102,1,23,2,21201,1,0,3,21101,1,0,1,21102,57,1,0,1105,1,303,1201,1,0,222,21001,221,0,3,20101,0,221,2,21102,1,259,1,21101,0,80,0,1105,1,225,21101,76,0,2,21102,1,91,0,1106,0,303,2102,1,1,223,21002,222,1,4,21102,1,259,3,21101,0,225,2,21102,225,1,1,21102,1,118,0,1105,1,225,21001,222,0,3,21102,1,54,2,21102,1,133,0,1106,0,303,21202,1,-1,1,22001,223,1,1,21101,148,0,0,1106,0,259,1202,1,1,223,21001,221,0,4,20101,0,222,3,21101,14,0,2,1001,132,-2,224,1002,224,2,224,1001,224,3,224,1002,132,-1,132,1,224,132,224,21001,224,1,1,21101,0,195,0,106,0,108,20207,1,223,2,20101,0,23,1,21101,0,-1,3,21102,1,214,0,1105,1,303,22101,1,1,1,204,1,99,0,0,0,0,109,5,1202,-4,1,249,22102,1,-3,1,21201,-2,0,2,21202,-1,1,3,21101,0,250,0,1106,0,225,22101,0,1,-4,109,-5,2105,1,0,109,3,22107,0,-2,-1,21202,-1,2,-1,21201,-1,-1,-1,22202,-1,-2,-2,109,-3,2105,1,0,109,3,21207,-2,0,-1,1206,-1,294,104,0,99,21201,-2,0,-2,109,-3,2105,1,0,109,5,22207,-3,-4,-1,1206,-1,346,22201,-4,-3,-4,21202,-3,-1,-1,22201,-4,-1,2,21202,2,-1,-1,22201,-4,-1,1,22101,0,-2,3,21102,1,343,0,1106,0,303,1106,0,415,22207,-2,-3,-1,1206,-1,387,22201,-3,-2,-3,21202,-2,-1,-1,22201,-3,-1,3,21202,3,-1,-1,22201,-3,-1,2,22102,1,-4,1,21101,0,384,0,1105,1,303,1106,0,415,21202,-4,-1,-4,22201,-4,-3,-4,22202,-3,-2,-2,22202,-2,-4,-4,22202,-3,-2,-3,21202,-4,-1,-2,22201,-3,-2,1,21202,1,1,-4,109,-5,2106,0,0 -------------------------------------------------------------------------------- /2022/ts/D10.ts: -------------------------------------------------------------------------------- 1 | import { mapLine } from './util'; 2 | type Action = 'addx' | 'noop'; 3 | type Instruction = [Action, number]; 4 | type State = { 5 | cycles: number; 6 | interesting: number; 7 | x: number; 8 | pos: number; 9 | crt: string; 10 | }; 11 | const lineToInstruction = (l: string): Instruction => { 12 | const parts = l.split(' '); 13 | return [parts[0] as Action, +parts[1]]; 14 | }; 15 | const cycle = ( 16 | { cycles, interesting, x, pos, crt }: State, 17 | v: number 18 | ): State => { 19 | cycles = cycles + 1; 20 | if ((cycles - 20) % 40 === 0) { 21 | interesting = interesting + cycles * x; 22 | } 23 | crt = crt + (x - 1 <= pos && pos <= x + 1 ? '#' : ' '); 24 | pos = (pos + 1) % 40; 25 | if (pos === 0) crt = crt + '\n'; 26 | x = x + v; 27 | return { cycles, interesting, x, pos, crt }; 28 | }; 29 | const followInstruction = (state: State, [Action, v]: Instruction): State => { 30 | state = cycle(state, 0); 31 | if (Action === 'addx') { 32 | state = cycle(state, v); 33 | } 34 | return state; 35 | }; 36 | const solve = (fn: string) => { 37 | const seed = { cycles: 0, interesting: 0, x: 1, pos: 0, crt: '' }; 38 | const final = mapLine(fn, lineToInstruction).reduce( 39 | followInstruction, 40 | seed 41 | ); 42 | console.log(final.interesting); 43 | console.log(final.crt); 44 | }; 45 | solve('10-test'); 46 | solve('10'); 47 | -------------------------------------------------------------------------------- /2016/src/run.ts: -------------------------------------------------------------------------------- 1 | // tslint:disable:no-unused-variable 2 | import * as day01 from "./01"; 3 | import * as day02 from "./02"; 4 | import * as day03 from "./03"; 5 | import * as day04 from "./04"; 6 | // day05 - slow 7 | import * as day06 from "./06"; 8 | import * as day07 from "./07"; 9 | import * as day08 from "./08"; 10 | import * as day09 from "./09"; 11 | import * as day10 from "./10"; 12 | import * as day11 from "./11"; // Just part 1, part 2 slow hence commented 13 | import * as day12 from "./12"; 14 | import * as day13 from "./13"; 15 | import * as day14 from "./14"; // Just part 1, part 2 slow hence commented 16 | import * as day15 from "./15"; 17 | import * as day16 from "./16"; // Just part 1, part 2 slow hence commented 18 | import * as day17 from "./17"; 19 | import * as day18 from "./18"; // Just part 1, part 2 slow hence commented 20 | import * as day19 from "./19"; 21 | import * as day20 from "./20"; 22 | import * as day21 from "./21"; 23 | import * as day22 from "./22"; 24 | import * as day23 from "./23"; 25 | import * as day24 from "./23"; 26 | import * as day25 from "./25"; 27 | import { printSummary } from "./util"; 28 | 29 | // tslint:disable-next-line:no-unused-variable 30 | const days = [day01, day02, day03, day04, 31 | day06, day07, day08, day09, day10, 32 | day11, day12, day13, day14, day15, 33 | day16, day17, day18, day19, day20, 34 | day21, day22, day23, day24, day25]; 35 | printSummary(); 36 | -------------------------------------------------------------------------------- /2018/elixir/14.exs: -------------------------------------------------------------------------------- 1 | # No good option for data structure with random access, end up using Map, only part 1 2 | defmodule D14 do 3 | def iterate(board, fe, se, count, iterations) do 4 | fe_rec = Map.get(board, fe) # elem(board, fe) 5 | se_rec = Map.get(board, se) # elem(board, se) 6 | if fe_rec == nil do 7 | IO.inspect(board) 8 | IO.inspect(fe) 9 | IO.inspect(se) 10 | end 11 | ne_rec = fe_rec + se_rec 12 | up_board = if ne_rec > 9, 13 | do: Map.put(Map.put(board, count, 1), count + 1, ne_rec - 10), 14 | else: Map.put(board, count, ne_rec) 15 | up_count = count + (if ne_rec > 9, do: 2, else: 1) 16 | up_fe = rem(fe + fe_rec + 1, up_count) 17 | up_se = rem(se + se_rec + 1, up_count) 18 | if up_count < iterations + 10 do 19 | iterate(up_board, up_fe, up_se, up_count, iterations) 20 | else 21 | up_board 22 | |> Enum.filter(fn {k, _} -> iterations <= k and k < iterations + 10 end) 23 | |> Enum.sort(fn {k1, _}, {k2, _} -> k1 < k2 end) 24 | |> Enum.reduce("", fn {_, v}, acc -> "#{acc}#{v}" end) 25 | end 26 | end 27 | def find_score(iterations) do 28 | iterate(%{0 => 3, 1 => 7}, 0, 1, 2, iterations) 29 | end 30 | end 31 | 32 | "5158916779" = D14.find_score(9) 33 | "0124515891" = D14.find_score(5) 34 | "9251071085" = D14.find_score(18) 35 | "5941429882" = D14.find_score(2018) 36 | "6985103122" = D14.find_score(380621) 37 | 38 | IO.puts("Only Part 1") 39 | -------------------------------------------------------------------------------- /2017/src/01.ts: -------------------------------------------------------------------------------- 1 | import * as inputSets from "./01-input"; 2 | import { assert } from "./util"; 3 | 4 | const parseInput = input => input.split("").map(n => +n); 5 | const getNextDigit = (i, arr) => arr[i === arr.length - 1 ? 0 : i + 1]; 6 | const getHalfwayAroundDigit = (i, arr) => arr[(i + (arr.length / 2)) % arr.length]; 7 | const solveCaptcha = (seq, next) => seq.reduce((acc, d, i, arr) => acc + (d === next(i, arr) ? d : 0), 0); 8 | 9 | assert(solveCaptcha(parseInput(inputSets.ip0101), getNextDigit), 3, "01.1, Test 01"); 10 | assert(solveCaptcha(parseInput(inputSets.ip0102), getNextDigit), 4, "01.1, Test 02"); 11 | assert(solveCaptcha(parseInput(inputSets.ip0103), getNextDigit), 0, "01.1, Test 03"); 12 | assert(solveCaptcha(parseInput(inputSets.ip0104), getNextDigit), 9, "01.1, Test 04"); 13 | assert(solveCaptcha(parseInput(inputSets.ip0105), getNextDigit), 1177, "01.1"); 14 | assert(solveCaptcha(parseInput(inputSets.ip0106), getHalfwayAroundDigit), 6, "01.2, Test 01"); 15 | assert(solveCaptcha(parseInput(inputSets.ip0107), getHalfwayAroundDigit), 0, "01.2, Test 02"); 16 | assert(solveCaptcha(parseInput(inputSets.ip0108), getHalfwayAroundDigit), 4, "01.2, Test 03"); 17 | assert(solveCaptcha(parseInput(inputSets.ip0109), getHalfwayAroundDigit), 12, "01.2, Test 04"); 18 | assert(solveCaptcha(parseInput(inputSets.ip0110), getHalfwayAroundDigit), 4, "01.2, Test 05"); 19 | assert(solveCaptcha(parseInput(inputSets.ip0105), getHalfwayAroundDigit), 1060, "01.2"); 20 | -------------------------------------------------------------------------------- /2019/ts/D04.test.ts: -------------------------------------------------------------------------------- 1 | import { range } from 'dotless'; 2 | 3 | const countValidPasswords = (from: number, to: number) => { 4 | let [p1, p2] = [0, 0]; 5 | // TODO :: Change range for i5 based on from and to 6 | for (const i5 of range(2, 7)) { 7 | for (const i4 of range(i5, 9)) { 8 | for (const i3 of range(i4, 9)) { 9 | for (const i2 of range(i3, 9)) { 10 | for (const i1 of range(i2, 9)) { 11 | for (const i0 of range(i1, 9)) { 12 | // prettier-ignore 13 | const currentNum = +(i5 + '' + i4 + '' + i3 + '' + i2 + '' + i1 + '' + i0); 14 | if (currentNum < from || to < currentNum) { 15 | continue; 16 | } 17 | // prettier-ignore 18 | if (i5 === i4 || i4 === i3 || i3 === i2 || i2 === i1 || i1 === i0) { 19 | p1 = p1 + 1; 20 | } 21 | if ( 22 | (i5 === i4 && i4 !== i3) || 23 | (i4 === i3 && i5 !== i4 && i3 !== i2) || 24 | (i3 === i2 && i4 !== i3 && i2 !== i1) || 25 | (i2 === i1 && i3 !== i2 && i1 != i0) || 26 | (i1 === i0 && i2 !== i1) 27 | ) { 28 | p2 = p2 + 1; 29 | } 30 | } 31 | } 32 | } 33 | } 34 | } 35 | } 36 | return [p1, p2]; 37 | }; 38 | 39 | test('04', () => { 40 | expect(countValidPasswords(240920, 789857)).toEqual([1154, 750]); 41 | }); 42 | -------------------------------------------------------------------------------- /2018/elixir/03.exs: -------------------------------------------------------------------------------- 1 | test_01 = "#1 @ 1,3: 4x4\n#2 @ 3,1: 4x4\n#3 @ 5,5: 2x2" 2 | puzzle_input = with {:ok, file} = File.open("../inputs/03.txt"), 3 | content = IO.read(file, :all), 4 | :ok = File.close(file) do 5 | content 6 | end 7 | 8 | update_cord = fn [id, x, y, w, h] -> [id, x, y, x + w - 1, y + h - 1] end 9 | 10 | parse_line = fn l -> 11 | l 12 | |> (&Regex.scan(~r/\d+/, &1)).() 13 | |> List.flatten() 14 | |> Enum.map(&String.to_integer/1) 15 | |> update_cord.() 16 | end 17 | 18 | parse = fn ip -> 19 | ip 20 | |> String.split("\n") 21 | |> Enum.map(parse_line) 22 | end 23 | 24 | get_squares = fn ([_, x1, y1, x2, y2]) -> 25 | for x <- x1..x2, y <- y1..y2, do: {x, y} 26 | end 27 | 28 | claim_squares = fn (claim, acc) -> 29 | claim 30 | |> get_squares.() 31 | |> Enum.reduce(acc, fn s, {fabric, disputed} -> 32 | {Map.update(fabric, s, 1, &(&1 + 1)), (if fabric[s] == 1, do: disputed + 1, else: disputed)} 33 | end) 34 | end 35 | 36 | find_undisputed = fn fabric, claims -> 37 | claims 38 | |> Enum.find(fn c -> Enum.all?(get_squares.(c), fn s -> fabric[s] == 1 end) end) 39 | end 40 | 41 | slice_it = fn ip -> 42 | with claims = parse.(ip), 43 | { fabric, disputed } = Enum.reduce(claims, {%{}, 0}, claim_squares), 44 | [undisputed_id | _] = find_undisputed.(fabric, claims) do 45 | [disputed, undisputed_id] 46 | end 47 | end 48 | 49 | [4, 3] = slice_it.(test_01) 50 | [119572, 775] = slice_it.(puzzle_input) 51 | 52 | IO.puts("Done") 53 | -------------------------------------------------------------------------------- /2018/ts/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "emitDecoratorMetadata": true, 5 | "experimentalDecorators": true, 6 | "module": "commonjs", 7 | "moduleResolution": "node", 8 | "noEmitOnError": true, 9 | "declaration": true, 10 | "declarationDir": "./dist", 11 | 12 | // "strict": true, /* Enable all strict type-checking options. */ 13 | "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 14 | "strictNullChecks": true, /* Enable strict null checks. */ 15 | "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 16 | "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 17 | 18 | /* Additional Checks */ 19 | "noUnusedLocals": true, /* Report errors on unused locals. */ 20 | "noUnusedParameters": true, /* Report errors on unused parameters. */ 21 | "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 22 | "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 23 | 24 | "removeComments": true, 25 | "sourceMap": true, 26 | "target": "es6", 27 | "lib" : ["es2017"] 28 | }, 29 | "exclude": [ 30 | "node_modules", 31 | "dist" 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /2019/inputs/20b.txt: -------------------------------------------------------------------------------- 1 | A 2 | A 3 | #################.############# 4 | #.#...#...................#.#.# 5 | #.#.#.###.###.###.#########.#.# 6 | #.#.#.......#...#.....#.#.#...# 7 | #.#########.###.#####.#.#.###.# 8 | #.............#.#.....#.......# 9 | ###.###########.###.#####.#.#.# 10 | #.....# A C #.#.#.# 11 | ####### S P #####.# 12 | #.#...# #......VT 13 | #.#.#.# #.##### 14 | #...#.# YN....#.# 15 | #.###.# #####.# 16 | DI....#.# #.....# 17 | #####.# #.###.# 18 | ZZ......# QG....#..AS 19 | ###.### ####### 20 | JO..#.#.# #.....# 21 | #.#.#.# ###.#.# 22 | #...#..DI BU....#..LF 23 | #####.# #.##### 24 | YN......# VT..#....QG 25 | #.###.# #.###.# 26 | #.#...# #.....# 27 | ###.### J L J #.#.### 28 | #.....# O F P #.#...# 29 | #.###.#####.#.#####.#####.###.# 30 | #...#.#.#...#.....#.....#.#...# 31 | #.#####.###.###.#.#.#########.# 32 | #...#.#.....#...#.#.#.#.....#.# 33 | #.###.#####.###.###.#.#.####### 34 | #.#.........#...#.............# 35 | #########.###.###.############# 36 | B J C 37 | U P P -------------------------------------------------------------------------------- /2018/ts/D05.test.ts: -------------------------------------------------------------------------------- 1 | import { map, query, range, reduce } from "dotless"; 2 | import { getInput } from "./util"; 3 | 4 | const reducePolymer = (units: string, ignore: number = 0) => { 5 | const stack = []; 6 | for (const u of units) { 7 | const uc = u.charCodeAt(0); 8 | if(uc === ignore || uc === ignore + 32) { 9 | continue; 10 | } 11 | if(stack.length === 0) { 12 | stack.push(uc); 13 | continue; 14 | } 15 | const luc = stack[stack.length - 1]; 16 | if(luc === uc + 32 || luc === uc - 32) { 17 | stack.pop(); 18 | } else { 19 | stack.push(uc); 20 | } 21 | } 22 | return stack.length; 23 | }; 24 | 25 | const findOptimalSolution = (units: string) => query( 26 | range(65, 90), 27 | map(r => reducePolymer(units, r)), 28 | reduce((acc, l) => acc < l ? acc : l, Number.MAX_SAFE_INTEGER) 29 | ); 30 | 31 | test("05", () => { 32 | const test01 = "dabAcCaCBAcCcaDA"; 33 | const puzzleInput = getInput("05"); 34 | expect(reducePolymer("aA")).toEqual(0); 35 | expect(reducePolymer("abBA")).toEqual(0); 36 | expect(reducePolymer("abAB")).toEqual(4); 37 | expect(reducePolymer("aabAAB")).toEqual(6); 38 | expect(reducePolymer(test01)).toEqual(10); 39 | expect(findOptimalSolution(test01)).toEqual(4); 40 | expect(reducePolymer(puzzleInput)).toEqual(9808); 41 | expect(findOptimalSolution(puzzleInput)).toEqual(6484); 42 | }); 43 | -------------------------------------------------------------------------------- /2021/fs/D02.fs: -------------------------------------------------------------------------------- 1 | module D02 2 | 3 | open Common 4 | open Xunit 5 | 6 | type CommandType = Forward | Down | Up 7 | type Instruction = { Command: CommandType; Unit: int } 8 | type Position = { Horizontal : int; Depth1: int; Depth2 : int; Aim : int } 9 | 10 | let parseCommandType = function 11 | | "forward" -> Forward 12 | | "down" -> Down 13 | | "up" -> Up 14 | | code -> failwith (sprintf "Wrong Command Type! %s" code) 15 | 16 | let toInstruction (line : string) = 17 | let parts = line.Split() 18 | { Command = parseCommandType parts[0]; Unit = int parts[1] } 19 | 20 | let navigate (p:Position) (i: Instruction) = 21 | match i with 22 | | { Command = Forward; Unit = u } -> { p with Horizontal = p.Horizontal + u; Depth2 = p.Depth2 + (u * p.Aim) } 23 | | { Command = Down; Unit = u } -> { p with Depth1 = p.Depth1 + u; Aim = p.Aim + u } 24 | | { Command = Up; Unit = u } -> { p with Depth1 = p.Depth1 - u; Aim = p.Aim - u } 25 | 26 | let getProducts (p:Position) : (int * int) = (p.Horizontal * p.Depth1, p.Horizontal * p.Depth2) 27 | 28 | let solve fn = fn 29 | |> mapLines toInstruction 30 | |> Array.fold navigate { Horizontal = 0 ; Depth1 = 0; Depth2 = 0; Aim = 0 } 31 | |> getProducts 32 | 33 | [] 34 | [] 35 | [] 36 | let test fn ep1 ep2 = 37 | let (ap1, ap2) = solve fn 38 | Assert.Equal(ep1, ap1) 39 | Assert.Equal(ep2, ap2) 40 | -------------------------------------------------------------------------------- /2023/fs/D01.fs: -------------------------------------------------------------------------------- 1 | module D01 2 | 3 | open Common 4 | open Xunit 5 | 6 | let toTuple list = 7 | list |> List.mapi (fun i li -> (li, i + 1)) 8 | 9 | let tokensP1 = [ "1"; "2"; "3"; "4"; "5"; "6"; "7"; "8"; "9" ] |> toTuple 10 | 11 | let tokensP2 = 12 | [ "one"; "two"; "three"; "four"; "five"; "six"; "seven"; "eight"; "nine" ] 13 | |> toTuple 14 | 15 | let valuesP1 = tokensP1 |> Map.ofSeq 16 | 17 | let valuesP2 = (tokensP1 @ tokensP2) |> Map.ofSeq 18 | 19 | let forward (l: string) = [ 0 .. l.Length ] 20 | 21 | let backward (l: string) = [ l.Length .. -1 .. 0 ] 22 | 23 | let search direction (tokens: string seq) values (l: string) = 24 | l 25 | |> direction 26 | |> Seq.map (fun n -> tokens |> Seq.tryFind (fun num -> l[ n.. ].StartsWith(num))) 27 | |> Seq.choose id 28 | |> Seq.tryHead 29 | |> Option.bind (fun n -> values |> Map.tryFind n) 30 | |> Option.defaultValue 0 31 | 32 | let parseLine tokens values (l: string) = 33 | ((search forward tokens values l) * 10) + (search backward tokens values l) 34 | 35 | let solve fileName values = 36 | let tokens = values |> Map.keys 37 | fileName |> seqOfLines |> Seq.map (parseLine tokens values) |> Seq.sum 38 | 39 | [] 40 | [] 41 | [] 42 | let test01P1 fn ep1 = Assert.Equal(ep1, (solve fn valuesP1)) 43 | 44 | [] 45 | [] 46 | [] 47 | let test01P2 fn ep2 = Assert.Equal(ep2, (solve fn valuesP2)) 48 | -------------------------------------------------------------------------------- /2018/ts/D01.test.ts: -------------------------------------------------------------------------------- 1 | import { cycle, first, mapWithLast, query } from "dotless"; 2 | import { getInput, seenBefore } from "./util"; 3 | 4 | const parse = (s: string) => s.split(/,|\n/).map(n => + n); 5 | const test01 = parse("+1, +1, +1"); 6 | const test02 = parse("+1, +1, -2"); 7 | const test03 = parse("-1, -2, -3"); 8 | const test04 = parse("+1, -1"); 9 | const test05 = parse("+3, +3, +4, -2, -4"); 10 | const test06 = parse("-6, +3, +8, +5, -6"); 11 | const test07 = parse("+7, +7, -2, -7, -4"); 12 | const puzzleInput = parse(getInput("01")); 13 | 14 | const sum = (f: number, i: number) => f + i; 15 | 16 | const findResultingFrequency = (frequencies: number[]) => frequencies.reduce(sum, 0); 17 | 18 | const firstFrequencyReachesTwice = (frequencies: number[]) => query( 19 | cycle(frequencies), 20 | mapWithLast(sum, 0), 21 | first(seenBefore([0])) 22 | ); 23 | 24 | test("01, Part 1", () => { 25 | expect(findResultingFrequency(test01)).toEqual(3); 26 | expect(findResultingFrequency(test02)).toEqual(0); 27 | expect(findResultingFrequency(test03)).toEqual(-6); 28 | expect(findResultingFrequency(puzzleInput)).toEqual(466); 29 | }); 30 | 31 | test("01, Part 2", () => { 32 | expect(firstFrequencyReachesTwice(test04)).toEqual(0); 33 | expect(firstFrequencyReachesTwice(test05)).toEqual(10); 34 | expect(firstFrequencyReachesTwice(test06)).toEqual(5); 35 | expect(firstFrequencyReachesTwice(test07)).toEqual(14); 36 | expect(firstFrequencyReachesTwice(puzzleInput)).toEqual(750); 37 | }); 38 | -------------------------------------------------------------------------------- /2022/inputs/11.txt: -------------------------------------------------------------------------------- 1 | Monkey 0: 2 | Starting items: 54, 82, 90, 88, 86, 54 3 | Operation: new = old * 7 4 | Test: divisible by 11 5 | If true: throw to monkey 2 6 | If false: throw to monkey 6 7 | 8 | Monkey 1: 9 | Starting items: 91, 65 10 | Operation: new = old * 13 11 | Test: divisible by 5 12 | If true: throw to monkey 7 13 | If false: throw to monkey 4 14 | 15 | Monkey 2: 16 | Starting items: 62, 54, 57, 92, 83, 63, 63 17 | Operation: new = old + 1 18 | Test: divisible by 7 19 | If true: throw to monkey 1 20 | If false: throw to monkey 7 21 | 22 | Monkey 3: 23 | Starting items: 67, 72, 68 24 | Operation: new = old * old 25 | Test: divisible by 2 26 | If true: throw to monkey 0 27 | If false: throw to monkey 6 28 | 29 | Monkey 4: 30 | Starting items: 68, 89, 90, 86, 84, 57, 72, 84 31 | Operation: new = old + 7 32 | Test: divisible by 17 33 | If true: throw to monkey 3 34 | If false: throw to monkey 5 35 | 36 | Monkey 5: 37 | Starting items: 79, 83, 64, 58 38 | Operation: new = old + 6 39 | Test: divisible by 13 40 | If true: throw to monkey 3 41 | If false: throw to monkey 0 42 | 43 | Monkey 6: 44 | Starting items: 96, 72, 89, 70, 88 45 | Operation: new = old + 4 46 | Test: divisible by 3 47 | If true: throw to monkey 1 48 | If false: throw to monkey 2 49 | 50 | Monkey 7: 51 | Starting items: 79 52 | Operation: new = old + 8 53 | Test: divisible by 19 54 | If true: throw to monkey 4 55 | If false: throw to monkey 5 --------------------------------------------------------------------------------