Inputs:
- Target number: 20
- Factors: [19]
Output
- 19
DIGITS = { | |
'0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, | |
'5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9 | |
} | |
def string_to_integer(string) | |
# todo | |
end |
pragma solidity >= 0.5.0 < 0.6.3; |
function sumOfMultiples(targetNumber, factors) { | |
var multiples = []; | |
if (factors.length === 0) { | |
factors = [3, 5]; | |
} | |
factors.forEach(function(factor) { | |
var currentMultiple; | |
for (currentMultiple = factor; currentMultiple < targetNumber; currentMultiple += factor) { | |
if (multiples.indexOf(currentMultiple) === -1) { |
def sum_of_multiples(target, factors) | |
multiples = [] | |
factors = [3, 5] if factors.length == 0 | |
factors.each do |factor| | |
current_multiple = factor | |
while current_multiple < target | |
multiples << current_multiple | |
current_multiple += factor |
Determine a list of all multiples of a set of factors up to a target value, then filter the list of multiples to the unique values. Finally, compute and return the sum of the unique multiples.
multiples
that will contain the list of multiples.[3, 5]
factor
in the factors
list:
current_multiple
to factor
to keep track of the multiples of factor
.current_multiple
< target
current_multiple
to multiples
.factor
to current_multiple
.multiples
.A mental model is an explanation of someone's thought process about how something works in the real world (source: wikipedia)