This file contains hidden or 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
| var permutations = [], | |
| numberArray = '1234567890'.split(''); | |
| function swap(a, b) { | |
| var tmp = numberArray[a]; | |
| numberArray[a] = numberArray[b]; | |
| numberArray[b] = tmp; | |
| } | |
| // Use Heap's algorithm to swap around numbers |
This file contains hidden or 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
| var carryup = 0, | |
| triangle = [ | |
| [75], | |
| [95, 64], | |
| [17, 47, 82], | |
| [18, 35, 87, 10], | |
| [20, 4, 82, 47, 65], | |
| [19, 1, 23, 75, 3, 34], | |
| [88, 2, 77, 73, 7, 63, 67], | |
| [99, 65, 4, 28, 6, 16, 70, 92], |
This file contains hidden or 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
| var divisors = function( a ) { | |
| var divisorList = []; | |
| for (var i = 1; i <= a / 2; i++) { | |
| if ( a % i === 0 ) { | |
| divisorList.push( i ); | |
| } | |
| } | |
| return divisorList; | |
| }, | |
This file contains hidden or 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
| var names = names.sort(), | |
| alpha = { | |
| A: 1, | |
| B: 2, | |
| C: 3, | |
| D: 4, | |
| E: 5, | |
| F: 6, | |
| G: 7, | |
| H: 8, |
This file contains hidden or 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
| var results = [], | |
| a, | |
| b; | |
| function divisors( a ) { | |
| var divisor = []; | |
| for (var i = 1; i <= a / 2; i++) { | |
| if ( a % i === 0 ) { | |
| divisor.push( i ); | |
| } |
This file contains hidden or 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 factorial( n ) { | |
| var product = bigInt(1); | |
| for (var i = n; i > 0; i--) { | |
| product = product.multiply( i ); | |
| } | |
| return product.toString(); | |
| } | |
| var number = factorial( 100 ), | |
| result = 0; |
This file contains hidden or 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
| var date, | |
| counter = 0; | |
| for (var i = 1901; i <= 2000; i++) { | |
| for (var j = 1; j <= 12; j++) { | |
| date = new Date( i + '-' + pad( j ) + '-01' ); | |
| if ( date.getDay() === 0 ) { | |
| counter++; | |
| } | |
| } |
This file contains hidden or 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 nameNumber( count ) { | |
| var ones = [ '', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen' ], | |
| tens = [ 'zero', 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety' ]; | |
| // Thousands | |
| if ( count === 1000 ) { | |
| return 'one thousand'; | |
| } |
This file contains hidden or 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
| var result = 0, | |
| count = 0; | |
| result = bigInt(2).pow( 1000 ).toString(); | |
| for (var i = result.length - 1; i >= 0; i--) { | |
| count += parseInt( result[ i ] ); | |
| } | |
| document.write( count ); |
This file contains hidden or 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
| var result = 0, | |
| i, | |
| j; | |
| for ( i = 1; i <= 20; i++ ) { | |
| result = 1; | |
| for ( j = (2*i) - i + 1; j <= (2*i); j++) { | |
| result *= j; | |
| } |