Sarcina este urmatoare
DOI +DOI +DOI = ȘASE
Unde DOIȘASE sunt cifre diferite si trebuie de gasit aceste cifre care satisfac aceasta egalitate.
Am incercat diferite cifre si nu gaseam, deci am decis sa scriu un programel :)
Scritpul este in javascript scris in editorul de la ramdajs
const startNumber = 100
const endNumber = 999
const startProductNumber = 1000
const endProductNumber = 9999
const arrayOfNumbers = Array.from(Array(endNumber - startNumber)).map((a, i) => startNumber + i)
const isProductInRange = p => p >= startProductNumber && p <= endProductNumber
const isNumberWithUniqNumbers = a => R.uniq(a).length == a.length
const areAnyNumberDuplicates = (k, p) => {
const ks = k.toString(), ps = p.toString()
return isNumberWithUniqNumbers(ks) && isNumberWithUniqNumbers(ps) && R.intersection(ks,ps).length == 0
}
const reducer = (ac, k) => {
const p = k * 3
if (isProductInRange(p)) {
if (areAnyNumberDuplicates(k, p)) {
ac = ac.concat(`${k} + ${k} + ${k} = ${p}`)
}
}
return ac
}
const validResults = arrayOfNumbers.reduce(reducer, [])
validResults
Si rezultatul este :)
[
"354 + 354 + 354 = 1062",
"358 + 358 + 358 = 1074",
"364 + 364 + 364 = 1092",
"534 + 534 + 534 = 1602",
"543 + 543 + 543 = 1629",
"568 + 568 + 568 = 1704",
"582 + 582 + 582 = 1746",
"583 + 583 + 583 = 1749",
"594 + 594 + 594 = 1782",
"609 + 609 + 609 = 1827",
"634 + 634 + 634 = 1902",
"658 + 658 + 658 = 1974",
"673 + 673 + 673 = 2019",
"678 + 678 + 678 = 2034",
"681 + 681 + 681 = 2043",
"683 + 683 + 683 = 2049",
"691 + 691 + 691 = 2073",
"768 + 768 + 768 = 2304",
"819 + 819 + 819 = 2457",
"839 + 839 + 839 = 2517",
"873 + 873 + 873 = 2619",
"891 + 891 + 891 = 2673",
"906 + 906 + 906 = 2718",
"916 + 916 + 916 = 2748",
"918 + 918 + 918 = 2754"
]