Guest User

Untitled

a guest
Jan 18th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. /*
  2. Self powers
  3. Problem 48
  4. The series, 1**1 + 2**2 + 3**3 + ... + 10**10 = 10405071317.
  5.  
  6. Find the last ten digits of the series, 1**1 + 2**2 + 3**3 + ... + 1000**1000.
  7. */
  8. const fp = require('lodash/fp');
  9. const object = require('lodash/fp/object');
  10. const extend = require('lodash/fp/extend');
  11.  
  12. let modulo = 1e10;
  13.  
  14. let ns = n => fp.range(1,n+1);
  15. let compute = n => fp.reduce((a,v) => fn(a,v),0)(ns(n));
  16.  
  17. function fn(a,v){
  18. let t = v;
  19. for(let i=1; i<v; i++){
  20. t *= v;
  21. t %= modulo;
  22. }
  23. a += t;
  24. return a;
  25. }
  26.  
  27. let solution = fp.compose(
  28. fp.join(''),
  29. fp.takeLast(10),
  30. fp.toString
  31. )(compute(1000));
Add Comment
Please, Sign In to add comment