3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Start / End range $start = 1; $end = 100; // The two statements below allowed me to suggest which number to remove // I opted to use a file because I thought it was less obvious than passing // another argument. //$remove = is_readable(__DIR__ . '/remove') ? trim(file_get_contents(__DIR__ . '/remove')) : false; //$remove = isset($argv[2]) ? true : false; // Otherwise we simulate which number we have removed $remove = rand($start, $end); $random = isset($argv[1]) ? true : false; // Create the range $list = range($start, $end); // Determine whether the array should be random $random and shuffle($list); // Because $remove is optional (if user defined) we wrap this with an if if($remove) { $key = array_search($remove, $list); // Make sure the key exists otherwise php treat false == 0 // meaning the first element of the array would be removed if the key wasn't found if($key !== false) { unset($list[$key]); } } // Time to search for the number that was removed // I can't remeber whether I'm allowed to use the in_array method, but this loops through the range 1..100 // and determines whether that value exists. $found = false; for($i = $start; $i <= $end; $i++) { if(!in_array($i, $list)) { $found = $i; print $i . " was removed\n"; break; } } if($found == $remove) { print "Successfuly found the missing number\n"; }
Output for 4.3.9, 4.4.5, 5.3.5, 7.1.0, 7.2.7, 7.3.12
18 was removed Successfuly found the missing number
Output for 4.4.4, 5.4.5, 7.3.11
9 was removed Successfuly found the missing number
Output for 4.3.3, 5.4.0, 5.4.29, 5.6.21, 7.3.10
32 was removed Successfuly found the missing number
Output for 5.1.2, 5.4.30, 5.5.35, 7.3.9
56 was removed Successfuly found the missing number
Output for 4.4.6, 7.1.6, 7.3.8
74 was removed Successfuly found the missing number
Output for 4.3.7, 5.2.5, 5.4.26, 5.4.32, 5.4.45, 7.1.27, 7.3.7
97 was removed Successfuly found the missing number
Output for 4.3.8, 5.2.12, 5.5.26, 7.3.6
63 was removed Successfuly found the missing number
Output for 5.3.25, 5.5.29, 7.3.5
37 was removed Successfuly found the missing number
Output for 5.3.18, 7.3.4
85 was removed Successfuly found the missing number
Output for 4.4.8, 5.4.35, 7.3.3
50 was removed Successfuly found the missing number
Output for 5.4.3, 5.6.12, 7.3.2
86 was removed Successfuly found the missing number
Output for 5.4.40, 7.3.1
52 was removed Successfuly found the missing number
Output for 7.1.29, 7.3.0
27 was removed Successfuly found the missing number
Output for 5.4.21, 5.6.20, 7.2.21, 7.2.24
16 was removed Successfuly found the missing number
Output for 7.2.23
70 was removed Successfuly found the missing number
Output for 5.4.39, 7.2.22
94 was removed Successfuly found the missing number
Output for 4.3.4, 5.4.36, 7.2.20
95 was removed Successfuly found the missing number
Output for 4.3.6, 5.2.8, 5.4.43, 7.2.19
15 was removed Successfuly found the missing number
Output for 7.2.18
80 was removed Successfuly found the missing number
Output for 7.2.17
62 was removed Successfuly found the missing number
Output for 5.3.12, 5.6.11, 7.2.16
43 was removed Successfuly found the missing number
Output for 5.4.20, 7.1.33, 7.2.5, 7.2.15
42 was removed Successfuly found the missing number
Output for 5.1.0, 5.4.6, 7.0.20, 7.2.14
26 was removed Successfuly found the missing number
Output for 5.0.2, 5.4.31, 5.4.38, 7.1.31 - 7.1.32, 7.2.13
36 was removed Successfuly found the missing number
Output for 4.3.11, 5.4.15 - 5.4.16, 7.2.12
66 was removed Successfuly found the missing number
Output for 5.4.37, 7.2.11
30 was removed Successfuly found the missing number
Output for 5.3.7, 7.1.5, 7.2.10
58 was removed Successfuly found the missing number
Output for 5.1.3, 5.3.3, 5.3.6, 7.2.9
55 was removed Successfuly found the missing number
Output for 5.2.15, 7.2.8
82 was removed Successfuly found the missing number
Output for 7.2.6
81 was removed Successfuly found the missing number
Output for 5.1.4, 5.3.23, 5.4.24, 7.2.4
71 was removed Successfuly found the missing number
Output for 5.1.1, 5.3.28, 7.2.3
1 was removed Successfuly found the missing number
Output for 4.4.0, 7.2.2
88 was removed Successfuly found the missing number
Output for 5.2.11, 5.3.4, 7.2.1
65 was removed Successfuly found the missing number
Output for 5.2.0, 5.3.24, 7.2.0
3 was removed Successfuly found the missing number
Output for 5.5.33, 7.1.30
20 was removed Successfuly found the missing number
Output for 5.2.1, 5.4.8, 5.6.8, 5.6.16, 7.1.7, 7.1.28
72 was removed Successfuly found the missing number
Output for 5.3.11, 7.1.26
57 was removed Successfuly found the missing number
Output for 4.3.2, 4.3.10, 5.4.12, 5.5.24, 7.1.25
22 was removed Successfuly found the missing number
Output for 4.4.3, 5.0.1, 7.0.6
46 was removed Successfuly found the missing number
Output for 5.2.13 - 5.2.14, 5.4.18, 7.0.5
23 was removed Successfuly found the missing number
Output for 5.4.28, 5.5.34, 7.0.4
92 was removed Successfuly found the missing number
Output for 5.1.5, 5.2.16, 7.0.3
14 was removed Successfuly found the missing number
Output for 5.4.27, 7.0.2
41 was removed Successfuly found the missing number
Output for 5.3.10, 5.6.14, 7.0.1
87 was removed Successfuly found the missing number
Output for 5.1.6, 7.0.0
40 was removed Successfuly found the missing number
Output for 5.6.19
31 was removed Successfuly found the missing number
Output for 5.6.18
12 was removed Successfuly found the missing number
Output for 5.3.13, 5.6.17
51 was removed Successfuly found the missing number
Output for 5.3.9, 5.6.15
91 was removed Successfuly found the missing number
Output for 5.6.13
28 was removed Successfuly found the missing number
Output for 4.4.2, 5.6.10
73 was removed Successfuly found the missing number
Output for 5.3.26, 5.6.9
8 was removed Successfuly found the missing number
Output for 5.3.1, 5.4.17, 5.5.28, 5.5.32
53 was removed Successfuly found the missing number
Output for 5.5.31
79 was removed Successfuly found the missing number
Output for 5.0.3, 5.4.1, 5.5.30
69 was removed Successfuly found the missing number
Output for 5.5.27
21 was removed Successfuly found the missing number
Output for 5.4.34, 5.5.25
48 was removed Successfuly found the missing number
Output for 5.4.44
6 was removed Successfuly found the missing number
Output for 5.4.42
61 was removed Successfuly found the missing number
Output for 5.4.41
17 was removed Successfuly found the missing number
Output for 5.4.9, 5.4.25
24 was removed Successfuly found the missing number
Output for 4.3.1, 5.4.23
78 was removed Successfuly found the missing number
Output for 5.4.19, 5.4.22
93 was removed Successfuly found the missing number
Output for 5.4.14
11 was removed Successfuly found the missing number
Output for 5.0.4, 5.3.19, 5.4.13
84 was removed Successfuly found the missing number
Output for 5.4.11
10 was removed Successfuly found the missing number
Output for 5.3.17, 5.4.10
47 was removed Successfuly found the missing number
Output for 4.3.0, 5.4.7
44 was removed Successfuly found the missing number
Output for 5.2.10, 5.4.4
96 was removed Successfuly found the missing number
Output for 4.3.5, 5.2.2, 5.4.2
49 was removed Successfuly found the missing number
Output for 5.3.29
35 was removed Successfuly found the missing number
Output for 4.4.1, 5.2.17, 5.3.27
64 was removed Successfuly found the missing number
Output for 5.3.22
59 was removed Successfuly found the missing number
Output for 5.3.21
38 was removed Successfuly found the missing number
Output for 4.4.7, 4.4.9, 5.3.8, 5.3.20
75 was removed Successfuly found the missing number
Output for 5.3.16
13 was removed Successfuly found the missing number
Output for 5.3.15
33 was removed Successfuly found the missing number
Output for 5.3.14
25 was removed Successfuly found the missing number
Output for 5.2.6, 5.3.2
76 was removed Successfuly found the missing number
Output for 5.3.0
2 was removed Successfuly found the missing number
Output for 5.0.5, 5.2.9
83 was removed Successfuly found the missing number
Output for 5.2.7
98 was removed Successfuly found the missing number
Output for 5.2.4
100 was removed Successfuly found the missing number
Output for 5.2.3
89 was removed Successfuly found the missing number
Output for 5.0.0
77 was removed Successfuly found the missing number

preferences:
57.09 ms | 533 KiB | 5 Q