alboig

Javascript Apr20 Module 0 - Task 01 Game

Apr 3rd, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Game
  2. // Three friends came up with a game for having fun in the break between the classes.
  3. // One of them says a three-digit number and the others use it to form a mathematical expressions
  4. // by using operators for sum and multiplication between the digits of that number.
  5. // The winner is the first one who founds the biggest number that is a result of the above mentioned rules.
  6. // Write a program 'game', which prints out that biggest number.
  7. // Input
  8. // Read from the standard input
  9. // The first line of the input will be positive three-digit number N.
  10. // Output
  11. // Print on the standard output
  12. // The result should be the calculated biggest number.
  13. // Sample tests
  14. // Input
  15. // 185
  16. // Output
  17. // 41
  18. // Input
  19. // 111
  20. // Output
  21. // 3
  22. const input = ['345'];
  23. const print = this.print || console.log;
  24. const gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  25. const initialNum = gets();
  26. const hundreds = Number(initialNum[0]);
  27. const tenths = Number(initialNum[1]);
  28. const units = Number(initialNum[2]);
  29. const maxNum = Math.max((hundreds * tenths * units), (hundreds * tenths + units), (hundreds + tenths * units), (hundreds + tenths + units));
  30. print(maxNum);
Advertisement
Add Comment
Please, Sign In to add comment