Advertisement
3vo

Menthor Cherry Blossom

3vo
Nov 24th, 2022
769
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // let input = [
  2. //     '7 March 2021', // the input is always a string, so it's '3' and not 3
  3. //     '30',
  4. //     '30',
  5. //     '7'
  6. // ];
  7. let input = [
  8.     '11 March 2021', // the input is always a string, so it's '3' and not 3
  9.     '22',
  10.     '27',
  11.     '35'
  12. ];
  13.  
  14. let print = this.print || console.log;
  15. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  16.  
  17. // Input
  18. let expectedDate = gets().split(' ');
  19. let day = +expectedDate[0];
  20. let month = expectedDate[1];
  21. let year = +expectedDate[2];
  22.  
  23. let averageTemperature = +gets();
  24. let optimalAverageTemperature = 20;
  25.  
  26. let rain = +gets();
  27. let optimalRain = 30;
  28.  
  29. let winterLength = +gets();
  30.  
  31. // Solution
  32. let itsLeapYear = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
  33.  
  34. if (itsLeapYear) averageTemperature += 5;
  35.  
  36. day += Math.floor(winterLength / 7);
  37. day -= averageTemperature - optimalAverageTemperature;
  38. day += Math.floor(Math.abs(rain - optimalRain) / 3)
  39.  
  40. if (day > 31) {
  41.     day -= 31;
  42.     month = "April";
  43. }
  44.  
  45. if (day < 0) {
  46.     day += 28;
  47.     month = "February";
  48.  
  49.     if (itsLeapYear) day += 1;
  50. }
  51.  
  52. // Output
  53. console.log(`${day} ${month} ${year}`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement