Skip to content

Commit

Permalink
Merge pull request #481 from icecream17/setmethods
Browse files Browse the repository at this point in the history
  • Loading branch information
icecream17 authored Sep 20, 2024
2 parents d45a17f + aaaa3ad commit 5c753e7
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
node-version: '>=22'
cache: yarn

- run: yarn install
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Note: Many earlier versions are not specified, that's too much work.

When a `@types` dependency updates, they almost always don't affect anything.

## v0.36.2

- (code) Use new Set methods, simplifies code. This shouldn't break support for old browsers.

## v0.36.1

- (css) Fix explanation changing the size of Aside
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ You can run `yarn install` and then `yarn npm audit` for the full report.

## Node version

This project does not seem to use node, but just in case, this uses `String.prototype.replaceAll`, so your node version must be `>=15.0.0`.
This project does not seem to use node, but just in case, this uses `Set.prototype.isSubsetOf`, so your node version must be `>=22.0.0`.

Also, `@types/node` is usually on one of the latest versions, since github actions eventually deprecates old versions of node. If `@types/node` is incompatible with an earlier version of node, you can try downgrading the dependency, or post an issue if it doesn't work. Alternatively, if you're on gitpod run `nvm install 16` or higher.
11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "solver",
"version": "0.36.1",
"version": "0.36.2",
"private": true,
"homepage": "https://icecream17.github.io/solver",
"dependencies": {
Expand All @@ -17,7 +17,7 @@
},
"devDependencies": {
"@types/jest": "^27.0.2",
"@types/node": "^20.0.0",
"@types/node": "^22.0.0",
"@types/react": "^17.0.34",
"@types/react-dom": "^17.0.11",
"eslint-plugin-jest-dom": "^4.0.0",
Expand All @@ -39,10 +39,7 @@
},
"browserslist": {
"production": [
"supports prefers-color-scheme",
"not ios_saf < 14.5",
"not safari < 14.1",
"not firefox < 90",
"last 1 year",
"not dead"
],
"development": [
Expand All @@ -52,7 +49,7 @@
]
},
"engines": {
"node": ">=15.0.0"
"node": ">=22.0.0"
},
"packageManager": "[email protected]"
}
6 changes: 3 additions & 3 deletions src/Api/Strategies/pairCoversGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ function _checkPair(
// ^ group [sees A or B] [has A or B]
// Avoid eliminating everything
if (group_A.size === 0) {
const [groupIndex] = groupInfo(prop, [...group_A])
const [groupIndex] = groupInfo(prop, group_A)
window._custom.alert(`${prop} ${GRP_NAMES[prop][groupIndex]} has no possibilities for ${candidateA} !`)
return "error"
}

// Condition 2: The two cells see all cells in the group that have A.
if (isSubset(group_A, affectsEitherAorB)) {
if (group_A.isSubsetOf(affectsEitherAorB)) {
// Elimination type A
const [, allOfGroup, remaining] = groupInfo(prop, [...group_A])
const [, allOfGroup, remaining] = groupInfo(prop, group_A)

// Strategy does not work when X or Y is in the group
if (allOfGroup.includes(cellA) || allOfGroup.includes(cellB)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Api/Strategies/twoMinusOneLines.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ALL_CANDIDATES, IndexToNine, INDICES_TO_NINE, SudokuDigits } from "../../Types";
import PureSudoku from "../Spaces/PureSudoku";
import { affects, CellID, setDifference, sharedInArrays } from "../Utils";
import { affects, CellID, sharedInArrays } from "../Utils";
import { colorGroup } from "../Utils.dependent";
import { __incrementMapValue } from "./skyscraper";

Expand Down Expand Up @@ -101,7 +101,7 @@ export function _innerGroupSubtractionLogic(

if (successcount) {
const nonExtraLineCells = __inLine(sumLines, nonExtraLine as IndexToNine, pendLineProp)
const extraCells = setDifference(sumLines, nonExtraLineCells)
const extraCells = sumLines.difference(nonExtraLineCells)
colorGroup(sudoku, extraCells, candidate, "orange")
colorGroup(sudoku, nonExtraLineCells, candidate)
return {
Expand Down
18 changes: 14 additions & 4 deletions src/Api/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,32 @@ export function getIDFromIndexWithinBox(indexOfBox: IndexToNine, indexInBox: Ind
return id(boxRow * 3 + withinRow as IndexToNine, boxColumn * 3 + withinColumn as IndexToNine)
}

export function groupInfo(type: GrpTyp, cells: CellID[]) {
function elementInIterable<T>(iter: Iterable<T>): T | undefined {
for (const elem of iter) {
return elem
}
}

/**
* @param cells A nonempty iterable of `CellID`
*/
export function groupInfo(type: GrpTyp, cells: Iterable<CellID>) {
let groupIndex: IndexToNine
let cellsInGroup
const arbitraryCell = elementInIterable(cells) as CellID // If it is undefined, it will error at runtime
switch (type) {
case "row": {
groupIndex = cells[0].row
groupIndex = arbitraryCell.row
cellsInGroup = INDICES_TO_NINE.map(indice => id(groupIndex, indice))
break
}
case "column": {
groupIndex = cells[0].column
groupIndex = arbitraryCell.column
cellsInGroup = INDICES_TO_NINE.map(indice => id(indice, groupIndex))
break
}
case "box": {
groupIndex = boxAt(cells[0].row, cells[0].column)
groupIndex = boxAt(arbitraryCell.row, arbitraryCell.column)
cellsInGroup = INDICES_TO_NINE.map(indice => getIDFromIndexWithinBox(groupIndex, indice))
break
}
Expand Down
2 changes: 1 addition & 1 deletion src/Elems/Version.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import StaticComponent from './StaticComponent';
* <Version />
*/
function Version () {
return <span className="Version">v0.36.1</span>
return <span className="Version">v0.36.2</span>
}

export default StaticComponent(Version)
25 changes: 9 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3822,12 +3822,12 @@ __metadata:
languageName: node
linkType: hard

"@types/node@npm:^20.0.0":
version: 20.16.5
resolution: "@types/node@npm:20.16.5"
"@types/node@npm:^22.0.0":
version: 22.5.5
resolution: "@types/node@npm:22.5.5"
dependencies:
undici-types: ~6.19.2
checksum: f38b7bd8c4993dcf38943afa2ffdd7dfd18fc94f8f3f28d0c1045a10d39871a6cc1b8f8d3bf0c7ed848457d0e1d283482f6ca125579c13fed1b7575d23e8e8f5
checksum: 1f788966ff7df07add0af3481fb68c7fe5091cc72a265c671432abb443788ddacca4ca6378af64fe100c20f857c4d80170d358e66c070171fcea0d4adb1b45b1
languageName: node
linkType: hard

Expand Down Expand Up @@ -5335,17 +5335,10 @@ __metadata:
languageName: node
linkType: hard

"caniuse-lite@npm:^1.0.0, caniuse-lite@npm:^1.0.30001259, caniuse-lite@npm:^1.0.30001272, caniuse-lite@npm:^1.0.30001280":
version: 1.0.30001651
resolution: "caniuse-lite@npm:1.0.30001651"
checksum: c31a5a01288e70cdbbfb5cd94af3df02f295791673173b8ce6d6a16db4394a6999197d44190be5a6ff06b8c2c7d2047e94dfd5e5eb4c103ab000fca2d370afc7
languageName: node
linkType: hard

"caniuse-lite@npm:^1.0.30001646":
version: 1.0.30001653
resolution: "caniuse-lite@npm:1.0.30001653"
checksum: 289cf06c26a46f3e6460ccd5feffa788ab0ab35d306898c48120c65cfb11959bfa560e9f739393769b4fd01150c69b0747ad3ad5ec3abf3dfafd66df3c59254e
"caniuse-lite@npm:^1.0.0, caniuse-lite@npm:^1.0.30001259, caniuse-lite@npm:^1.0.30001272, caniuse-lite@npm:^1.0.30001280, caniuse-lite@npm:^1.0.30001646":
version: 1.0.30001662
resolution: "caniuse-lite@npm:1.0.30001662"
checksum: 7a6a0c0d9f7c4a1c51de02838eb47f41f36fff57a77b846c8faed35ba9afba17b9399bc00bd637e5c1663cbc132534085d91151de48edca2ad8932a5d87e23af
languageName: node
linkType: hard

Expand Down Expand Up @@ -13394,7 +13387,7 @@ resolve@^2.0.0-next.3:
"@testing-library/react": ^12.1.2
"@testing-library/user-event": ^13.5.0
"@types/jest": ^27.0.2
"@types/node": ^20.0.0
"@types/node": ^22.0.0
"@types/react": ^17.0.34
"@types/react-dom": ^17.0.11
eslint-plugin-jest-dom: ^4.0.0
Expand Down

0 comments on commit 5c753e7

Please sign in to comment.