Skip to content

Instantly share code, notes, and snippets.

@lubien
Forked from Woodsphreaker/obmep.js
Last active March 27, 2017 18:34
Show Gist options
  • Save lubien/210bc9c6fdc5af0a78b2e03fa686b1d3 to your computer and use it in GitHub Desktop.
Save lubien/210bc9c6fdc5af0a78b2e03fa686b1d3 to your computer and use it in GitHub Desktop.
  • Pense em qualquer número de DOIS dígitos, por exemplo 47

  • Subtraia a soma dos algarismos. Ex.: 47 - (4 + 7) = 36

  • Depois some os algarismos resultantes da subtração anterior, adicionando 4. Ex.: 3 + 6 + 4 = 13

  • Multiplique o resultado pelo inverso do número. Ex.: 13 x 31 = 403

  • E por último, multiplique por 3 o resultado anterior. Ex. 403 x 3 = 1209

  • Obs.: Qualquer número de 2 algarismos (entre 10 e 99) terão o mesmo resultado.

  • Não acredita ? Faça o teste !!!!

const digits = number => number.toString().split('').map(Number)
const reverseDigits = number => digits(number).reverse()
const reversedNumber = number => toNumber(reverseDigits(number))
const toNumber = arr => parseInt(arr.join(''));
const sumList = arr => arr.reduce((a, b) => a + b);
const sumDigits = number => sumList(digits(number))
const pipe = (...functions) => startValue => functions.reduce((acc, fn) => fn(acc), startValue)
const solve =
pipe(
step => step - sumDigits(step),
step => sumDigits(step) + 4,
step => step * (reversedNumber(step)),
step => step * 3
)
console.log(solve(39))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment