Skip to content

Commit

Permalink
minimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Sep 5, 2024
1 parent a34c048 commit 2178244
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions c/src/include/factors.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ void generate_combinations(
const size_t max_combinations
) {
size_t *indices = (size_t *) malloc(num_factors * sizeof(size_t));
for (size_t i = 0; i < num_factors; i++) {
for (size_t i = 0; i < num_factors; i++)
indices[i] = i;
}
size_t batch_index = 0;
while (batch_index < max_combinations) {
uintmax_t product = factors[indices[0]];
for (size_t i = 1; i < num_factors; i++) {
for (size_t i = 1; i < num_factors; i++)
product *= factors[indices[i]];
}
batch[batch_index++] = product;

size_t i = num_factors - 1;
Expand All @@ -43,9 +41,8 @@ void generate_combinations(
i--;
}
indices[i]++;
for (size_t j = i + 1; j < num_factors; j++) {
for (size_t j = i + 1; j < num_factors; j++)
indices[j] = indices[j - 1] + 1;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion cplusplus/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ native_test: native
.PHONY: clean
clean: SHELL := bash
clean:
@rm -rf build dist {.,*,*/*}/{*.pyc,__pycache__,.mypy_cache,.pytest_cache,.benchmarks} || echo
@rm -rf build dist {.,*,*/*{,/*}}/{*.pyc,__pycache__,.mypy_cache,.pytest_cache,.benchmarks} || echo

dist/cp-lib.wasm: build/lib.cpp
@mkdir -p dist
Expand Down

0 comments on commit 2178244

Please sign in to comment.