Project Euler: Problem 1 – PHP Solution

Solving Mathematical problems is one of the purpose of computers, able to calculate large numbers faster than human can do. ProjectEuler.net challenge us to solve there set of problem using any form of calculation. I accept the challenge by using my Programming skills using PHP as a tool.

My first encounter and a quick solution to the first one.

Problem 1:

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.

Solution1: 



<?php 
echo array_sum(array_unique(array_merge(range(3,999,3),range(5,999,5))));
#233168

If you had a better solution and believe that I need some corrections, I'd be happy to know.

Comments

Popular Posts