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 = 30000; $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.0150.00618.31
8.3.50.0050.01322.05
8.3.40.0120.00318.93
8.3.30.0140.00019.13
8.3.20.0070.00020.21
8.3.10.0000.00921.92
8.3.00.0000.00822.39
8.2.180.0190.00316.88
8.2.170.0140.00022.96
8.2.160.0110.00420.98
8.2.150.0000.00824.18
8.2.140.0050.00324.66
8.2.130.0040.00426.16
8.2.120.0000.00817.63
8.2.110.0090.00022.26
8.2.100.0040.00817.84
8.2.90.0000.00819.08
8.2.80.0090.00318.02
8.2.70.0060.00317.63
8.2.60.0080.00018.04
8.2.50.0000.00818.07
8.2.40.0040.00418.16
8.2.30.0040.00418.16
8.2.20.0000.00817.78
8.2.10.0080.00019.63
8.2.00.0040.00417.75
8.1.280.0140.00025.92
8.1.270.0040.00422.27
8.1.260.0070.00026.35
8.1.250.0040.00428.09
8.1.240.0030.00723.73
8.1.230.0070.00419.21
8.1.220.0030.00517.77
8.1.210.0000.00818.77
8.1.200.0030.00917.48
8.1.190.0100.00317.38
8.1.180.0000.00818.10
8.1.170.0000.00818.60
8.1.160.0070.00022.10
8.1.150.0030.00518.65
8.1.140.0080.00417.43
8.1.130.0030.00317.84
8.1.120.0050.00217.56
8.1.110.0000.00917.52
8.1.100.0000.00717.39
8.1.90.0040.00417.46
8.1.80.0000.00717.54
8.1.70.0040.00417.48
8.1.60.0000.00817.64
8.1.50.0000.00717.54
8.1.40.0000.00717.58
8.1.30.0000.00917.71
8.1.20.0040.00417.73
8.1.10.0000.00817.63
8.1.00.0050.00317.53
8.0.300.0030.00518.77
8.0.290.0000.00817.28
8.0.280.0070.00018.51
8.0.270.0000.00717.34
8.0.260.0000.00616.85
8.0.250.0000.00716.99
8.0.240.0000.00716.97
8.0.230.0040.00417.01
8.0.220.0030.00416.98
8.0.210.0000.00717.04
8.0.200.0030.00317.10
8.0.190.0040.00417.10
8.0.180.0080.00016.95
8.0.170.0030.00616.93
8.0.160.0040.00416.89
8.0.150.0040.00416.91
8.0.140.0040.00417.03
8.0.130.0000.00513.45
8.0.120.0040.00416.83
8.0.110.0040.00416.95
8.0.100.0000.00716.90
8.0.90.0040.00417.01
8.0.80.0070.00717.00
8.0.70.0080.00016.87
8.0.60.0040.00417.04
8.0.50.0000.00716.88
8.0.30.0140.00517.04
8.0.20.0160.00317.40
8.0.10.0000.00717.02
8.0.00.0090.00916.70
7.4.330.0000.00615.00
7.4.320.0040.00416.66
7.4.300.0030.00316.67
7.4.290.0040.00416.59
7.4.280.0040.00216.65
7.4.270.0030.00316.67
7.4.260.0030.00316.55
7.4.250.0050.00216.52
7.4.240.0020.00516.49
7.4.230.0000.00716.75
7.4.220.0030.01416.65
7.4.210.0080.00816.53
7.4.200.0070.00016.46
7.4.190.0040.00416.53
7.4.160.0080.00816.71
7.4.150.0070.01017.40
7.4.140.0080.01317.86
7.4.130.0110.00916.59
7.4.120.0100.00716.54
7.4.110.0210.00416.43
7.4.100.0030.01316.72
7.4.90.0030.01516.66
7.4.80.0200.00319.39
7.4.70.0120.00316.63
7.4.60.0070.01016.67
7.4.50.0040.00416.61
7.4.40.0060.00922.77
7.4.30.0040.01416.77
7.4.00.0090.01015.02
7.3.330.0000.00513.35
7.3.320.0000.00613.24
7.3.310.0080.00016.52
7.3.300.0050.00216.31
7.3.290.0100.00716.44
7.3.280.0060.00916.44
7.3.270.0100.00717.40
7.3.260.0030.01316.39
7.3.250.0050.01516.52
7.3.240.0100.00716.66
7.3.230.0130.00316.68
7.3.210.0100.00616.52
7.3.200.0090.00919.39
7.3.190.0070.01116.49
7.3.180.0100.00616.33
7.3.170.0060.00916.54
7.3.160.0090.00616.35
7.3.120.0070.01114.97
7.3.110.0060.01115.06
7.3.100.0040.01214.71
7.3.90.0030.01314.89
7.3.80.0030.00915.00
7.3.70.0090.00514.93
7.3.60.0040.00914.87
7.3.50.0080.00614.89
7.3.40.0030.01014.87
7.3.30.0030.01014.95
7.3.20.0070.00516.45
7.3.10.0080.00616.63
7.3.00.0050.00816.63
7.2.330.0100.00716.48
7.2.320.0090.00916.85
7.2.310.0130.00316.56
7.2.300.0130.00316.70
7.2.290.0060.01116.78
7.2.250.0050.01015.05
7.2.240.0050.01415.09
7.2.230.0040.01115.00
7.2.220.0070.00615.28
7.2.210.0050.00815.19
7.2.200.0030.01115.01
7.2.190.0050.00614.80
7.2.180.0070.00715.20
7.2.170.0060.01015.00
7.2.160.0040.00415.22
7.2.150.0060.00916.91
7.2.140.0070.01017.13
7.2.130.0070.01116.84
7.2.120.0050.00516.93
7.2.110.0080.00417.01
7.2.100.0110.00416.99
7.2.90.0030.01017.01
7.2.80.0100.00717.02
7.2.70.0070.00717.20
7.2.60.0110.00317.02
7.2.50.0040.01116.95
7.2.40.0000.01117.05
7.2.30.0080.00816.96
7.2.20.0060.00917.13
7.2.10.0040.00816.78
7.2.00.0060.00317.11
7.1.330.0060.01115.83
7.1.320.0090.00815.73
7.1.310.0060.00815.81
7.1.300.0080.00515.83
7.1.290.0050.00915.67
7.1.280.0090.00515.69
7.1.270.0080.00515.77
7.1.260.0090.00515.84
7.1.250.0070.00315.81
7.1.240.0030.01415.63
7.1.230.0040.00815.96
7.1.220.0000.01315.70
7.1.210.0030.01416.00
7.1.200.0050.00515.54
7.1.190.0000.01215.69
7.1.180.0040.00715.75
7.1.170.0060.00315.88
7.1.160.0090.00015.75
7.1.150.0040.00815.80
7.1.140.0000.01115.65
7.1.130.0060.00915.79
7.1.120.0030.00615.82
7.1.110.0070.00715.73
7.1.100.0060.00615.93
7.1.90.0040.00815.62
7.1.80.0000.00815.66
7.1.70.0030.00916.41
7.1.60.0030.01317.80
7.1.50.0110.00916.33
7.1.40.0060.00915.72
7.1.30.0100.00316.00
7.1.20.0030.01415.90
7.1.10.0060.00615.77
7.1.00.0030.04219.06
7.0.330.0030.01015.49
7.0.320.0000.00915.33
7.0.310.0030.00615.58
7.0.300.0090.00315.30
7.0.290.0030.00915.55
7.0.280.0030.00715.23
7.0.270.0030.00615.63
7.0.260.0060.00615.10
7.0.250.0030.01015.46
7.0.240.0040.00715.64
7.0.230.0080.00815.43
7.0.220.0060.00615.36
7.0.210.0040.00715.29
7.0.200.0020.01015.99
7.0.190.0070.00715.15
7.0.180.0110.00415.40
7.0.170.0060.00615.50
7.0.160.0060.00615.16
7.0.150.0030.00515.52
7.0.140.0080.03518.64
7.0.130.0070.00415.38
7.0.120.0070.00315.39
7.0.110.0030.00715.32
7.0.100.0030.00715.56
7.0.90.0040.01115.29
7.0.80.0060.00915.61
7.0.70.0090.00615.47
7.0.60.0060.02417.86
7.0.50.0050.04516.61
7.0.40.0080.04416.77
7.0.30.0170.03416.78
7.0.20.0130.04716.83
7.0.10.0200.03716.69
7.0.00.0080.03016.88
5.6.400.0090.00014.55
5.6.390.0060.00614.58
5.6.380.0170.00014.67
5.6.370.0090.00914.32
5.6.360.0030.01114.42
5.6.350.0070.00714.63
5.6.340.0000.00914.14
5.6.330.0070.00714.75
5.6.320.0100.00614.85
5.6.310.0070.00414.68
5.6.300.0090.00614.63
5.6.290.0000.01114.62
5.6.280.0080.04017.97
5.6.270.0000.01314.80
5.6.260.0030.01114.58
5.6.250.0080.00414.70
5.6.240.0040.00814.52
5.6.230.0070.00714.45
5.6.220.0120.00314.72
5.6.210.0090.04017.49
5.6.200.0100.02816.19
5.6.190.0120.02017.62
5.6.180.2030.02517.42
5.6.170.0130.04717.60
5.6.160.0140.03717.38
5.6.150.0080.04316.28
5.6.140.0070.02916.34
5.6.130.0090.04116.26
5.6.120.0050.04817.88
5.6.110.0080.04617.64
5.6.100.0020.02817.56
5.6.90.0150.04017.78
5.6.80.0070.04317.42
5.6.70.0250.02517.39
5.6.60.0030.00614.43
5.6.50.0040.00414.11
5.6.40.0040.01114.20
5.6.30.0100.00314.28
5.6.20.0070.00714.55
5.6.10.0060.00314.56
5.6.00.0070.00714.36
5.5.380.0000.00814.13
5.5.370.0090.00614.48
5.5.360.0040.00414.32
5.5.350.0060.04217.35
5.5.340.0030.02616.31
5.5.330.0070.03017.31
5.5.320.0170.03217.28
5.5.310.0100.04917.38
5.5.300.0100.04216.32
5.5.290.0070.04716.12
5.5.280.0070.03017.72
5.5.270.0100.04517.57
5.5.260.0080.03817.54
5.5.250.0200.02817.60
5.5.240.0150.03217.31
5.5.230.0060.00314.37
5.5.220.0030.00614.43
5.5.210.0090.00014.38
5.5.200.0040.01114.57
5.5.190.0040.00814.53
5.5.180.0110.00414.32
5.5.170.0060.00614.36
5.5.160.0000.01514.00
5.5.150.0030.00614.38
5.5.140.0030.01214.57
5.5.130.0030.00914.09
5.5.120.0120.00314.58
5.5.110.0070.00714.23
5.5.100.0030.01014.52
5.5.90.0060.01214.30
5.5.80.0100.00314.53
5.5.70.0100.00714.50
5.5.60.0090.00614.54
5.5.50.0060.01214.25
5.5.40.0110.00514.36
5.5.30.0030.01714.39
5.5.20.0060.01314.34
5.5.10.0030.01314.30
5.5.00.0120.00414.17
5.4.450.0340.02515.58
5.4.440.0150.02015.61
5.4.430.0730.00215.67
5.4.420.0580.00515.80
5.4.410.0080.02815.46
5.4.400.0100.02815.39
5.4.390.0130.02615.36
5.4.380.0150.03215.22
5.4.370.0020.03815.26
5.4.360.0080.02615.28
5.4.350.0120.03015.35
5.4.340.0080.03215.36
5.4.330.0060.00011.95
5.4.320.0060.02012.24
5.4.310.0060.02112.24
5.4.300.0050.02212.24
5.4.290.0040.02112.24
5.4.280.0050.02412.19
5.4.270.0050.02412.17
5.4.260.0050.02212.17
5.4.250.0050.02512.17
5.4.240.0070.02212.17
5.4.230.0050.02412.17
5.4.220.0040.02112.17
5.4.210.0060.01912.17
5.4.200.0080.01912.17
5.4.190.0040.02312.16
5.4.180.0060.02512.16
5.4.170.0030.02612.17
5.4.160.0020.02912.17
5.4.150.0060.02212.17
5.4.140.0060.02012.01
5.4.130.0050.02212.00
5.4.120.0030.02811.98
5.4.110.0030.02411.98
5.4.100.0040.02011.98
5.4.90.0020.02411.98
5.4.80.0080.01911.98
5.4.70.0020.02411.98
5.4.60.0040.02311.98
5.4.50.0070.01911.97
5.4.40.0060.02311.97
5.4.30.0100.02311.96
5.4.20.0090.02211.97
5.4.10.0050.02111.97
5.4.00.0050.01911.71
5.3.290.0020.02612.38
5.3.280.0070.01912.33
5.3.270.0040.02412.34
5.3.260.0050.02312.34
5.3.250.0080.01912.34
5.3.240.0040.02512.34
5.3.230.0070.02112.33
5.3.220.0060.02212.32
5.3.210.0030.02612.32
5.3.200.0040.02112.32
5.3.190.0040.02212.32
5.3.180.0060.02312.31
5.3.170.0060.02212.31
5.3.160.0040.02212.31
5.3.150.0070.02212.31
5.3.140.0040.02312.31
5.3.130.0070.02112.30
5.3.120.0020.02412.31
5.3.110.0040.02212.30
5.3.100.0070.01812.04
5.3.90.0050.02212.03
5.3.80.0050.02012.02
5.3.70.0040.02212.02
5.3.60.0050.02012.01
5.3.50.0040.02211.99
5.3.40.0030.02111.99
5.3.30.0050.01911.97
5.3.20.0040.01911.86
5.3.10.0040.02011.84
5.3.00.0040.02111.83
5.2.170.0070.0289.22
5.2.160.0030.0319.22
5.2.150.0030.0369.23
5.2.140.0030.0349.22
5.2.130.0020.0319.18
5.2.120.0020.0309.18
5.2.110.0050.0299.19
5.2.100.0040.0319.19
5.2.90.0060.0289.18
5.2.80.0040.0319.17
5.2.70.0080.0289.17
5.2.60.0020.0349.13
5.2.50.0060.0319.10
5.2.40.0030.0319.08
5.2.30.0040.0319.05
5.2.20.0040.0329.04
5.2.10.0050.0288.97
5.2.00.0050.0288.82
5.1.60.0040.0248.11
5.1.50.0020.0268.11
5.1.40.0020.0268.09
5.1.30.0060.0238.44
5.1.20.0040.0268.46
5.1.10.0050.0248.19
5.1.00.0070.0248.19
5.0.50.0040.0206.68
5.0.40.0030.0196.53
5.0.30.0050.0306.35
5.0.20.0020.0206.32
5.0.10.0020.0256.29
5.0.00.0020.0346.29
4.4.90.0040.0144.78
4.4.80.0020.0164.76
4.4.70.0030.0154.75
4.4.60.0040.0144.75
4.4.50.0020.0164.77
4.4.40.0040.0244.71
4.4.30.0020.0174.76
4.4.20.0030.0174.85
4.4.10.0030.0164.85
4.4.00.0040.0234.76
4.3.110.0050.0164.67
4.3.100.0010.0194.67
4.3.90.0030.0144.63
4.3.80.0030.0244.58
4.3.70.0020.0154.63
4.3.60.0030.0144.63
4.3.50.0030.0154.63
4.3.40.0000.0274.54
4.3.30.0010.0173.33
4.3.20.0010.0173.32
4.3.10.0000.0183.27
4.3.00.0030.01713.27

preferences:
41.89 ms | 401 KiB | 5 Q