Created
August 19, 2020 02:48
-
-
Save bparanj/8e28da40dde2ea77c7137e7de33746df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @param {Integer} n | |
# @return {Integer} | |
def subtract_product_and_sum(n) | |
product = 1 | |
sum = 0 | |
while n > 0 | |
sum += n % 10 | |
product *= n % 10 | |
n = n / 10 | |
end | |
product - sum | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment