- Think in a two-digit number.
- Subtract by it's digits sum. Ex.: 13 - (1 + 3).
- Sum it's digits. Ex.: 13 => 1 + 3.
- Sum by 4.
- Multiply by it's reversed digits number. Ex.: 31 * 13.
- Multiply by 3.
- Should be equal 1209.
-
-
Save lubien/ecbeb58197686f75af87c35dc6a2e114 to your computer and use it in GitHub Desktop.
OBMEP 2015 - 2ª Fase - Data - https://www.youtube.com/watch?v=XxceY97NjEU
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
/* | |
Run at: https://repl.it/Gle8/1 | |
1. Pense num número de dois algarismos. | |
2. Subtraia a soma de seus algarismos | |
3. Calcule a soma dos algarismos do resultado. | |
4. Some 4 | |
5. Multiplique o resultado pelo numero cujos algarismos são o contrário dele (Ex.: 13 * 31) | |
6. Multiplique por 3 | |
= 1209 | |
*/ | |
const { | |
compose | |
, pipe | |
, range | |
, all | |
, equals | |
, prop | |
, map | |
, reverse | |
, split | |
, join | |
, sum | |
, add | |
, multiply | |
, toString | |
} = require('ramda') | |
const | |
digits = | |
compose(map(Number), split(''), toString) | |
, sumDigits = | |
compose(sum, digits) | |
, reverseDigits = | |
compose(Number, join(''), reverse, digits) | |
, solve = | |
pipe( | |
x => x - sumDigits(x) | |
, sumDigits | |
, add(4) | |
, x => x * reverseDigits(x) | |
, multiply(3) | |
) | |
, check = | |
all(compose(equals(1209), solve))(range(10)(100)) | |
check |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment