Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
78
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let S = (x) => {
  2.     return ++x;
  3. }
  4.  
  5. let P = (x) =>{
  6.     return --x;
  7. }
  8.  
  9. let add = (a, b) => {
  10.     if(b == 0) return a;   
  11.     if(b > 0) return add(S(a), P(b))
  12.     return add(P(a), S(b))
  13. }
  14.  
  15. let mul = (a, b) => {
  16.     if(a == 0 || b == 0) return 0;
  17.     if(b == 1) return a;
  18.     if(b == -1) return -a;
  19.     if(b > 1) return add(a, mul(a, P(b)));
  20.     return add(mul(a, -1), mul(a, S(b)));
  21. }
  22.  
  23. let pow = (a, b) => {
  24.     if(a == 1) return 1;
  25.     if(b < 0) return 0;
  26.     if(b == 0) return 1;
  27.     return mul(a, pow(a, P(b)))
  28. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement