From 014c71d64cd512e877c64589e2375e7b01a86d6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=A4fliger?= Date: Fri, 2 May 2025 15:26:34 +0200 Subject: [PATCH] no message --- Verbraucher_extern/module.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) 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 = [];