From 2178244d58646fc605723002464303505a115be9 Mon Sep 17 00:00:00 2001 From: Olivia Appleton Date: Wed, 4 Sep 2024 22:05:07 -0500 Subject: [PATCH] minimize code --- c/src/include/factors.h | 9 +++------ cplusplus/Makefile | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/c/src/include/factors.h b/c/src/include/factors.h index ec1585cb..5753a4da 100644 --- a/c/src/include/factors.h +++ b/c/src/include/factors.h @@ -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; @@ -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; - } } } diff --git a/cplusplus/Makefile b/cplusplus/Makefile index 4a9ae6e3..97976920 100644 --- a/cplusplus/Makefile +++ b/cplusplus/Makefile @@ -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