Skip to content

Commit 71d2a32

Browse files
committed
Massive push of all chaotic code
1 parent 241cba5 commit 71d2a32

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+3191
-106
lines changed

.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/adventofcode.iml

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

2015/assignments/day09.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
**--- Day 9: All in a Single Night ---**
2+
3+
Every year, Santa manages to deliver all of his presents in a single night.
4+
5+
This year, however, he has some new locations to visit; his elves have provided him the distances between every pair of locations. He can start and end at any two (different) locations he wants, but he must visit each location exactly once. What is the shortest distance he can travel to achieve this?
6+
7+
For example, given the following distances:
8+
9+
London to Dublin = 464
10+
London to Belfast = 518
11+
Dublin to Belfast = 141
12+
13+
The possible routes are therefore:
14+
15+
Dublin -> London -> Belfast = 982
16+
London -> Dublin -> Belfast = 605
17+
London -> Belfast -> Dublin = 659
18+
Dublin -> Belfast -> London = 659
19+
Belfast -> Dublin -> London = 605
20+
Belfast -> London -> Dublin = 982
21+
22+
The shortest of these is London -> Dublin -> Belfast = 605, and so the answer is 605 in this example.
23+
24+
*What is the distance of the shortest route?*
25+
26+
**--- Part Two ---**
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

2015/assignments/day6.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
**--- Day 6: Probably a Fire Hazard ---**
2+
3+
Because your neighbors keep defeating you in the holiday house decorating contest year after year, you've decided to deploy one million lights in a 1000x1000 grid.
4+
5+
Furthermore, because you've been especially nice this year, Santa has mailed you instructions on how to display the ideal lighting configuration.
6+
7+
Lights in your grid are numbered from 0 to 999 in each direction; the lights at each corner are at 0,0, 0,999, 999,999, and 999,0. The instructions include whether to turn on, turn off, or toggle various inclusive ranges given as coordinate pairs. Each coordinate pair represents opposite corners of a rectangle, inclusive; a coordinate pair like 0,0 through 2,2 therefore refers to 9 lights in a 3x3 square. The lights all start turned off.
8+
9+
To defeat your neighbors this year, all you have to do is set up your lights by doing the instructions Santa sent you in order.
10+
11+
For example:
12+
13+
turn on 0,0 through 999,999 would turn on (or leave on) every light.
14+
toggle 0,0 through 999,0 would toggle the first line of 1000 lights, turning off the ones that were on, and turning on the ones that were off.
15+
turn off 499,499 through 500,500 would turn off (or leave off) the middle four lights.
16+
17+
*After following the instructions, how many lights are lit?*
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

2015/solutionsPython/day02.py

-30
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1+
# Imports -----------------------------------------------------------------
2+
import numpy as np
3+
14
# Day 1 - Part 1 ----------------------------------------------------------
2-
with open("2015/data/day01.txt") as data:
3-
aoc_input = data.read()
5+
with open("2015/data/day1.txt") as file:
6+
inp = file.read()
47

5-
print(sum(+1 if inst == "(" else -1 for inst in aoc_input))
8+
print(sum(+1 if inst == "(" else -1 for inst in inp))
69

710
# one-liner using the ternary operator and the fact that python can evaluate
811
# int +1+1+1-1 as 2 implicitly
912

1013
# Day 1 - Part 2 ----------------------------------------------------------
11-
with open("2015/data/day01.txt") as data:
12-
aoc_input = data.read()
14+
with open("2015/data/day1.txt") as file:
15+
inp = file.read()
1316

1417
floor, pos = 0, 0 # position would be 1, but python iterates from 0
15-
for inst in aoc_input:
18+
for inst in inp:
1619
if floor == -1:
1720
print(pos)
1821
break
@@ -24,3 +27,7 @@
2427
pos += 1
2528

2629
print(pos)
30+
31+
# one-liner alternative with numpy
32+
33+
np.cumsum([+1 if inst == "(" else -1 for inst in inp]).tolist().index(-1)

