JSFiddle

  • Euler Problem 26

    jQuery 2.1.3, HTML, CSS, JavaScript

    $(document).ready(function() {
        var longest = 0;
        var longestIndex = 0;
        for (var i = 0; i < 1000; ++i) {
            var len = lengthOfRepeat(i);
            if (longest < len) {
                longestIndex = i;
                longest = len;
            }
        }
        print(longest, longestIndex);
    })
    
    function lengthOfRepeat(n) {
        var value = 1;
        var arr = []
        while (value) {
            value *= 10;
            value %= n;
            var ffound = arr.indexOf(value);
            if (ffound >= 0) {
                return arr.length - ffound;
            }
            arr ...
  • Euler Problem 25

    jQuery 2.1.3, HTML, CSS, JavaScript

    $(document).ready(function() {
        print(fibonacci());
    });
    
    function fibonacci() {
        var p = [1];
        var c = [1];
        var i = 0;
        while(c.length < 1000){
            var s = addArrays(p,c);
            p = c;
            c = s;
            ++i;
        }
        return i;
    }
    
    function addArrays(a, b) {
        var carry = 0;
        var sum = [];
        for (var i = 0; i < Math.max(a.length, b.length); ++i) {
            var digit_a = (i<a.length)?a[i]:0;
            var digit_b = (i<b.length)?b[i]:0;
            var s = digit_a + digit_b;
            var digit = s%10;
            carry = (s/10)<<0;
            sum[i] = digit;
        }
        while(carry>0 ...
  • Euler Problem 24

    jQuery 2.1.3, HTML, CSS, JavaScript

    if (typeof Math.factorial === "undefined") {
    
      Math.factorial = function factorial (n) {
        if (n == 0 || n == 1)
          return 1;
        if (Math.factorial ...
  • Euler Problem 23

    jQuery 2.1.3, HTML, CSS, JavaScript

    $(document).ready(function() {
        var seive = seiveOfAbundants(28123);
        var allSums = allSumsOfAbundants(seive);
        var s = 0;
        for (var i = 1; i <= 28123; ++i) {
            var key = i.toString();
            if (allSums[key] == undefined) {
                s += i;
            }
        }
        print(s);
    })
    
    function seiveOfAbundants(limit) {
        var ret = [];
        for (var i = 1; i < limit; ++i) {
            //var f = factors(i);
            //var s = sum.apply(null, f);
            if (divisorsSum(i) > i ...</=>
  • Check for Balanced Parens #2 is the latest revision

    jQuery 2.1.3, HTML, CSS, JavaScript

    function Stack() {
        this.data = new Array();
    	this.push = function(n) {
            if (n) {
    	        this.data.push(n);
            }
        }
        this.pop = function() {
            return ...
  • BST Stuff

    jQuery 2.1.3, HTML, CSS, JavaScript

     var Node = function() {
        var data;
        var left;
        var right;
        Node.prototype.toString = function() {
            return "[Node " + this.data /*+ ", left=" + this.left ...
  • Euler Problem 20

    jQuery 2.1.3, HTML, CSS, JavaScript

    $(document).ready(function() {
        var a = [1];
        var count = 1;
        var target = 100;
        while (count <= target) {
            a = multiplyArray(a, count);
            ++count;
        }
        var total = sum.apply(null, a);
        print(total)
    })
    
    function sum() {
        var f = 0;
        for (var i = 0; i < arguments.length; ++i) {
            f += arguments[i];
        }
        return f;
    }
    
    function multiplyArray(a, b) {
        var carry = 0;
        for (var i = 0; i < a.length; ++i) {
            var d = a[i] * b + carry;
            a[i] = d%10;
            carry = (d / 10) << 0;
        }
        while (carry > 0) {
        	a[i++] = carry%10;
            carry ...</=>
  • Euler Problem 19

    jQuery 2.1.3, HTML, CSS, JavaScript

    (function(D) {
        // DAYS
        D.Sunday 		= 0
        D.Monday 		= 1
        D.Tuesday 		= 2
        D.Wednesday		= 3
        D.Thursday 		= 4
        D.Friday ...
  • Maximum path sum I

    jQuery 2.1.3, HTML, CSS, JavaScript

    $(document).ready(function() {
    	var p = [
            [75],
    		[95, 64],
    		[17, 47, 82],
    		[18, 35, 87, 10],
    		[20, 04, 82, 47, 65 ...
  • Euler Problem 16

    Ways of dealing with integer overflow in javascript

    $(document).ready(function() {
    	var arr = expArray(1000);
        print(sum.apply(null, arr));
    })
    
    function sum() {
        var s = 0;
        for (var i ...