diff --git a/Verbraucher_extern/module.php b/Verbraucher_extern/module.php index 31172b9..603ee63 100644 --- a/Verbraucher_extern/module.php +++ b/Verbraucher_extern/module.php @@ -87,15 +87,25 @@ class Verbraucher_extern extends IPSModule return array_values(array_unique($kombinationen)); } - private function findCombinationRecursive($power, $values, $currentCombination, $startIndex, &$result) { - if ($power == 0) { - $result = $currentCombination; - return true; - } - if ($power < 0) { - return false; - } - } + private + function findCombinationRecursive($power, $values, $currentCombination, $startIndex, &$result) { + if ($power == 0) { + $result = $currentCombination; + return true; + } + if ($power < 0) { + return false; + } + for ($i = $startIndex; $i < count($values); $i++) { + $currentCombination[] = $values[$i]; + if (findCombinationRecursive($power - $values[$i], $values, $currentCombination, $i + 1, $result)) { + return true; + } + array_pop($currentCombination); + } + return false; + } + private function findCombination($power, $values) { $result = [];