2015/solutionsPython/day2.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Day 2 - Part 1 ----------------------------------------------------------
2+
with open("2015/data/day2.txt") as file:
3+
inp = [line.strip("\n").split("x") for line in file]
4+
5+
inp = [sorted([int(j) for j in i]) for i in inp]
6+
7+
sides = [2*gift[0]*gift[1] + 2*gift[1]*gift[2] + 2*gift[2]*gift[0] for gift in inp]
8+
extra = [gift[0] * gift[1] for gift in inp]
9+
wrapper = [sides[i] + extra[i] for i in range(len(sides))]
10+
11+
sum(wrapper)
12+
13+
# Day 2 - Part 2 ----------------------------------------------------------
14+
with open("2015/data/day2.txt") as file:
15+
inp = [line.strip("\n").split("x") for line in file]
16+
17+
inp = [sorted([int(j) for j in i]) for i in inp]
18+
dist = [gift[0]*2 + gift[1]*2 for gift in inp]
19+
bow = [gift[0]*gift[1]*gift[2] for gift in inp]
20+
21+
ribbon = [dist[i] + bow[i] for i in range(len(dist))]
22+
23+
sum(ribbon)

2015/solutionsPython/day03.py renamed to 2015/solutionsPython/day3.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
coord_s = (0, 0) # santa's initial coords
3232
coord_rs = (0, 0) # robo-santa's initial coords
3333
coords = set() # create a set (unique values only)
34-
coords.add((0,0)) # add the initial position. It's (0,0) for both, so adding once is enough
34+
coords.add((0, 0)) # add the initial position. It's (0,0) for both, so adding once is enough
3535

3636
for i, x in enumerate(aoc_input):
3737
n = char.index(x) # n is the index of the currently iterated command

2015/solutionsPython/day5.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Day 5 - Part 1 ----------------------------------------------------------
2+
3+
with open("2015/data/day5.txt") as file:
4+
inp = [line.strip("\n") for line in file]
5+

2015/solutionsPython/day6.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Imports -----------------------------------------------------------------
2+
from dis import Instruction
3+
import numpy as np
4+
import json
5+
6+
# Day 6 - Part 1 ----------------------------------------------------------
7+
8+
with open("2015/data/day6.txt") as file:
9+
inp = [line.strip("\n")
10+
.removeprefix("turn ")
11+
.replace(" through ", " ")
12+
.split(" ") for line in file]
13+
14+
grid = np.zeros((1000, 1000))
15+
16+
for instruction in inp:
17+
start = np.array(json.loads("[" + instruction[1] + "]"))
18+
end = np.array(json.loads("[" + instruction[2] + "]"))
19+
coords = []
20+
match instruction[0]:
21+
case "on":
22+
grid[coords[0], coords[1]] = 1
23+
case "off":
24+
grid[coords[0], coords[1]] = 0
25+
case "toggle":
26+
if grid[coords[0], coords[1]] == 0:
27+
grid[coords[0], coords[1]] == 1
28+
else:
29+
grid[coords[0], coords[1]] == 0
30+
31+
32+
grid.sum()

2015/solutionsR/day06.R

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Day 7 - Part 1 ----------------------------------------------------------
2+
3+
input <- readLines("2015/data/day06.txt", warn = F) # load the data
4+
input <- trimws(gsub("turn", "", input))
5+
input <- strsplit(input, " |,")
6+
input <- as.data.frame(matrix(data = do.call(rbind, input), ncol = 6))
7+
8+
grid <- matrix(0, 1000,1000)
9+
10+
switch <- function(x) {
11+
12+
if (x[1] == "on") {
13+
grid[x[2]:x[5], x[3]:x[6]] <- 1
14+
} else if (x[1] == "off") {
15+
grid[x[2]:x[5], x[3]:x[6]] <- 0
16+
} else {
17+
grid[x[2]:x[5], x[3]:x[6]] <- ifelse(grid[x[2]:x[5], x[3]:x[6]] == 0, 1, 0)
18+
}
19+
20+
return(grid)
21+
22+
}
23+
24+
apply(input, 1, switch)
25+
26+
switch(input[,1])
27+
28+
# Day 7 - Part 2 ----------------------------------------------------------
29+
30+

