--- tags: challenge, studiomate --- # StudioMate Collaboration 1 ## The problem :::info Write a script in PHP that prints a list of numbers from 1 to 1000. For each number that is a multiple of 3 replace the number with the string "Studio", for each number that is a multiple of 5 replace the number with the string "Mate". If you have a number that is both a multiple of 3 and 5 replace the number with the string "Studio Mate". Please pay attention to: - Readability and maintainability - Easy to expand - Meet the requirements - How you deliver the code ::: ## The solution (code) > This solution prioritizes clean, readable and scalable code over performance. ``` php <?php // Write a script in PHP that prints a list of numbers from 1 to 1000. // - For each number that is a multiple of 3 replace the number with the string "Studio", // - for each number that is a multiple of 5 replace the number with the string "Mate". // - If you have a number that is both a multiple of 3 and 5 replace the number with the string "Studio Mate". // run script customPrintList(range(1, 1000)); function customPrintList($list) { foreach ($list as $number) { customPrintNumber($number); // print new line echo PHP_EOL; } } function customPrintNumber($number) { // is multiple of 3 and 5 if (isMultipleOf($number, 15)) { echo "Studio Mate"; } else if (isMultipleOf($number, 3)) { echo "Studio"; } else if (isMultipleOf($number, 5)) { echo "Mate"; } else { echo $number; } } // a multiple is a number that can be divided by another number a certain number of times without a remainder. function isMultipleOf($number, $n) { return ($number % $n == 0); } ?> ``` ## Try it here ! https://replit.com/@AndresBernardi/StudioMate#main.php