Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function exercise4()
- {
- var pascalHeight = parseInt(document.getElementsByName('pascalHeight')[0].value);
- var actualWidth = 0;
- var destinationWidth = 0;
- var resultDiv = document.getElementById("exercise4Results");
- resultDiv.textContent = "";
- resultDiv.setAttribute('style', 'white-space: pre;')
- var result = exercise4_recursion(1, 3);
- for(var h = 1; h <= pascalHeight; h++)
- {
- for(var actualWidth = 0; actualWidth < h; actualWidth++)
- {
- resultDiv.textContent += exercise4_recursion(actualWidth, h) + " ";
- }
- resultDiv.textContent += "\r\n";
- }
- }
- function exercise4_recursion(actualWidth, destinationWidth)
- {
- /*
- console.log("# DEBUG #");
- console.log(actualWidth);
- console.log(destinationWidth);
- console.log("# DEBUG #");
- */
- if(actualWidth == 0 || (actualWidth + 1) == destinationWidth)
- return 1;
- else
- return exercise4_recursion(actualWidth - 1, destinationWidth - 1) + exercise4_recursion(actualWidth, destinationWidth - 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement