Skip to content

Commit

Permalink
Solve p21 in js, attempt table sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Sep 3, 2024
1 parent e7954b7 commit a0c039c
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 6 deletions.
5 changes: 4 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ Olivia's Project Euler Solutions
.. |pcc| replace:: ``pcc``
.. |tcc| replace:: ``tcc``

.. table::
:class: datatable

+------------+----------------------------+--------+-------------------+
| Language | Version | Solved | Status |
+============+============================+========+===================+
Expand All @@ -78,7 +81,7 @@ Olivia's Project Euler Solutions
| | Microsoft, Oracle, |br| | | |CodeQL| |br| |
| | Semeru, Temurin, & Zulu | | |Java-lint| |
+------------+----------------------------+--------+-------------------+
| JavaScript | Node 12+ |br| | 32 | |JavaScript| |br| |
| JavaScript | Node 12+ |br| | 33 | |JavaScript| |br| |
| | Bun 1.0+ |br| | | |Js-Cov| |br| |
| | Browser [#]_ | | |CodeQL| |br| |
| | | | |ESLint| |
Expand Down
3 changes: 3 additions & 0 deletions docs/_static/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$(document).ready( function () {
$('table.datatable').DataTable();
} );
9 changes: 8 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,14 @@

html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']
html_css_files = ['style.css']
html_css_files = [
'https://cdn.datatables.net/1.10.23/css/jquery.dataTables.min.css',
'style.css'
]
html_js_files = [
'https://cdn.datatables.net/1.10.23/js/jquery.dataTables.min.js',
'main.js',
]

# -- Options for autodoc extension -------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#configuration
Expand Down
6 changes: 3 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ Problems Solved
| |s| |Done, but slower than 60 seconds|
+------+--------------------------------+

.. rst-class:: centertable
.. table::
:class: datatable centertable

+-----------+------------+------------+------------+------------+------------+------------+------------+
| | |C| | |Cp| | |C#| | |Ja| | |Js| | |Py| | |Rs| |
Expand All @@ -75,7 +76,6 @@ Problems Solved
+-----------+------------+------------+------------+------------+------------+------------+------------+
| Browser | |ip| | |ip| | | | |d| | |d| | |d| |
+-----------+------------+------------+------------+------------+------------+------------+------------+
+-----------+------------+------------+------------+------------+------------+------------+------------+
|:prob:`1` |:c-d:`0001` |:cp-d:`0001`|:cs-d:`0001`|:ja-d:`0001`|:js-d:`0001`|:py-d:`0001`|:rs-d:`0001`|
+-----------+------------+------------+------------+------------+------------+------------+------------+
|:prob:`2` |:c-d:`0002` |:cp-d:`0002`|:cs-d:`0002`|:ja-d:`0002`|:js-d:`0002`|:py-d:`0002`|:rs-d:`0002`|
Expand Down Expand Up @@ -116,7 +116,7 @@ Problems Solved
+-----------+------------+------------+------------+------------+------------+------------+------------+
|:prob:`20` |:c-d:`0020` |:cp-d:`0020`|:cs-d:`0020`|:ja-d:`0020`|:js-d:`0020`|:py-d:`0020`|:rs-d:`0020`|
+-----------+------------+------------+------------+------------+------------+------------+------------+
|:prob:`21` | | | | | |:py-d:`0021`|:rs-i:`0021`|
|:prob:`21` | | | | |:js-d:`0021`|:py-d:`0021`|:rs-i:`0021`|
+-----------+------------+------------+------------+------------+------------+------------+------------+
|:prob:`22` |:c-d:`0022` |:cp-d:`0022`|:cs-d:`0022`|:ja-d:`0022`|:js-d:`0022`|:py-d:`0022`|:rs-d:`0022`|
+-----------+------------+------------+------------+------------+------------+------------+------------+
Expand Down
20 changes: 20 additions & 0 deletions docs/src/javascript/p0021.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
JavaScript Implementation of Problem 21
=======================================

Includes
--------

- `factors <./lib/factors.html>`_

Problem Solution
----------------

View source code :source:`javascript/src/p0021.js`

.. js:autofunction:: p0021

.. literalinclude:: ../../../javascript/src/p0021.js
:language: javascript
:linenos:

.. tags:: divisor-sum, prime-number, factorization, divisibility, js-iterator
2 changes: 1 addition & 1 deletion docs/src/rust/p0021.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Problem Solution
:language: rust
:linenos:

.. tags:: large-numbers, digit-sum, factorial
.. tags:: divisor-sum, prime-number, factorization, divisibility, rust-iterator
1 change: 1 addition & 0 deletions javascript/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Problems Solved
- ☒ `18 <./src/p0019.js>`__
- ☒ `19 <./src/p0019.js>`__
- ☒ `20 <./src/p0020.js>`__
- ☒ `21 <./src/p0021.js>`__
- ☒ `22 <./src/p0022.js>`__
- ☒ `23 <./src/p0023.js>`__
- ☒ `27 <./src/p0027.js>`__
Expand Down
1 change: 1 addition & 0 deletions javascript/euler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const answers = {
18: [require('./src/p0018.js'), false],
19: [require('./src/p0019.js'), false],
20: [require('./src/p0020.js'), false],
21: [require('./src/p0021.js'), false],
22: [require('./src/p0022.js'), false],
23: [require('./src/p0023.js'), false],
27: [require('./src/p0027.js'), false],
Expand Down
30 changes: 30 additions & 0 deletions javascript/src/p0021.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Project Euler Problem 21
*
* Problem:
* @return {number}
*/
exports.p0021 = function() {
let answer = 0;
const toCheck = Array.from(...Array(10000).keys());
for (const a of toCheck) {
const b = d(a);
if (a !== b && d(b) === a) {
answer += a + b;
if (b < 10000) {
toCheck.splice(toCheck.find(b), 1);
}
}
}
return answer;
};

/**
* @param {number} i
* @return {number}
*/
function d(i) {
return Array.from(factors.properDivisors(i)).reduce((x, y) => x + y, 0);
}

const factors = require('./lib/factors');

0 comments on commit a0c039c

Please sign in to comment.