Skip to content

Instantly share code, notes, and snippets.

@bparanj
Created August 19, 2020 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bparanj/8e28da40dde2ea77c7137e7de33746df to your computer and use it in GitHub Desktop.
Save bparanj/8e28da40dde2ea77c7137e7de33746df to your computer and use it in GitHub Desktop.
# @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