Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. function exercise4()
  2. {
  3. var pascalHeight = parseInt(document.getElementsByName('pascalHeight')[0].value);
  4. var actualWidth = 0;
  5. var destinationWidth = 0;
  6.  
  7. var resultDiv = document.getElementById("exercise4Results");
  8. resultDiv.textContent = "";
  9. resultDiv.setAttribute('style', 'white-space: pre;')
  10.  
  11. var result = exercise4_recursion(1, 3);
  12. for(var h = 1; h <= pascalHeight; h++)
  13. {
  14. for(var actualWidth = 0; actualWidth < h; actualWidth++)
  15. {
  16. resultDiv.textContent += exercise4_recursion(actualWidth, h) + " ";
  17. }
  18. resultDiv.textContent += "\r\n";
  19. }
  20.  
  21. }
  22.  
  23. function exercise4_recursion(actualWidth, destinationWidth)
  24. {
  25. /*
  26. console.log("# DEBUG #");
  27. console.log(actualWidth);
  28. console.log(destinationWidth);
  29. console.log("# DEBUG #");
  30. */
  31.  
  32. if(actualWidth == 0 || (actualWidth + 1) == destinationWidth)
  33. return 1;
  34. else
  35. return exercise4_recursion(actualWidth - 1, destinationWidth - 1) + exercise4_recursion(actualWidth, destinationWidth - 1);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement