Created
October 12, 2012 03:10
-
-
Save weisjohn/3877079 to your computer and use it in GitHub Desktop.
Pseudo Non-Terminating Decimal Represenation of a Rational Number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function test_pntdrrn_regex(pattern, sample, dividend, divisor) { | |
console.log( | |
dividend + "/" + divisor + "\t\t" + | |
pattern.toString() + | |
( pattern.test(sample) ? "" : " doesn't" ) + " match" + | |
( pattern.test(sample) ? "es " : " " ) + | |
"`" + sample + "`" | |
); | |
} | |
// Pseudo Non-Terminating Decimal Represenation of a Rational Number | |
var pntdrrn = /\d{5,}/; | |
for (var i = 1; i < 10; i++) { | |
for (var j = 1; j <= i-1; j++) { | |
test_pntdrrn_regex(pntdrrn, (j/i) + "", j, i); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
1/2 /\d{5,}/ doesn't match `0.5` | |
1/3 /\d{5,}/ matches `0.3333333333333333` | |
2/3 /\d{5,}/ matches `0.6666666666666666` | |
1/4 /\d{5,}/ doesn't match `0.25` | |
2/4 /\d{5,}/ doesn't match `0.5` | |
3/4 /\d{5,}/ doesn't match `0.75` | |
1/5 /\d{5,}/ doesn't match `0.2` | |
2/5 /\d{5,}/ doesn't match `0.4` | |
3/5 /\d{5,}/ doesn't match `0.6` | |
4/5 /\d{5,}/ doesn't match `0.8` | |
1/6 /\d{5,}/ matches `0.16666666666666666` | |
2/6 /\d{5,}/ matches `0.3333333333333333` | |
3/6 /\d{5,}/ doesn't match `0.5` | |
4/6 /\d{5,}/ matches `0.6666666666666666` | |
5/6 /\d{5,}/ matches `0.8333333333333334` | |
1/7 /\d{5,}/ matches `0.14285714285714285` | |
2/7 /\d{5,}/ matches `0.2857142857142857` | |
3/7 /\d{5,}/ matches `0.42857142857142855` | |
4/7 /\d{5,}/ matches `0.5714285714285714` | |
5/7 /\d{5,}/ matches `0.7142857142857143` | |
6/7 /\d{5,}/ matches `0.8571428571428571` | |
1/8 /\d{5,}/ doesn't match `0.125` | |
2/8 /\d{5,}/ doesn't match `0.25` | |
3/8 /\d{5,}/ doesn't match `0.375` | |
4/8 /\d{5,}/ doesn't match `0.5` | |
5/8 /\d{5,}/ doesn't match `0.625` | |
6/8 /\d{5,}/ doesn't match `0.75` | |
7/8 /\d{5,}/ doesn't match `0.875` | |
1/9 /\d{5,}/ matches `0.1111111111111111` | |
2/9 /\d{5,}/ matches `0.2222222222222222` | |
3/9 /\d{5,}/ matches `0.3333333333333333` | |
4/9 /\d{5,}/ matches `0.4444444444444444` | |
5/9 /\d{5,}/ matches `0.5555555555555556` | |
6/9 /\d{5,}/ matches `0.6666666666666666` | |
7/9 /\d{5,}/ matches `0.7777777777777778` | |
8/9 /\d{5,}/ matches `0.8888888888888888` | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment