Skip to content

Commit

Permalink
Use different combination lib
Browse files Browse the repository at this point in the history
  • Loading branch information
romellem committed Dec 30, 2024
1 parent 0094da9 commit 06e175f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions 2024/7/part-two.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { input } from './input';
import G from 'generatorics';
import { cartesianProduct } from 'combinatorial-generators';

interface Equation {
result: number;
Expand Down Expand Up @@ -36,7 +36,8 @@ function couldBeTrue({ result, numbers }: Equation): boolean {
// It is OK to fill with the same reference
const spaces: Array<typeof VALID_OPERATIONS> = Array(numbers.length - 1).fill(VALID_OPERATIONS);

for (const operations of G.cartesian(...spaces)) {
for (const operations of cartesianProduct(...spaces)) {
// for (const operations of G.cartesian(...spaces)) {
const evaluation = evaluate(numbers, operations);
if (evaluation === result) {
return true;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dependencies": {
"@thi.ng/bitstream": "^2.1.3",
"colors": "^1.3.3",
"combinatorial-generators": "^1.1.2",
"concurrently": "^6.2.0",
"double-ended-queue": "^2.1.0-0",
"fs-extra": "^10.0.0",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,11 @@ colors@^1.3.3:
resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78"
integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==

combinatorial-generators@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/combinatorial-generators/-/combinatorial-generators-1.1.2.tgz#4be8e54784d799116b33054c7b600088c9ee0bcc"
integrity sha512-3dMye87xRejFz2ZySj1TMIBavMy792v0Dnwzjn8kuxN1tTPKA7Joh3V8i5UyxWJOCmKygSVSClJUeAh6+Cy+1g==

concurrently@^6.2.0:
version "6.2.0"
resolved "https://registry.yarnpkg.com/concurrently/-/concurrently-6.2.0.tgz#587e2cb8afca7234172d8ea55176088632c4c56d"
Expand Down

0 comments on commit 06e175f

Please sign in to comment.