3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Given the Japanese numeral reading system, write a program that converts an integer into the equivalent Japanese reading. * * Basic numeral readings: * 1: ichi * 2: ni * 3: san * 4: yon * 5: go * 6: roku * 7: nana * 8: hachi * 9: kyuu * 10: juu * 20: ni-juu * 30: san-juu * 100: hyaku * 1000 : sen * 10,000: man * 100,000,000: oku * 1,000,000,000,000: chou * 10,000,000,000,000,000: kei * * Exceptions due to voice rounding in Japanese reading: * 300: sanbyaku * 600: roppyaku * 800: happyaku * 3000: sanzen * 8000: hassen * 1,000,000,000,000: itchou * 8,000,000,000,000: hatchou * 10,000,000,000,000: jutchou (also applies to multiplies of 10,000,000,000,000) * 10,000,000,000,000,000: ikkei * 60,000,000,000,000,000: rokkei * 80,000,000,000,000,000: hakkei * 100,000,000,000,000,000: jukkei (also applies to multiplies of 10,000,000,000,000,000) * 1,000,000,000,000,000,000: hyakkei (also applies to multiplies of 1,000,000,000,000,000,000) * * Starting at 10,000, numbers begin with ichi if no digit would otherwise precede, e.g. 1,000 is sen but 10,000 is ichi-man. * * Examples: * 11: juu ichi * 17: juu nana * 151: hyaku go-juu ichi * 302: san-byaku ni * 469: yon-hyaku roku-juu kyuu * 2025 : ni-sen ni-juu go * 10,403: ichi-man yon-byaku san * 41,892: yon-juu ichi-man happyaku kyuu-juu ni * 80,000,000,000,000: hachi-jutchou */ $inputNumber = 2025; $inputString = (String)$inputNumber; $numeralReadings = array( 1 => 'ichi', 2 => 'ni', 3 => 'san', 4 => 'yon', 5 => 'go', 6 => 'roku', 7 => 'nana', 8 => 'hachi', 9 => 'kyuu', 10 => 'juu', 20 => 'ni-juu', 30 => 'san-juu', 100 => 'hyaku', 1000 => 'sen', 10000 => 'man', 100000000 => 'oku', 1000000000000 => 'chou', 10000000000000000 => 'kei' ); $numeralExceptions = array( 300 => 'sanbyaku', 600 => 'roppyaku', 800 => 'happyaku', 3000 => 'sanzen', 8000 => 'hassen', 1000000000000 => 'itchou', 8000000000000 => 'hatchou', 10000000000000 => 'jutchou', 10000000000000000 => 'ikkei', 60000000000000000 => 'rokkei', 80000000000000000 => 'hakkei', 100000000000000000 => 'jukkei', 1000000000000000000 => 'hyakkei' ); if ($inputString > 10000) { $inp1 = floor($inputString / 1000); $inp = $inputString - ($inp1 * 1000); if($inp !== 0) { read($inp1, $numeralReadings, $numeralExceptions, false); read($inp, $numeralReadings, $numeralExceptions); } else { read($inputString, $numeralReadings, $numeralExceptions); } } else { read($inputString, $numeralReadings, $numeralExceptions); } function read($inputStr, $numeralReadings, $numeralExceptions, $parse1 = true) { $splitString = str_split($inputStr); $returnString = ''; $appendIchi = false; $firstNumber = null; foreach ($splitString as $key => $number) { if ($firstNumber == null) { $firstNumber = $number; } if ($number !== 0) { $int = 1; $a = count($splitString) - 1 - $key; for ($i = 0; $i < $a; $i++) { $int = $int * 10; } $tempNumber = (int)$number * $int; if (isset($numeralExceptions[$tempNumber])) { $returnString .= $numeralExceptions[$tempNumber] . ' '; continue; } if (isset($numeralReadings[$tempNumber])) { if ($parse1 == false && $tempNumber == 1) { continue; } $returnString .= $numeralReadings[$tempNumber] . ' '; continue; } if (isset($numeralReadings[(int)$number])) { if ($parse1 == false && $tempNumber == 1) { continue; } $returnString .= $numeralReadings[(int)$number]; if ($int !== 1) { $returnString .= '-' . $numeralReadings[$int]; } $returnString .= ' '; } } } echo $returnString; }

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.3.60.0140.00718.09
8.3.50.0090.00721.92
8.3.40.0070.00718.70
8.3.30.0100.00319.27
8.3.20.0070.00020.31
8.3.10.0060.00321.83
8.3.00.0040.00422.37
8.2.180.0100.00716.50
8.2.170.0000.01722.96
8.2.160.0070.00720.39
8.2.150.0040.00424.18
8.2.140.0030.00524.66
8.2.130.0030.00526.16
8.2.120.0080.00019.76
8.2.110.0000.01119.30
8.2.100.0110.00017.78
8.2.90.0000.00819.20
8.2.80.0050.00317.97
8.2.70.0040.00417.63
8.2.60.0080.00018.05
8.2.50.0040.00418.07
8.2.40.0050.00318.22
8.2.30.0050.00318.19
8.2.20.0050.00217.66
8.2.10.0000.00817.73
8.2.00.0040.00417.80
8.1.280.0000.01525.92
8.1.270.0030.00622.14
8.1.260.0040.00428.09
8.1.250.0040.00428.09
8.1.240.0100.00021.37
8.1.230.0090.00317.64
8.1.220.0040.00417.78
8.1.210.0040.00418.77
8.1.200.0030.00617.47
8.1.190.0000.00917.48
8.1.180.0000.00818.10
8.1.170.0060.00318.77
8.1.160.0040.00421.94
8.1.150.0070.00018.74
8.1.140.0040.00417.48
8.1.130.0000.00717.77
8.1.120.0040.00417.57
8.1.110.0000.00817.56
8.1.100.0040.00417.45
8.1.90.0000.00817.51
8.1.80.0000.00717.41
8.1.70.0040.00417.49
8.1.60.0040.00417.68
8.1.50.0060.00317.50
8.1.40.0040.00417.57
8.1.30.0070.00017.75
8.1.20.0080.00017.71
8.1.10.0000.00717.48
8.1.00.0000.00817.54
8.0.300.0040.00418.77
8.0.290.0030.00616.75
8.0.280.0030.00318.42
8.0.270.0040.00417.32
8.0.260.0030.00318.50
8.0.250.0040.00417.03
8.0.240.0070.00317.05
8.0.230.0050.00316.98
8.0.220.0000.00716.96
8.0.210.0020.00516.94
8.0.200.0030.00316.99
8.0.190.0040.00416.99
8.0.180.0040.00416.99
8.0.170.0040.00416.88
8.0.160.0000.00716.82
8.0.150.0060.00316.98
8.0.140.0050.00316.81
8.0.130.0060.00013.39
8.0.120.0080.00016.95
8.0.110.0040.00416.93
8.0.100.0040.00417.02
8.0.90.0040.00417.02
8.0.80.0070.01016.94
8.0.70.0070.00016.94
8.0.60.0070.00016.84
8.0.50.0050.00316.97
8.0.30.0090.00917.15
8.0.20.0120.00617.40
8.0.10.0080.00016.92
8.0.00.0110.00716.79
7.4.330.0030.00315.10
7.4.320.0000.00616.68
7.4.300.0070.00016.67
7.4.290.0040.00416.59
7.4.280.0030.00316.56
7.4.270.0040.00416.69
7.4.260.0040.00416.68
7.4.250.0000.00716.45
7.4.240.0030.00516.61
7.4.230.0040.00416.69
7.4.220.0030.01616.57
7.4.210.0110.00516.63
7.4.200.0040.00416.59
7.4.190.0030.00316.59
7.4.160.0130.00316.48
7.4.150.0110.00717.40
7.4.140.0080.01117.86
7.4.130.0140.00516.61
7.4.120.0090.01216.71
7.4.110.0070.01016.70
7.4.100.0140.00316.62
7.4.90.0170.00716.66
7.4.80.0090.00919.39
7.4.70.0140.00716.64
7.4.60.0150.00316.40
7.4.50.0000.00816.13
7.4.40.0100.00322.77
7.4.30.0140.00316.52
7.4.00.0110.00014.99
7.3.330.0060.00013.42
7.3.320.0050.00013.24
7.3.310.0000.00816.48
7.3.300.0000.00716.39
7.3.290.0100.01016.46
7.3.280.0080.01016.40
7.3.270.0070.01117.40
7.3.260.0090.00916.45
7.3.250.0080.01216.43
7.3.240.0100.00716.47
7.3.230.0070.01016.49
7.3.210.0070.01016.72
7.3.200.0080.01219.39
7.3.190.0080.00816.62
7.3.180.0070.01016.48
7.3.170.0070.01016.46
7.3.160.0030.01316.73
7.3.120.0100.00314.79
7.2.330.0080.00816.82
7.2.320.0130.00916.89
7.2.310.0130.01016.66
7.2.300.0080.00816.78
7.2.290.0040.01316.67
7.2.00.0030.00919.55
7.1.100.0040.00818.23
7.1.70.0040.00417.09
7.1.60.0030.02219.82
7.1.50.0030.01616.70
7.1.00.0000.08022.33
7.0.200.0050.00216.83
7.0.140.0000.07021.99
7.0.60.0030.09019.94
7.0.50.0070.04317.74
7.0.40.0100.04720.30
7.0.30.0300.06320.19
7.0.20.0300.05320.09
7.0.10.0070.09020.12
7.0.00.0000.09020.19
5.6.280.0130.06321.14
5.6.210.0070.08320.54
5.6.200.0030.05718.25
5.6.190.0070.05020.52
5.6.180.0130.04320.67
5.6.170.0200.04720.45
5.6.160.0070.05720.44
5.6.150.0030.06018.23
5.6.140.0030.04018.20
5.6.130.0070.05318.24
5.6.120.0000.07021.01
5.6.110.0070.04020.98
5.6.100.0000.05721.15
5.6.90.0070.03721.04
5.6.80.0100.07720.55
5.5.350.0370.06720.52
5.5.340.0100.07717.96
5.5.330.0070.08320.29
5.5.320.0300.06320.30
5.5.310.0200.05720.42
5.5.300.0100.04717.99
5.5.290.0030.09017.96
5.5.280.0130.07720.97
5.5.270.0100.04020.96
5.5.260.0100.07320.91
5.5.250.0130.07320.60
5.5.240.0030.03720.37
5.4.450.0100.06319.58
5.4.440.0070.06319.47
5.4.430.0130.05719.47
5.4.420.0100.07719.46
5.4.410.0100.06719.04
5.4.400.0100.07719.16
5.4.390.0130.06719.24
5.4.380.0130.07318.92
5.4.370.0000.08319.13
5.4.360.0070.03718.85
5.4.350.0070.05719.20
5.4.340.0100.08019.00
5.4.320.0100.04718.98
5.4.310.0070.08019.16
5.4.300.0070.07719.15
5.4.290.0200.06318.85
5.4.280.0070.07719.24
5.4.270.0070.07318.95
5.4.260.0030.04019.15
5.4.250.0070.07719.27
5.4.240.0100.07018.85
5.4.230.0070.03718.84
5.4.220.0070.06319.23
5.4.210.0030.07718.92
5.4.200.0100.06319.23
5.4.190.0030.06319.10
5.4.180.0070.07319.07
5.4.170.0100.04018.86
5.4.160.0000.07719.08
5.4.150.0030.05719.13
5.4.140.0030.04016.27
5.4.130.0030.04016.35
5.4.120.0070.06716.26
5.4.110.0170.06016.39
5.4.100.0130.06716.38
5.4.90.0000.05316.46
5.4.80.0030.03716.39
5.4.70.0030.04716.39
5.4.60.0070.03716.41
5.4.50.0170.03716.41
5.4.40.0100.07016.27
5.4.30.0000.06716.38
5.4.20.0000.07716.36
5.4.10.0000.04716.37
5.4.00.0070.04315.89
5.3.290.0000.05014.70
5.3.280.0100.07714.69
5.3.270.0030.07714.64
5.3.260.0100.06314.63
5.3.250.0030.07014.64
5.3.240.0100.07014.70
5.3.230.0130.07014.68
5.3.220.0030.04714.60
5.3.210.0030.07714.64
5.3.200.0030.07314.63
5.3.190.0070.04014.59
5.3.180.0000.04014.62
5.3.170.0070.07314.64
5.3.160.0070.03714.64
5.3.150.0000.04314.74
5.3.140.0100.03014.63
5.3.130.0030.05014.72
5.3.120.0000.07014.61
5.3.110.0000.07314.57
5.3.100.0030.05314.08
5.3.90.0070.03714.05
5.3.80.0030.04713.98
5.3.70.0000.06714.05
5.3.60.0130.05714.07
5.3.50.0130.06013.86
5.3.40.0130.06014.01
5.3.30.0070.07013.98
5.3.20.0070.04013.63
5.3.10.0030.04013.56
5.3.00.0030.04313.68
5.2.170.0030.06711.14
5.2.160.0000.05011.21
5.2.150.0000.03711.12
5.2.140.0070.05711.32
5.2.130.0030.03311.13
5.2.120.0070.03011.08
5.2.110.0030.06711.13
5.2.100.0000.06311.21
5.2.90.0070.05711.09
5.2.80.0030.02711.20
5.2.70.0030.06311.10
5.2.60.0030.05011.08
5.2.50.0000.06311.00
5.2.40.0100.05310.96
5.2.30.0000.06311.00
5.2.20.0070.03311.01
5.2.10.0030.04010.95
5.2.00.0030.04010.80
5.1.60.0000.04710.04
5.1.50.0030.03010.01
5.1.40.0100.04310.03
5.1.30.0030.02710.41
5.1.20.0030.03310.44
5.1.10.0030.06010.06
5.1.00.0000.05710.06
5.0.50.0000.0339.10
5.0.40.0070.0439.10
5.0.30.0030.0679.10
5.0.20.0000.0479.10
5.0.10.0100.0279.10
5.0.00.0000.0679.10
4.4.90.0030.0379.10
4.4.80.0000.0379.10
4.4.70.0030.0309.10
4.4.60.0030.0139.10
4.4.50.0000.0409.10
4.4.40.0000.0279.10
4.4.30.0000.0379.10
4.4.20.0030.0339.10
4.4.10.0000.0309.10
4.4.00.0100.0509.10
4.3.110.0030.0209.10
4.3.100.0030.0309.10
4.3.90.0070.0239.10
4.3.80.0000.0539.10
4.3.70.0000.0309.10
4.3.60.0030.0339.10
4.3.50.0000.0379.10
4.3.40.0070.0479.10
4.3.30.0030.0179.10
4.3.20.0000.0379.10
4.3.10.0000.0209.10
4.3.00.0000.0339.10

preferences:
57.82 ms | 401 KiB | 5 Q