Code formatting
This commit is contained in:
parent
ba24d16664
commit
bc46b28ae5
8 changed files with 38 additions and 22 deletions
25
.github/clocgen.py
vendored
25
.github/clocgen.py
vendored
|
@ -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
12
.github/tablegen.py
vendored
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue