Advertisement
Danny_Berova

4thGradeProblem

Nov 10th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     let sub = 333;
  3.  
  4.     for (let index = 598; index > 501; index--) {
  5.         let num = index.toString().split('').sort((a, b) => a.localeCompare(b));
  6.         let result = (index - sub).toString().split('').sort((a, b) => a.localeCompare(b));
  7.  
  8.         if((index.toString()[1] !== index.toString()[2])
  9.             && (index.toString()[1] !== '5')
  10.             && (index.toString()[2] !== '5')  
  11.             && (num.join('') === result.join(''))) {
  12.            return result.join('');
  13.         }
  14.     }
  15. }
  16.  
  17. console.log(solve()); //259
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement