Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save McLarenCollege/d9f0b00cb579ff8b0e2de972097a1c44 to your computer and use it in GitHub Desktop.
Save McLarenCollege/d9f0b00cb579ff8b0e2de972097a1c44 to your computer and use it in GitHub Desktop.
Weekend Catchup Assignment

Return the Sum of Two Numbers

When two numbers are added together, the strange Lunar arithmetic is used on the Moon. The Lunar sum of two numbers is not determined by the sum of their individual digits, but by the highest digit of the two taken into account at each step, in columnar form.

2  4  6  +
3  1  7  =
--------
3  4  7

// 3 > 2 | 4 > 1 | 7 > 6

1  3  4  +
   5  4  =
--------
1  5  4

//  1 > 0 | 5 > 3 | 4 == 4
// Blank spots in the columnar form are equals to 0

   2  0  +
1  4  0  =
-------
1  4  0

// 1 > 0 | 4 > 2 | 0 == 0

Given two positive integers number1 and number2, implement a function that returns their sum as a new integer.

Examples

lunarSum(246, 317) ➞ 347

lunarSum(134, 54) ➞ 154

lunarSum(20, 140) ➞ 140
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment