Code formatting

This commit is contained in:
akp 2020-12-14 19:52:30 +00:00
parent ba24d16664
commit bc46b28ae5
No known key found for this signature in database
GPG key ID: D3E7EAA31B39637E
8 changed files with 38 additions and 22 deletions

25
.github/clocgen.py vendored
View file

@ -4,20 +4,22 @@ import json
import os
import sys
def best_fit(X, Y):
xbar = sum(X)/len(X)
ybar = sum(Y)/len(Y)
n = len(X) # or len(Y)
xbar = sum(X) / len(X)
ybar = sum(Y) / len(Y)
n = len(X) # or len(Y)
numer = sum([xi*yi for xi,yi in zip(X, Y)]) - n * xbar * ybar
denum = sum([xi**2 for xi in X]) - n * xbar**2
numer = sum([xi * yi for xi, yi in zip(X, Y)]) - n * xbar * ybar
denum = sum([xi ** 2 for xi in X]) - n * xbar ** 2
b = numer / denum
a = ybar - b * xbar
return a, b
with open(sys.argv[1], errors="ignore") as f:
cloc_results = json.loads(f.read())
@ -33,7 +35,12 @@ for file in cloc_results["files"]:
continue
split_name = file["name"].split(os.path.sep)
if split_name[-1].lower() not in ["__main__.py", "main.go", "visualise.py", "visualise.go"]:
if split_name[-1].lower() not in [
"__main__.py",
"main.go",
"visualise.py",
"visualise.go",
]:
try:
day_num = int(split_name[0].split("-")[0])
except ValueError:
@ -69,8 +76,10 @@ a, b = best_fit(keys, [go_by_day[key] for key in keys])
yfit = [a + b * xi for xi in days_array]
plt.plot(days_array, yfit, color=golang_colour, linestyle=":")
custom_lines = [Line2D([0], [0], color=python_colour, lw=2),
Line2D([0], [0], color=golang_colour, lw=2)]
custom_lines = [
Line2D([0], [0], color=python_colour, lw=2),
Line2D([0], [0], color=golang_colour, lw=2),
]
plt.legend(custom_lines, ["Python", "Golang"])

12
.github/tablegen.py vendored
View file

@ -33,9 +33,17 @@ for i, l in enumerate(table_lines):
table_lines[i] = f"| {today_day} | ![Not yet attempted][pending] | | |"
rank_lines = "### Personal day-by-day stats\n\n```".split("\n")
r = requests.get("https://adventofcode.com/2020/leaderboard/self", cookies={"session": sys.argv[2]})
r = requests.get(
"https://adventofcode.com/2020/leaderboard/self", cookies={"session": sys.argv[2]}
)
soup = BeautifulSoup(r.text, features="html.parser")
rank_lines += soup.find("article").get_text().split("and 0 otherwise.")[-1].strip("\n").split("\n")
rank_lines += (
soup.find("article")
.get_text()
.split("and 0 otherwise.")[-1]
.strip("\n")
.split("\n")
)
rank_lines += ["```"]
in_rank = False

View file

@ -4,8 +4,8 @@ func PartOne(instr string) int {
instructions := parse(instr)
var (
acc int
pc int
acc int
pc int
visited []int
)
@ -35,7 +35,7 @@ func PartOne(instr string) int {
acc += cir.Operand
case "nop":
}
pc += 1
}

View file

@ -87,7 +87,7 @@ func findChain(adaptors []Adaptor, currentJoltage int) (bool, int, int) {
}
return false, 0, 0
}
func PartOne(instr string) int {
@ -102,13 +102,13 @@ func PartOne(instr string) int {
}
}
}
adaptors = append(adaptors, NewAdaptor(maxJ + 3))
adaptors = append(adaptors, NewAdaptor(maxJ+3))
s, oj, tj := findChain(adaptors, 0)
if s {
return oj * tj
}
}
return 0
}

View file

@ -6,7 +6,7 @@ def partTwo(instr: str) -> int:
total_routes = 0
# Get the route lengths for the three previous joltages
for n in [1, 2, 3]:
total_routes += route_lengths.get(joltage - n, 0)
total_routes += route_lengths.get(joltage - n, 0)
print(joltage, total_routes)
route_lengths[joltage] = total_routes

View file

@ -1,6 +1,5 @@
package challenge
func getNewStateOne(numNeighbours int, oldState rune) rune {
if numNeighbours == 0 {
return filledSeat
@ -24,10 +23,10 @@ func countNeighboursOne(hall [][]rune, currentPos [2]int, hallSize [2]int) (numN
}
}
}
return
}
func PartOne(instr string) int {
return run(parse(instr), countNeighboursOne, getNewStateOne)
}
}

View file

@ -80,7 +80,7 @@ func PartOne(instr string) int {
lat = lat + -2*lat
}
if long < 0 {
long = long + -2 * long
long = long + -2*long
}
return lat + long

View file

@ -126,7 +126,7 @@ func PartTwo(instr string) int {
lat = lat + -2*lat
}
if long < 0 {
long = long + -2 * long
long = long + -2*long
}
return lat + long