Skip to content

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Pamblam committed Jan 6, 2018
1 parent e51ebff commit 2420298
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ module.exports = function(grunt) {
'src/factorial.js',
'src/isAbundant.js',
'src/permute.js',
'src/fibonacci.js'
'src/fibonacci.js',
'src/divideInts.js'
],
dest: 'Methodus.js',
},
Expand Down
29 changes: 27 additions & 2 deletions Methodus.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* methodus - v1.0.71
* methodus - v1.0.72
* A Math Library inspired by Project Euler
* @author Pamblam
*/

function Methodus(){
this.version = "1.0.71";
this.version = "1.0.72";
}

if(!!(typeof module !== 'undefined' && module.exports)) module.exports = Methodus;
Expand Down Expand Up @@ -390,4 +390,29 @@ Methodus.prototype.fibonacci = function (funct) {
b = temp;
if (funct(i, b) === false) return;
}
};

Methodus.prototype.divideInts = function(n, d, peren, maxlen) {
var num = n + "",
numLength = num.length,
remainder = 0,
answer = '',
pStack = [],
pattern, i, pIndex, digit;
maxlen = maxlen || 1000000;
for(i=0; i < numLength + maxlen; i++) {
digit = i < numLength ? parseInt(num[i]) : 0;
if (i == numLength) answer = answer + ".";
answer = answer + Math.floor((digit + (remainder * 10)) / d);
remainder = (digit + (remainder * 10)) % d;
pattern = remainder + "," + digit;
pIndex = pStack.indexOf(pattern);
if (pIndex > -1) {
return peren ?
answer.substring(0, pIndex + 1) + "(" + answer.substring(pIndex + 1, answer.length - 1) + ")" :
answer.substring(0, answer.length - 1);
}
pStack.push(pattern);
}
return answer;
};
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

## Methodus.js

**Version 1.0.71** | [NPM](https://www.npmjs.com/package/methodus) | [Github](https://github.com/Pamblam/Methodus)
**Version 1.0.72** | [NPM](https://www.npmjs.com/package/methodus) | [Github](https://github.com/Pamblam/Methodus)

Named after Euler's work which includes 100 problems that Euler considers to illustrate his methods, and was, in all likelihood, part of the inspiration for Project Euler. Thus, the library is an arbitrary list of mathematical algorithms and helper functions that are useful for, among other things, solving the Project Euler problems.

Expand Down Expand Up @@ -36,7 +36,7 @@ Create a new instance with `const m = new Methodus`. The constructor does not ac
| **`m.primeFactors(1233)`** | Will return n array containing the prime factorization of `1233`. |
| **`m.range(3,78)`** | Will return an array of numbers ranging from `3` to `78` |
| **`m.smallestCommonMultiple(123, 32, 12, 32)`** | Will return the smallest common multiple of all the arguments passed to it. You can pass as many arguments as you need. |
| **`m.greatestCommonDivisor(1.0.71)`** | Will return the greatest common divisor of the two numbers passed to it. |
| **`m.greatestCommonDivisor(1.0.72)`** | Will return the greatest common divisor of the two numbers passed to it. |
| **`m.pythagoreanTripletFromCircumference(1000)`** | Will generate a Pythagorean triplet for a triangle whose circumference is 1000. |
| **`m.generateTriangleNumbers(funct)`** | Will call `funct` once for every triangle number until `funct` returns false. The function is provided the index of the triangle number and it's value. |
| **`m.addInts(arr)`** | Will add the large integers in the array `arr` and return the sum. |
Expand All @@ -49,4 +49,5 @@ Create a new instance with `const m = new Methodus`. The constructor does not ac
| **`m.factorial(n)`** | Will return the factorial of `n`. |
| **`m.isAbundant(n)`** | Will return `true` if `n` is an abundant number, else false. |
| **`m.permute(arr, limit)`** | Will all permutations of `arr`, optionally truncating at the given `limit`, if provided. |
| **`m.fibonacci(funct)`** | Will continue to call `funct`, passing it the index of the fibonacci sequence as well as the value at that index (starting at one) until the function returns `false`. |
| **`m.fibonacci(funct)`** | Will continue to call `funct`, passing it the index of the fibonacci sequence as well as the value at that index (starting at one) until the function returns `false`. |
| **`m.divideInts(a, b, perens, limit)`** | Will return the result of `a` divided by `b`. If `perens` is true it will put repeating digits in parentheses. Result is truncated after the first occurrence of repeating digits, or at the number of digits defined by `limit`. |
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "methodus",
"version": "1.0.71",
"version": "1.0.72",
"keywords": [
"Project Euler",
"algorithms",
Expand Down
13 changes: 13 additions & 0 deletions solutions/26.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

const M = require("../Methodus.js");
var lr = 0, i, d, l, m=new M();
for(i=2; i<1000; i++){
d = m.divideInts(1, i, true);
if(d.indexOf("(") > -1){
l = d.match(/\(\d+\)/g)[0].length-2;
if(l > lr){
lr = l;
console.log("New longest: 1/"+i+" ("+l+" repeating) = "+d);
}
}
}
25 changes: 25 additions & 0 deletions src/divideInts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Methodus.prototype.divideInts = function(n, d, peren, maxlen) {
var num = n + "",
numLength = num.length,
remainder = 0,
answer = '',
pStack = [],
pattern, i, pIndex, digit;
maxlen = maxlen || 1000000;
for(i=0; i < numLength + maxlen; i++) {
digit = i < numLength ? parseInt(num[i]) : 0;
if (i == numLength) answer = answer + ".";
answer = answer + Math.floor((digit + (remainder * 10)) / d);
remainder = (digit + (remainder * 10)) % d;
pattern = remainder + "," + digit;
pIndex = pStack.indexOf(pattern);
if (pIndex > -1) {
return peren ?
answer.substring(0, pIndex + 1) + "(" + answer.substring(pIndex + 1, answer.length - 1) + ")" :
answer.substring(0, answer.length - 1);
}
pStack.push(pattern);
}
return answer;
};

0 comments on commit 2420298

Please sign in to comment.