3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Para testear tu código en nuestros servidores debes mantener la estructura expuesta abajo. // Eres libre de crear nuevas funciones/procedimientos. // Recuerda que el código que escribas podrá ser visto por las empresas a las que te postules. ?> <?php $relieve = [[8, 9, 2, 2, 3, 5], [9, 8, 3, 2, 4, 5], [9, 7, 2, 2, 4, 3], [9, 9, 2, 4, 4, 3], [9, 2, 3, 4, 3, 5]]; var_dump(celdas_vecinas($relieve, 0, 1)); // Representación gráfica // 8 9 2 2 3 5 // 9 8 3 2 4 5 // 9 7 2 2 4 3 // 9 9 2 4 4 3 // 9 2 3 4 3 5 function encontrar_bordes($relieve){ $resp = []; for($i=0;$i<count($relieve);$i++){ for($j=0;$j<count($relieve[$i]);$j++){ $resp[$i][$j] = 0; } } return $resp; // return [[1, 0, 1, 1, 0, 0], [0, 0, 0, 1, 0, 0], [0, 0, 1, 1, 0, 1], [0, 0, 1, 0, 0, 1], [0, 1, 0, 0, 1, 0 ]]; } function celdas_vecinas($relieve, $i, $j){ $celdas = []; // si la celda no existe, regresamos. if(!celda_existe($relieve, $i, $j)){ return null; } if(celda_existe($relieve, $i-1, $j-1)) { $celdas[] = $relieve[$i-1][$j-1]; } if(celda_existe($relieve, $i-1, $j)) { $celdas[] = $relieve[$i-1][$j]; } if(celda_existe($relieve, $i-1, $j+1)) { $celdas[] = $relieve[$i-1][$j+1]; } if(celda_existe($relieve, $i, $j-1)) { $celdas[] = $relieve[$i][$j-1]; } if(celda_existe($relieve, $i, $j+1)) { $celdas[] = $relieve[$i][$j+1]; } if(celda_existe($relieve, $i+1, $j-1)) { $celdas[] = $relieve[$i+1][$j-1]; } if(celda_existe($relieve, $i+1, $j)) { $celdas[] = $relieve[$i+1][$j]; } if(celda_existe($relieve, $i+1, $j+1)) { $celdas[] = $relieve[$i+1][$j+1]; } //devolvemos los valores de las celdas vecinas return $celdas; } // verificar que una celda existe function celda_existe($arreglo, $x, $y){ if(!array_key_exists($x, $arreglo)){ return false; }elseif(!array_key_exists($y, $arreglo[$x])){ return false; }else{ return true; } } ?>

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.4.20.0120.00917.68
8.4.10.0070.01417.42
8.3.150.0110.00717.27
8.3.140.0150.00316.62
8.3.130.0060.00316.43
8.3.120.0060.00320.70
8.3.110.0070.00320.94
8.3.100.0100.01016.76
8.3.90.0040.00426.77
8.3.80.0090.00018.56
8.3.70.0160.00616.75
8.3.60.0160.01016.50
8.3.50.0120.00621.27
8.3.40.0100.01018.85
8.3.30.0100.00318.82
8.3.20.0000.00918.72
8.3.10.0000.00720.01
8.3.00.0050.00317.93
8.2.270.0150.00316.96
8.2.260.0080.00016.68
8.2.250.0030.00618.46
8.2.240.0080.00018.73
8.2.230.0060.01222.58
8.2.220.0100.00624.06
8.2.210.0070.00726.77
8.2.200.0050.00518.54
8.2.190.0080.00816.58
8.2.180.0080.00818.29
8.2.170.0140.00322.96
8.2.160.0060.00919.20
8.2.150.0090.00024.18
8.2.140.0040.00424.66
8.2.130.0040.00421.14
8.2.120.0000.00826.35
8.2.110.0060.00321.04
8.2.100.0090.00318.16
8.2.90.0040.00419.17
8.2.80.0060.00317.97
8.2.70.0000.00817.63
8.2.60.0040.00417.93
8.2.50.0050.00318.07
8.2.40.0080.00018.16
8.2.30.0000.00918.14
8.2.20.0030.00717.72
8.2.10.0000.00818.15
8.2.00.0050.00318.11
8.1.310.0150.00316.43
8.1.300.0030.00718.26
8.1.290.0070.00330.84
8.1.280.0080.00825.92
8.1.270.0040.00423.79
8.1.260.0070.00028.09
8.1.250.0050.00328.09
8.1.240.0030.00622.20
8.1.230.0110.00017.57
8.1.220.0080.00017.79
8.1.210.0080.00018.77
8.1.200.0030.00617.35
8.1.190.0050.00317.22
8.1.180.0000.01018.10
8.1.170.0000.00818.62
8.1.160.0020.00518.83
8.1.150.0000.00718.84
8.1.140.0040.00419.67
8.1.130.0040.00417.71
8.1.120.0040.00417.50
8.1.110.0050.00317.44
8.1.100.0000.00717.42
8.1.90.0020.00517.40
8.1.80.0000.00717.46
8.1.70.0000.00817.53
8.1.60.0030.00517.60
8.1.50.0060.00317.45
8.1.40.0050.00317.47
8.1.30.0030.00517.70
8.1.20.0000.00817.63
8.1.10.0040.00417.47
8.1.00.0070.00017.48
8.0.300.0050.00218.77
8.0.290.0100.00016.58
8.0.280.0030.00318.41
8.0.270.0000.00717.29
8.0.260.0030.00717.35
8.0.250.0070.00016.93
8.0.240.0000.00716.99
8.0.230.0040.00417.00
8.0.220.0000.00716.90
8.0.210.0030.00316.95
8.0.200.0000.00716.89
8.0.190.0000.00717.02
8.0.180.0050.00516.98
8.0.170.0040.00416.89
8.0.160.0000.00717.00
8.0.150.0110.00016.88
8.0.140.0000.00916.91
8.0.130.0030.00313.41
8.0.120.0040.00416.83
8.0.110.0080.00016.90
8.0.100.0000.00816.90
8.0.90.0080.00016.98
8.0.80.0100.00716.88
8.0.70.0000.00716.92
8.0.60.0040.00416.88
8.0.50.0040.00416.88
8.0.30.0120.00717.16
8.0.20.0140.00417.40
8.0.10.0020.00517.00
8.0.00.0090.01216.80
7.4.330.0050.00015.19
7.4.320.0000.00616.54
7.4.300.0000.00616.57
7.4.290.0030.00316.58
7.4.280.0060.00316.54
7.4.270.0000.00716.69
7.4.260.0070.00016.45
7.4.250.0000.00816.38
7.4.240.0080.00016.55
7.4.230.0040.00416.43
7.4.220.0000.01916.53
7.4.210.0000.01416.58
7.4.200.0040.00416.36
7.4.160.0080.00816.48
7.4.150.0090.00917.40
7.4.140.0090.01217.86
7.4.130.0130.00516.54
7.4.120.0110.00816.49
7.4.110.0110.01016.59
7.4.100.0080.00816.34
7.4.90.0080.00916.64
7.4.80.0120.00519.39
7.4.70.0040.01216.57
7.4.60.0150.00616.54
7.4.50.0100.00716.51
7.4.40.0150.01016.71
7.4.30.0070.01516.42
7.4.00.0140.00014.72
7.3.330.0000.00613.43
7.3.320.0050.00013.23
7.3.310.0080.00016.30
7.3.300.0030.00316.41
7.3.290.0090.01016.41
7.3.280.0060.01216.36
7.3.270.0130.00617.40
7.3.260.0090.01216.51
7.3.250.0060.01316.50
7.3.240.0140.01116.49
7.3.230.0030.01316.61
7.3.210.0130.00316.51
7.3.200.0100.01019.39
7.3.190.0160.00616.50
7.3.180.0090.01316.36
7.3.170.0090.01216.50
7.3.160.0090.00916.59
7.2.330.0130.01016.67
7.2.320.0170.00016.83
7.2.310.0120.01016.53
7.2.300.0100.00716.79
7.2.290.0070.01016.52
7.2.60.0060.00916.77
7.2.00.0030.01019.48
7.1.200.0030.01015.44
7.1.100.0780.00716.20
7.1.70.0180.00317.30
7.1.60.0070.01519.38
7.1.00.0100.07022.50
7.0.200.0320.00414.95
7.0.60.0200.05720.07
7.0.50.0330.05020.38
7.0.40.0270.05320.39
7.0.30.0100.06320.39
7.0.20.0170.06020.40
7.0.10.0100.05720.30
7.0.00.0270.05020.47
5.6.280.0070.07020.88
5.6.210.0070.08320.50
5.6.200.0270.05721.15
5.6.190.0070.06721.10
5.6.180.0130.05721.07
5.6.170.0270.04721.15
5.6.160.0130.05721.07
5.6.150.0100.06321.07
5.6.140.0130.05321.14
5.6.130.0130.06021.08
5.6.120.0200.05320.95
5.6.110.0200.05721.15
5.6.100.0100.06021.14
5.6.90.0170.05721.10
5.6.80.0170.05720.45
5.6.70.0100.06020.48
5.6.60.0230.04320.52
5.6.50.0230.06720.49
5.6.40.0130.05720.43
5.6.30.0170.05320.36
5.6.20.0070.05720.50
5.6.10.0000.06320.47
5.6.00.0330.04720.45
5.5.350.0300.06020.51
5.5.340.0100.08020.87
5.5.330.0200.05021.06
5.5.320.0170.05320.70
5.5.310.0130.05720.87
5.5.300.0200.05020.80
5.5.290.0170.05320.87
5.5.280.0130.06020.93
5.5.270.0170.05720.84
5.5.260.0170.05721.05
5.5.250.0100.06020.68
5.5.240.0170.05020.41
5.5.230.0070.06320.25
5.5.220.0100.05720.43
5.5.210.0200.04720.38
5.5.200.0200.05020.41
5.5.190.0070.06320.38
5.5.180.0100.05720.28
5.5.160.0200.05020.20
5.5.150.0100.06020.18
5.5.140.0170.05320.12
5.5.130.0200.05020.25
5.5.120.0270.04020.24
5.5.110.0130.05320.25
5.5.100.0170.05720.09
5.5.90.0200.05020.14
5.5.80.0070.06020.13
5.5.70.0130.05320.12
5.5.60.0130.06020.13
5.5.50.0030.06320.07
5.5.40.0130.05020.15
5.5.30.0130.05320.07
5.5.20.0230.05020.14
5.5.10.0170.05320.10
5.5.00.0200.05020.01

preferences:
34.16 ms | 403 KiB | 5 Q