@gkucmierz/utils 1.17.0 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/main.mjs CHANGED
@@ -20,6 +20,9 @@ import {
20
20
  import {
21
21
  getType
22
22
  } from './src/get-type.mjs'
23
+ import {
24
+ gpn, gpnBI
25
+ } from './src/gpn.mjs'
23
26
  import {
24
27
  heronsFormula, heronsFormulaBI
25
28
  } from './src/herons-formula.mjs'
@@ -52,6 +55,7 @@ export * from './src/egcd.mjs';
52
55
  export * from './src/factors.mjs';
53
56
  export * from './src/gcd.mjs';
54
57
  export * from './src/get-type.mjs';
58
+ export * from './src/gpn.mjs';
55
59
  export * from './src/herons-formula.mjs';
56
60
  export * from './src/lcm.mjs';
57
61
  export * from './src/mod.mjs';
@@ -62,5 +66,5 @@ export * from './src/square-root.mjs';
62
66
  export * from './src/tonelli-shanks.mjs';
63
67
 
64
68
  export default [
65
- SetCnt, fromBase64, fromBase64Url, toBase64, toBase64Url, bijective2num, bijective2numBI, num2bijective, num2bijectiveBI, egcd, factors, factorsBI, gcd, gcdBI, getType, heronsFormula, heronsFormulaBI, lcm, lcmBI, mod, modBI, phi, phiBI, powMod, powModBI, array2range, range2array, squareRoot, squareRootBI, tonelliShanksBI
69
+ SetCnt, fromBase64, fromBase64Url, toBase64, toBase64Url, bijective2num, bijective2numBI, num2bijective, num2bijectiveBI, egcd, factors, factorsBI, gcd, gcdBI, getType, gpn, gpnBI, heronsFormula, heronsFormulaBI, lcm, lcmBI, mod, modBI, phi, phiBI, powMod, powModBI, array2range, range2array, squareRoot, squareRootBI, tonelliShanksBI
66
70
  ];
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@gkucmierz/utils",
3
- "version": "1.17.0",
3
+ "version": "1.18.0",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@gkucmierz/utils",
9
- "version": "1.17.0",
9
+ "version": "1.18.0",
10
10
  "license": "MIT",
11
11
  "devDependencies": {
12
12
  "husky": "^8.0.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gkucmierz/utils",
3
- "version": "1.17.0",
3
+ "version": "1.18.0",
4
4
  "description": "Usefull functions for solving programming tasks",
5
5
  "main": "main.mjs",
6
6
  "scripts": {
@@ -0,0 +1,35 @@
1
+
2
+ import {
3
+ gpn,
4
+ gpnBI,
5
+ } from '../src/gpn.mjs';
6
+
7
+ describe('gpn', () => {
8
+ it('first terms', () => {
9
+ expect(gpn(0)).toBe(0);
10
+ expect(gpn(1)).toBe(1);
11
+ expect(gpn(2)).toBe(2);
12
+ expect(gpn(3)).toBe(5);
13
+ expect(gpn(4)).toBe(7);
14
+ expect(gpn(5)).toBe(12);
15
+ expect(gpn(6)).toBe(15);
16
+ expect(gpn(7)).toBe(22);
17
+ expect(gpn(8)).toBe(26);
18
+ expect(gpn(9)).toBe(35);
19
+ });
20
+ });
21
+
22
+ describe('gpn BI', () => {
23
+ it('first terms', () => {
24
+ expect(gpnBI(0n)).toBe(0n);
25
+ expect(gpnBI(1n)).toBe(1n);
26
+ expect(gpnBI(2n)).toBe(2n);
27
+ expect(gpnBI(3n)).toBe(5n);
28
+ expect(gpnBI(4n)).toBe(7n);
29
+ expect(gpnBI(5n)).toBe(12n);
30
+ expect(gpnBI(6n)).toBe(15n);
31
+ expect(gpnBI(7n)).toBe(22n);
32
+ expect(gpnBI(8n)).toBe(26n);
33
+ expect(gpnBI(9n)).toBe(35n);
34
+ });
35
+ });
package/src/gpn.mjs ADDED
@@ -0,0 +1,14 @@
1
+
2
+ // Generalized pentagonal numbers
3
+ // https://oeis.org/A001318
4
+
5
+ const getGpn = (zero, one, two, three) => {
6
+ const gk = k => k * (three * k - one) / two;
7
+ return n => {
8
+ const m = (n + one) / two | zero;
9
+ return n % two === zero ? gk(-m) : gk(m);
10
+ };
11
+ };
12
+
13
+ export const gpn = getGpn(0, 1, 2, 3);
14
+ export const gpnBI = getGpn(0n, 1n, 2n, 3n);