File tree Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 39
39
* [ Problem1] ( ./Maths/ProjectEuler/Problem1.php )
40
40
* [ Problem2] ( ./Maths/ProjectEuler/Problem2.php )
41
41
* [ Problem3] ( ./Maths/ProjectEuler/Problem3.php )
42
+ * [ Problem4] ( ./Maths/ProjectEuler/Problem4.php )
42
43
* [ Problem5] ( ./Maths/ProjectEuler/Problem5.php )
43
44
* [ Problem6] ( ./Maths/ProjectEuler/Problem6.php )
44
45
* [ Problem7] ( ./Maths/ProjectEuler/Problem7.php )
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /**
4
+ * Problem:
5
+ * A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
6
+ * Find the largest palindrome made from the product of two 3-digit numbers.
7
+ */
8
+
9
+ /**
10
+ * @return int
11
+ */
12
+ function problem4 (): int
13
+ {
14
+ $ largest = 0 ;
15
+
16
+ for ($ i =100 ; $ i <1000 ; $ i ++){
17
+
18
+ for ($ j =$ i ; $ j <1000 ; $ j ++) {
19
+ $ product = $ i *$ j ;
20
+
21
+ if ( strrev ((string )$ product ) == (string )$ product && $ product > $ largest ) {
22
+ $ largest = $ product ;
23
+ }
24
+ }
25
+ }
26
+
27
+ return $ largest ;
28
+ }
Original file line number Diff line number Diff line change 6
6
require_once __DIR__ . '/../../Maths/ProjectEuler/Problem1.php ' ;
7
7
require_once __DIR__ . '/../../Maths/ProjectEuler/Problem2.php ' ;
8
8
require_once __DIR__ . '/../../Maths/ProjectEuler/Problem3.php ' ;
9
+ require_once __DIR__ . '/../../Maths/ProjectEuler/Problem4.php ' ;
9
10
require_once __DIR__ . '/../../Maths/ProjectEuler/Problem5.php ' ;
10
11
require_once __DIR__ . '/../../Maths/ProjectEuler/Problem6.php ' ;
11
12
require_once __DIR__ . '/../../Maths/ProjectEuler/Problem7.php ' ;
@@ -30,6 +31,11 @@ public function testProblem3(): void
30
31
$ this ->assertSame (6857 , problem3 ());
31
32
}
32
33
34
+ public function testProblem4 (): void
35
+ {
36
+ $ this ->assertSame (906609 , problem4 ());
37
+ }
38
+
33
39
public function testProblem5 (): void
34
40
{
35
41
$ this ->assertSame (232792560 , problem5 ());
You can’t perform that action at this time.
0 commit comments