Advertisement
Ninbo

Pizza de Steiner

Nov 9th, 2020
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. // Termo por recorrĂȘncia
  4. // p(n+1) = 1+ ((n+1)*(n+2) /2)
  5. // p(n+1) = pn + (n+1)
  6. // pn = (2+n+n^2)/2
  7.  
  8. /**
  9.  *
  10.  *  1   2 para baixo +2
  11.  *  2   4 para baixo +3
  12.  *  3   7 para baixo +4
  13.  *  4   11
  14.  */
  15.  
  16. // pn = p(n-1) + n
  17.  
  18. /**
  19.  function numeroCortes(n) {
  20.      if (n > 0)
  21.         return n + numeroCortes(n - 1);
  22.     else
  23.         return 1;
  24.  };
  25. **/
  26.  
  27. /**
  28.    let numeroCortes = (n) => {
  29.         return (n > 0) ? (n + numeroCortes(n - 1)) : 1;
  30.    };
  31. **/
  32.  
  33. function numeroCortes(n) {
  34.     return (n > 0) ? (n + numeroCortes(n - 1)) : 1;
  35. };
  36.  
  37. console.log(numeroCortes(5))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement