File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed 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 ' ;
@@ -29,6 +30,11 @@ public function testProblem3(): void
29
30
$ this ->assertSame (6857 , problem3 ());
30
31
}
31
32
33
+ public function testProblem4 (): void
34
+ {
35
+ $ this ->assertSame (906609 , problem4 ());
36
+ }
37
+
32
38
public function testProblem5 (): void
33
39
{
34
40
$ this ->assertSame (232792560 , problem5 ());
You can’t perform that action at this time.
0 commit comments