From 9d1845a3fc2d4ff8d120d2095b552a2b250ba499 Mon Sep 17 00:00:00 2001 From: drbaggy Date: Thu, 5 Aug 2021 09:19:48 +0100 Subject: tidied up --- challenge-124/james-smith/php/ch-2.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/challenge-124/james-smith/php/ch-2.php b/challenge-124/james-smith/php/ch-2.php index 0696562330..2a888e40ee 100644 --- a/challenge-124/james-smith/php/ch-2.php +++ b/challenge-124/james-smith/php/ch-2.php @@ -12,11 +12,8 @@ function match_teams( $teams ) { implode( ' ', $bt[1] ), implode( ' ', $bt[2] ), $bt[0] ); } -function separate( $m, $t1, $t2, $d, &$b, $w ) { - if(!sizeof($w)) { - if( $b[0]>abs($d) ) list($b[0],$b[1],$b[2]) = [abs($d),$t1,$t2]; - return; - } +function separate( $m, $t1, $t2, $d, &$b, $w ) { // & in front of $b as pass by reference! + if(!sizeof($w)) return ( $b[0]>abs($d) ) && ( $b = [abs($d),$t1,$t2] ); $n = array_shift( $w ); if( sizeof($t1)<$m ) separate( $m, array_merge($t1,[$n]), $t2, $d+$n, $b, $w ); if( sizeof($t2)<$m ) separate( $m, $t1, array_merge($t2,[$n]), $d-$n, $b, $w ); -- cgit