• + 0 comments

    PHP solution

    function countApplesAndOranges(
        int $houseStart,
        int $houseEnd,
        int $applePoint,
        int $orrangePoint,
        array $apples,
        array $oranges
    ) {
        $getPoints=static function(int $treePoint, array $points) use ($houseStart,$houseEnd) {
            $res=0;
            foreach($points as $point) {
                $fallPoint = $treePoint+$point;
                if ($fallPoint>=$houseStart && $fallPoint<=$houseEnd) $res++;
            }
            return $res;
        };
        
        foreach([$applePoint=>$apples, $orrangePoint=>$oranges] as $tree=>$fruits) {
            print($getPoints($tree,$fruits) . "\n");
        }
    }