Skip to content

Commit

Permalink
brain power
Browse files Browse the repository at this point in the history
Co-authored-by: Hayatann <[email protected]>
  • Loading branch information
instructr13 and Hayatann committed Oct 19, 2024
1 parent e14e1f8 commit 75ee993
Show file tree
Hide file tree
Showing 30 changed files with 2,717 additions and 15 deletions.
4 changes: 3 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ insert_final_newline = true
max_line_length = 120
trim_trailing_whitespace = true

[*.rs]
indent_size = 4

[*.md]
trim_trailing_whitespace = false

[*.json]
insert_final_newline = false

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:

- name: Build solver (standalone)
working-directory: apps/solver
run: bun build --minify --sourcemap --compile --bytecode --target=bun-${{ matrix.target }} --outfile=dist/solver-${{ matrix.outfile }} dist/index.js $(find dist -name '*.js' -not -name 'index.js')
run: bun build --minify --sourcemap --compile --bytecode --target=bun-${{ matrix.target }} --outfile=dist/solver-${{ matrix.outfile }} dist/index.js $(find dist -name '*.js' -not -name 'index.js') $(find dist -name '*.wasm')

- name: Build mock server
working-directory: apps/mock-server
Expand Down
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"editor.rulers": [120],
"npm.packageManager": "bun",
"typescript.tsdk": "node_modules/typescript/lib"
"typescript.tsdk": "node_modules/typescript/lib",
"rust-analyzer.linkedProjects": ["${workspaceFolder}/packages/algorithm/src/v3/Cargo.toml"],
"rust-analyzer.cargo.target": "wasm32-unknown-unknown"
}
6 changes: 2 additions & 4 deletions apps/mock-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const validateAnswer = typia.createValidate<Answer>();

const validTokens = new Set(config.teams);

let customProblem: Problem;
let customProblem: Problem | null = null;

const generationSettings: GenerationSettings = {
widthRandom: true,
Expand Down Expand Up @@ -60,8 +60,6 @@ app.use(async (c, next) => {

let lockedDown = true;

const customProblemFlg: boolean = false;

app.post("/customProblem", async (c) => {
customProblem = await c.req.json();

Expand All @@ -75,7 +73,7 @@ app.get("/problem", (c) => {

c.header("X-Data-Maki-Problem-ID", id.toString());

return c.json(customProblemFlg ? customProblem : problem);
return c.json(customProblem ?? problem);
});

app.post("/answer", async (c) => {
Expand Down
4 changes: 3 additions & 1 deletion apps/solver/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ if (!results.success) {

console.log("Copying files...");

const files = await Array.fromAsync(new Glob("../../packages/algorithm/dist/workers/*.worker.js").scan());
const files = await Array.fromAsync(new Glob("../../packages/algorithm/dist/workers/*.worker.js*").scan());
const wasmFiles = await Array.fromAsync(new Glob("../../packages/algorithm/dist/workers/*.wasm").scan());
await mkdirp("./dist/workers");
await copyFiles(files, "./dist/workers");
await copyFiles(wasmFiles, "./dist");

console.timeEnd("Finished building solver");
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions packages/algorithm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@data-maki/biome-config": "workspace:*",
"@data-maki/typescript-config": "workspace:*",
"@vitest/web-worker": "^2.1.2",
"esbuild-plugin-wasm": "^1.1.0",
"tsup": "^8.3.0",
"vitest": "^2.1.2"
}
Expand Down
4 changes: 3 additions & 1 deletion packages/algorithm/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import type { Answer, Problem } from "@data-maki/schemas";
import { solve as solveV1 } from "./workers/v1.master";
import { solve as solveV2 } from "./workers/v2.master";
import { solve as solveV3 } from "./workers/v3.master";

export { easyKatanuki } from "./katanuki";

export const VERSIONS = ["v1", "v2"] as const;
export const VERSIONS = ["v1", "v2", "v3"] as const;

const solveFuncs: { [key in (typeof VERSIONS)[number]]: SolveFunc } = {
v1: solveV1,
v2: solveV2,
v3: solveV3,
};

export const isSolveFuncVersion = (version: string): version is (typeof VERSIONS)[number] =>
Expand Down
2 changes: 1 addition & 1 deletion packages/algorithm/src/models/pattern.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type General, type Pattern, fixedPatterns as fixedPatterns_ } from "@data-maki/schemas";
import { type Pattern, fixedPatterns as fixedPatterns_ } from "@data-maki/schemas";
import { TwoDimensionalCells } from "../utils/arrays";

export interface InternalPattern {
Expand Down
6 changes: 1 addition & 5 deletions packages/algorithm/src/utils/arrays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ export class TwoDimensionalCells {
return this.#inner.length;
}

[Symbol.iterator]() {
return this.#inner[Symbol.iterator]();
}

equals(other: TwoDimensionalCells) {
for (let i = 0; i < this.#inner.length; i++) {
if (this.#inner[i] !== other.#inner[i]) {
Expand Down Expand Up @@ -159,7 +155,7 @@ export class TwoDimensionalCells {
transposeInPlace() {
this.#inner = this.#transposeInner();

const tmp = this.width;
const tmp = this.height;
this.height = this.width;
this.width = tmp;

Expand Down
21 changes: 21 additions & 0 deletions packages/algorithm/src/v3.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { describe, expect, test } from "bun:test";
import type { Answer, Problem } from "@data-maki/schemas";
import typia from "typia";
import dataExample from "../examples/input.json";
import { solve } from "./workers/v3.master";

describe("algorithm v3 tests", () => {
let problem: Problem;
let answer: Answer;

test("example data correctly solves", async () => {
problem = typia.assert<Problem>(dataExample);

const expected = problem.board.goal;
const [actualAnswer, actual] = await solve(structuredClone(problem));

answer = actualAnswer;

expect(actual).toStrictEqual(expected);
});
});
199 changes: 199 additions & 0 deletions packages/algorithm/src/v3/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions packages/algorithm/src/v3/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "algorithm-v3-wasm"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib", "rlib"]

[profile.release]
lto = "thin"
opt-level = 3

[dependencies]
js-sys = "0.3.72"
once_cell = "1.20.2"
serde = { version = "1.0", features = ["derive"] }
ts-bindgen-rt = "0.5.0"
wasm-bindgen = "0.2.95"
1 change: 1 addition & 0 deletions packages/algorithm/src/v3/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { solve } from "./pkg";
Loading

0 comments on commit 75ee993

Please sign in to comment.