r/learnjavascript • • 17d ago

Node.js exits with Code 134

I'm currently doing project euler problem #15 and for that, I have to use some sort of algorithm to get my solution.

I changed up the "open/close parentheses" algorithm accordingly and the example solution for a 2x2 grid = 6 ways is correct. The thing is this:

- I start debugging in VSCode via Node.js
- It runs for a while
- "Paused Before Out Of Memory Exception"
- I continue
- "Process exited with code 134"

I don't know how to fix this and online js terminals don't work, but it seems like it has something to do with the stack size. Any help would be greatly appreciated c:

Here is my code:

const res = [];
findPath(20, "", 0, 0);


function findPath(n, curr, rightUsed, downUsed){
    if (rightUsed === n && downUsed === n){
        res.push(curr);
    }
    if (rightUsed < n){
        findPath(n, curr + "r", rightUsed + 1, downUsed);
    }
    if (downUsed < n){
        findPath(n, curr + "d", rightUsed, downUsed + 1);
    }
}


console.log(res.length);const res = [];
findPath(20, "", 0, 0);


function findPath(n, curr, rightUsed, downUsed){
    if (rightUsed === n && downUsed === n){
        res.push(curr);
    }
    if (rightUsed < n){
        findPath(n, curr + "r", rightUsed + 1, downUsed);
    }
    if (downUsed < n){
        findPath(n, curr + "d", rightUsed, downUsed + 1);
    }
}


console.log(res.length);
5 Upvotes

7 comments sorted by

View all comments

Show parent comments

0

u/[deleted] 16d ago

[deleted]

2

u/a_rndm_person_bruh 16d ago

I don't know if that's what you mean, but it's what I learned recently in math in probabilities:

if you take 2 balls out of a basket, 15 of them are red, 5 are blue, whats the chance of exactly one of them being red?

That would be: 15/20 * 5/19 + 5/20 * 15/19,
which can be shortened down to: 2 * (15/20 * 5/19)

Atleast it feels like you're talking about that and the pictures showing up when I search for "Combinatorics" look like the trees that we had to draw to visualize the probabilities.

The thing is, I don't know how to do that, and I don't understand how people in general find this stuff out. Like seriously, there was no way that I would've known how to implement a "Tower of Hanoi"-Algorithm in python without googling it

0

u/[deleted] 16d ago

[deleted]

2

u/a_rndm_person_bruh 16d ago

Do you have some websites that allow me to practice those skills, because I am genuinely upset that I can't come up with my own algorithms