2015/solutionsR/day09.R

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Day 9 - Part 1 ----------------------------------------------------------
2+
3+
input <- readLines("2015/data/day09.txt", warn = F)
4+
input <- strsplit(input, "( to )|( = )")
5+
input <- data.frame(do.call(rbind, input))
6+
names(input) <- c("from", "to", "dist")
7+
input$dist <- as.integer(input$dist)
8+
input$fromto <- paste0(input$from, input$to)
9+
10+
#matrix
11+
names <- sort(unique(c(unique(input$from), unique(input$to))))
12+
matrix(input$dist, length(input$dist)/2, length(input$dist)/2)
13+
14+
15+
M <- matrix(,8,8)
16+
17+
# Day 9 - Part 2 ----------------------------------------------------------
18+
19+
20+
x <- matrix(rnorm(100), nrow = 5)
21+
dist(x)

2015/solutionsR/day01.R renamed to 2015/solutionsR/day1.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Day 1 - Part 1 ----------------------------------------------------------
22

3-
input <- readLines("2015/data/day01.txt", warn = F) # load the data
3+
input <- readLines("2015/data/day1.txt", warn = F) # load the data
44

55
# rule - trying to avoid looping
66

@@ -13,7 +13,7 @@ sum(input) # sum of +1s and -1s reveals the answer/
1313

1414
# Day 1 - Part 2 ----------------------------------------------------------
1515

16-
input <- readLines("2015/data/day01.txt", warn = F)
16+
input <- readLines("2015/data/day1.txt", warn = F)
1717

1818
# rule - trying to avoid looping
1919

2015/solutionsR/day10.R

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Day 10 - Part 1 ---------------------------------------------------------
2+
3+
input <- readLines("2015/data/day10.txt", warn = F)
4+
5+
6+
looknsay <- function(input, times = 1) {
7+
8+
9+
10+
}
11+
12+
answer <- looknsay(input, 40)
13+
answer
14+
15+
16+
# Day 10 - Part 2 ---------------------------------------------------------
17+
18+
19+
20+
21+
# Day 10 - Visualize ------------------------------------------------------
File renamed without changes.

2016/R/README.md

-1
This file was deleted.

2016/README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
#placeholder
1+
# 🎄 Advent of Code 2016 🎁
2+
3+
| Assignment | Data | Solution R | Solution Python | Solution C++ | Part 1 | Part 2 |
4+
|-------|---|---|---|---|:-:|:-:|
5+
| [Day 1](https://adventofcode.com/2016/day/1) | [Data](data/day1.txt) | [R - D1](solutionsR/day1.R) | | |||
6+
7+
8+
### Notes
9+
Every day's assignment links to the AOC website. However, just in case, the assignments are backed up in the *assignments* folder. The input data generated by the website is not the same for everyone. The inputs generated for me are stored in the *data* folder.
10+
11+
![https://adventofcode.com/2016](aoc2016.png)

2016/assignments/day1.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
**--- Day 1: No Time for a Taxicab ---**
2+
3+
Santa's sleigh uses a very high-precision clock to guide its movements, and the clock's oscillator is regulated by stars. Unfortunately, the stars have been stolen... by the Easter Bunny. To save Christmas, Santa needs you to retrieve all fifty stars by December 25th.
4+
5+
Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
6+
7+
You're airdropped near Easter Bunny Headquarters in a city somewhere. "Near", unfortunately, is as close as you can get - the instructions on the Easter Bunny Recruiting Document the Elves intercepted start here, and nobody had time to work them out further.
8+
9+
The Document indicates that you should start at the given coordinates (where you just landed) and face North. Then, follow the provided sequence: either turn left (L) or right (R) 90 degrees, then walk forward the given number of blocks, ending at a new intersection.
10+
11+
There's no time to follow such ridiculous instructions on foot, though, so you take a moment and work out the destination. Given that you can only walk on the street grid of the city, how far is the shortest path to the destination?
12+
13+
For example:
14+
15+
- Following R2, L3 leaves you 2 blocks East and 3 blocks North, or 5 blocks away.
16+
- R2, R2, R2 leaves you 2 blocks due South of your starting position, which is 2 blocks away.
17+
- R5, L5, R5, R3 leaves you 12 blocks away.
18+
19+
How many blocks away is Easter Bunny HQ?
20+
21+
**--- Part Two ---**
22+

0 commit comments

Comments
 (0)