Guest User

Untitled

a guest
Jun 22nd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. bases = [24, 60, 60]
  2. input = 86462 #One day, 1 hour, 2 seconds
  3. output = []
  4.  
  5. for base in reverse(bases)
  6. output.prepend(input mod base)
  7. input = input div base #div is integer division (round down)
  8.  
  9. factors = [52,7,24,60,60,1000]
  10. value = 662321
  11. for i in n-1..0
  12. res[i] = value mod factors[i]
  13. value = value div factors[i]
  14.  
  15. values = [32,5,7,45,15,500]
  16. factors = [52,7,24,60,60,1000]
  17.  
  18. res = 0;
  19. for i in 0..n-1
  20. res = res * factors[i] + values[i]
  21.  
  22. var theNumber = 313732097;
  23.  
  24. // ms s m h d
  25. var bases = [1000, 60, 60, 24, 365];
  26. var placeValues = []; // initialise an array
  27. var currPlaceValue = 1;
  28.  
  29. for (var i = 0, l = bases.length; i < l; ++i) {
  30. placeValues.push(currPlaceValue);
  31. currPlaceValue *= bases[i];
  32. }
  33. console.log(placeValues);
  34. // this isn't relevant for this specific problem, but might
  35. // be useful in related problems.
  36. var maxNumber = currPlaceValue - 1;
  37.  
  38.  
  39. var output = new Array(placeValues.length);
  40.  
  41. for (var v = placeValues.length - 1; v >= 0; --v) {
  42. output[v] = Math.floor(theNumber / placeValues[v]);
  43. theNumber %= placeValues[v];
  44. }
  45.  
  46. console.log(output);
  47. // [97, 52, 8, 15, 3] --> 3 days, 15 hours, 8 minutes, 52 seconds, 97 milliseconds
Add Comment
Please, Sign In to add comment