Skip to content

Commit

Permalink
🌱 initial: Move source from primes repository.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Oct 29, 2022
1 parent 9e6b9b2 commit 2e20df2
Show file tree
Hide file tree
Showing 7 changed files with 8,946 additions and 14 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
:question: [@number-theoretic/integers](https://number-theoretic.github.io/integers)
:zzz: [@number-theoretic/integers](https://number-theoretic.github.io/integers)
==

Number theory for integers for JavaScript.
See [docs](https://number-theoretic.github.io/integers/index.html).

> :building_construction: Caveat emptor! This is work in progress. Code may be
> working. Documentation may be present. Coherence may be. Maybe.
> :warning: Depending on your environment, the code may require
> `regeneratorRuntime` to be defined, for instance by importing
> [regenerator-runtime/runtime](https://www.npmjs.com/package/regenerator-runtime).
```js
import * as double from '@arithmetic-type/double';
import {factorizer} from '@number-theoretic/integers';

const factorize = factorizer(double);

[...factorize(999)]; // 3 3 3 37
```

[![License](https://img.shields.io/github/license/number-theoretic/integers.svg)](https://raw.githubusercontent.com/number-theoretic/integers/main/LICENSE)
[![Version](https://img.shields.io/npm/v/@number-theoretic/integers.svg)](https://www.npmjs.org/package/@number-theoretic/integers)
[![Tests](https://img.shields.io/github/workflow/status/number-theoretic/integers/ci?event=push&label=tests)](https://github.com/number-theoretic/integers/actions/workflows/ci.yml?query=branch:main)
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,17 @@
},
"dependencies": {},
"devDependencies": {
"@babel/core": "7.19.3",
"@babel/plugin-transform-destructuring": "7.19.4",
"@arithmetic-type/double": "^5.0.0",
"@babel/core": "7.19.6",
"@babel/plugin-transform-destructuring": "7.20.0",
"@babel/plugin-transform-for-of": "7.18.8",
"@babel/preset-env": "7.19.4",
"@commitlint/cli": "17.1.2",
"@js-library/commitlint-config": "0.0.4",
"@node-loader/babel": "2.0.1",
"@node-loader/core": "2.0.0",
"@node-loader/import-maps": "1.1.0",
"ava": "4.3.3",
"ava": "5.0.1",
"babel-plugin-transform-remove-console": "6.9.4",
"babel-plugin-unassert": "3.2.0",
"babel-preset-power-assert": "3.0.0",
Expand Down
17 changes: 17 additions & 0 deletions src/factorizer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default function factorizer({$2, iadd1, eq0, gt1, divmod}) {
return function* (n) {
let divisor = $2();

while (gt1(n)) {
const [q, r] = divmod(n, divisor);

if (eq0(r)) {
yield divisor;

n = q;
} else {
divisor = iadd1(divisor);
}
}
};
}
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
const answer = 42;
export default answer;
export {default as factorizer} from './factorizer.js';
5 changes: 0 additions & 5 deletions test/src/api.js

This file was deleted.

29 changes: 29 additions & 0 deletions test/src/factorizer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import test from 'ava';

import * as double from '@arithmetic-type/double';

import {factorizer} from '#module';

const factorize = factorizer(double);

const macro = test.macro({
exec(t, n, expected) {
t.deepEqual([...factorize(n)], expected);
},
title(title, n, expected) {
return title ?? `factorize(${n}) = ${JSON.stringify(expected)}`;
},
});

test(macro, 1, []);
test(macro, 2, [2]);
test(macro, 3, [3]);
test(macro, 4, [2, 2]);
test(macro, 5, [5]);
test(macro, 6, [2, 3]);
test(macro, 7, [7]);
test(macro, 8, [2, 2, 2]);
test(macro, 15, [3, 5]);
test(macro, 17, [17]);
test(macro, 999, [3, 3, 3, 37]);
test(macro, 18_848_997_157, [13_729, 1_372_933]);
Loading

0 comments on commit 2e20df2

Please sign in to comment.