Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
diamondburned committed Mar 10, 2024
1 parent d1f41fe commit 7d6063f
Show file tree
Hide file tree
Showing 3 changed files with 1,235 additions and 1,247 deletions.
10 changes: 8 additions & 2 deletions problems/crafting/generate_recipes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ async function main() {
// Get the custom JSON formatting that we want.
let output = "{\n";
for (const [i, recipe] of Object.entries(outputRecipes).entries()) {
const result = JSON.stringify(recipe[0]);
const [first, second] = recipe[1].map((s) => JSON.stringify(s));
const [result, first, second] = [recipe[0], ...recipe[1]]
.map((s) => sanitizeName(s))
.map((s) => JSON.stringify(s));

output += ` ${result}: [${first}, ${second}]`;
output += i === Object.keys(outputRecipes).length - 1 ? "\n" : ",\n";
}
Expand All @@ -63,6 +65,10 @@ async function main() {
// await Deno.writeTextFile(outputRecipesFile, output);
}

function sanitizeName(name: string): string {
return name.toLowerCase().replaceAll("+", "p").replaceAll("=", "?");
}

function arrayEquals<T>(a: T[], b: T[]): boolean {
if (a.length !== b.length) {
return false;
Expand Down
18 changes: 0 additions & 18 deletions problems/crafting/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ def __init__(self, seed=0) -> None:
with open(RECIPES_JSON, "r") as f:
self.recipes = json.loads(f.read())

# Be lazy. I don't care!
self.items.relevant_items = sanitize_names(self.items.relevant_items)
self.items.miscellaneous_items = sanitize_names(self.items.miscellaneous_items)
self.recipes = {
sanitize_name(k): sanitize_names(v) for k, v in self.recipes.items()
}

self.wanted = self.rand.sample(self.items.relevant_items, 6)

def generate_input(self, output: typing.IO | None = None):
Expand All @@ -52,16 +45,5 @@ def part2_answer(self) -> int:
raise NotImplementedError


def sanitize_name(name: str) -> str:
name = name.lower()
name = name.replace("+", "p")
name = name.replace("=", "?")
return name


def sanitize_names(names: list[str]) -> list[str]:
return [sanitize_name(name) for name in names]


if __name__ == "__main__":
problem_utils.main(Problem)
Loading

0 comments on commit 7d6063f

Please sign in to comment.