Categories
Без категория

Решение на задача – Vehicles

Задача от изпита по JavaScript основи, проведен на 19 май 2014 година.
Решението не дава точки в BGCoder!

function findCombinationsCount(tiresCount, vehicles, checkFromIndex) {
if (tiresCount === 0) {
return 1;
} else if (tiresCount < 0 || vehicles.length === checkFromIndex) { return 0; } else { var withFirstVehicle = findCombinationsCount(tiresCount - vehicles[checkFromIndex], vehicles, checkFromIndex); var withoutFirstVehicle = findCombinationsCount(tiresCount, vehicles, checkFromIndex + 1); return withFirstVehicle + withoutFirstVehicle; } } function solve(params) { var tiresCount = params; var vehicles = [3, 4, 10]; var answer = findCombinationsCount(tiresCount, vehicles, 0); return answer; } console.log(solve(20));