<?php require_once "../libraries/Math.php"; /** * Write a program that outputs all possibilities to put + or - or nothing between the numbers 1, 2, ..., 9 (in this order) * such that the result is always 100. For example: 1 + 2 + 34 – 5 + 67 – 8 + 9 = 100. * @author Beau Durrant */ $desiredTotal = 100; $math = new Math(); $permutations = $math->permutate(array(1, 2, 3, 4, 5, 6, 7, 8, 9)); $totals = $math->plusMinusVariants($permutations); $results = array(); foreach ($totals as $groups) { foreach ($groups as $equation => $total) { if ($total == $desiredTotal) { $results[$equation] = $total; } } } print_r($results);