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 = 14000; $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.0130.00918.19
8.3.50.0220.00922.12
8.3.40.0090.00619.09
8.3.30.0140.00019.17
8.3.20.0000.00820.34
8.3.10.0000.00822.03
8.3.00.0040.00422.52
8.2.180.0110.00816.75
8.2.170.0110.00722.96
8.2.160.0060.00820.89
8.2.150.0040.00424.18
8.2.140.0050.00324.66
8.2.130.0070.00026.16
8.2.120.0050.00317.75
8.2.110.0030.00621.99
8.2.100.0120.00017.91
8.2.90.0090.00019.12
8.2.80.0040.00419.68
8.2.70.0030.00517.63
8.2.60.0050.00517.93
8.2.50.0040.00418.07
8.2.40.0000.00818.34
8.2.30.0040.00418.06
8.2.20.0030.00517.89
8.2.10.0000.00817.81
8.2.00.0080.00017.87
8.1.280.0110.00425.92
8.1.270.0080.00022.26
8.1.260.0070.00326.35
8.1.250.0080.00028.09
8.1.240.0060.00323.97
8.1.230.0080.00319.28
8.1.220.0040.00417.88
8.1.210.0000.00818.77
8.1.200.0090.00017.35
8.1.190.0030.00917.63
8.1.180.0040.00418.10
8.1.170.0000.00818.63
8.1.160.0040.00422.07
8.1.150.0000.00718.62
8.1.140.0060.00317.50
8.1.130.0000.00717.55
8.1.120.0040.00417.52
8.1.110.0000.00717.50
8.1.100.0000.00717.43
8.1.90.0040.00417.39
8.1.80.0000.00717.51
8.1.70.0030.00317.48
8.1.60.0000.00817.68
8.1.50.0040.00417.46
8.1.40.0040.00417.48
8.1.30.0000.00817.54
8.1.20.0040.00417.60
8.1.10.0000.00717.54
8.1.00.0000.00717.55
8.0.300.0040.00418.77
8.0.290.0040.00417.03
8.0.280.0000.00718.43
8.0.270.0050.00217.32
8.0.260.0050.00216.97
8.0.250.0030.00316.98
8.0.240.0050.00217.03
8.0.230.0000.00717.06
8.0.220.0040.00417.06
8.0.210.0000.00716.92
8.0.200.0030.00317.08
8.0.190.0030.00617.06
8.0.180.0000.00717.07
8.0.170.0030.00617.05
8.0.160.0050.00217.08
8.0.150.0000.00716.98
8.0.140.0000.00716.90
8.0.130.0030.00313.42
8.0.120.0040.00417.01
8.0.110.0050.00217.04
8.0.100.0040.00416.95
8.0.90.0040.00417.08
8.0.80.0150.00017.01
8.0.70.0000.00717.00
8.0.60.0070.00016.81
8.0.50.0040.00416.96
8.0.30.0120.00617.09
8.0.20.0130.00517.40
8.0.10.0040.00417.02
8.0.00.0120.00616.80
7.4.330.0030.00315.00
7.4.320.0040.00416.71
7.4.300.0030.00316.64
7.4.290.0040.00416.64
7.4.280.0000.00816.46
7.4.270.0000.00816.56
7.4.260.0000.00716.63
7.4.250.0050.00316.49
7.4.240.0040.00316.63
7.4.230.0000.00716.64
7.4.220.0030.01416.51
7.4.210.0060.00916.68
7.4.200.0000.00816.55
7.4.190.0000.00816.56
7.4.160.0100.00716.48
7.4.150.0170.00017.40
7.4.140.0080.01217.86
7.4.130.0090.01116.59
7.4.120.0130.00516.57
7.4.110.0120.01016.41
7.4.100.0160.00316.65
7.4.90.0030.01616.57
7.4.80.0100.00819.39
7.4.70.0110.00516.64
7.4.60.0100.00616.56
7.4.50.0030.00516.49
7.4.40.0000.01622.77
7.4.30.0140.00316.44
7.4.10.0070.01314.80
7.4.00.0100.00714.89
7.3.330.0000.00613.42
7.3.320.0060.00013.34
7.3.310.0070.00016.45
7.3.300.0000.00716.28
7.3.290.0090.00616.43
7.3.280.0030.01316.41
7.3.270.0160.00017.40
7.3.260.0100.00716.67
7.3.250.0120.00516.65
7.3.240.0120.00616.47
7.3.230.0180.00016.72
7.3.210.0060.01016.71
7.3.200.0100.01019.39
7.3.190.0070.01516.46
7.3.180.0090.00616.45
7.3.170.0130.00316.50
7.3.160.0030.01916.57
7.3.130.0100.01014.63
7.3.120.0070.00814.94
7.3.110.0100.01014.95
7.3.100.0070.00315.01
7.3.90.0040.01114.67
7.3.80.0140.00014.66
7.3.70.0070.00714.67
7.3.60.0070.00714.49
7.3.50.0070.01114.89
7.3.40.0070.00714.73
7.3.30.0080.00414.55
7.3.20.0080.00616.27
7.3.10.0070.00716.41
7.3.00.0040.00816.45
7.2.330.0100.00716.79
7.2.320.0110.00616.78
7.2.310.0030.01416.75
7.2.300.0060.01216.61
7.2.290.0030.01316.82
7.2.260.0030.01315.10
7.2.250.0070.01414.86
7.2.240.0000.01314.96
7.2.230.0090.00615.02
7.2.220.0070.01014.69
7.2.210.0030.01014.53
7.2.200.0100.00014.74
7.2.190.0040.00814.92
7.2.180.0060.00614.96
7.2.170.0030.01014.98
7.2.160.0040.00815.11
7.2.150.0070.00716.73
7.2.140.0090.00616.66
7.2.130.0000.01516.81
7.2.120.0030.01316.67
7.2.110.0060.00616.68
7.2.100.0080.00416.75
7.2.90.0090.00616.54
7.2.80.0060.00616.72
7.2.70.0070.00716.83
7.2.60.0060.00616.70
7.2.50.0070.00716.53
7.2.40.0110.00416.70
7.2.30.0060.00616.60
7.2.20.0070.00716.68
7.2.10.0030.01516.27
7.2.00.0040.01018.01
7.1.330.0030.01015.64
7.1.320.0050.00515.47
7.1.310.0000.01115.37
7.1.300.0000.01115.69
7.1.290.0090.00615.52
7.1.280.0030.00515.33
7.1.270.0070.00415.53
7.1.260.0070.00715.52
7.1.250.0100.00315.61
7.1.240.0030.01015.61
7.1.230.0030.00515.35
7.1.220.0060.00315.52
7.1.210.0130.00315.50
7.1.200.0030.01315.50
7.1.190.0040.01215.62
7.1.180.0070.00715.22
7.1.170.0040.01115.72
7.1.160.0070.00415.61
7.1.150.0120.00415.61
7.1.140.0120.00015.55
7.1.130.0060.00615.75
7.1.120.0100.00315.86
7.1.110.0040.00415.30
7.1.100.0120.00116.94
7.1.90.0140.00015.79
7.1.80.0040.01115.39
7.1.70.0050.00716.36
7.1.60.0100.00817.70
7.1.50.0070.01116.23
7.1.40.0060.00915.82
7.1.30.0030.01015.66
7.1.20.0060.00615.75
7.1.10.0000.01115.65
7.1.00.0020.04419.08
7.0.330.0100.00315.17
7.0.320.0040.01115.04
7.0.310.0060.00615.35
7.0.300.0100.00315.35
7.0.290.0030.00914.95
7.0.280.0000.00815.43
7.0.270.0030.01015.43
7.0.260.0110.00315.16
7.0.250.0090.00615.30
7.0.240.0120.00315.41
7.0.230.0060.00315.06
7.0.220.0050.00815.09
7.0.210.0100.00315.36
7.0.200.0060.00516.01
7.0.190.0090.00615.27
7.0.180.0090.00615.23
7.0.170.0080.00815.14
7.0.160.0030.00515.11
7.0.150.0090.00615.21
7.0.140.0050.04018.60
7.0.130.0030.00915.11
7.0.120.0040.01115.06
7.0.110.0070.01015.38
7.0.100.0050.00515.07
7.0.90.0130.00015.53
7.0.80.0030.00915.20
7.0.70.0040.01115.18
7.0.60.0080.04517.50
7.0.50.0030.02316.61
7.0.40.0080.03516.60
7.0.30.0170.02416.76
7.0.20.0150.04416.88
7.0.10.0030.05016.63
7.0.00.0080.04216.70
5.6.400.0000.01214.11
5.6.390.0040.01114.07
5.6.380.0120.00314.07
5.6.370.0090.00614.23
5.6.360.0030.00714.25
5.6.350.0060.01014.31
5.6.340.0070.00414.11
5.6.330.0060.00914.11
5.6.320.0030.01014.12
5.6.310.0100.00014.39
5.6.300.0030.01014.66
5.6.290.0060.00614.47
5.6.280.0090.03517.61
5.6.270.0000.01514.04
5.6.260.0050.00514.39
5.6.250.0100.00714.09
5.6.240.0070.01013.96
5.6.230.0030.00814.23
5.6.220.0120.00314.27
5.6.210.0090.04317.53
5.6.200.0050.04016.08
5.6.190.0060.03617.34
5.6.180.0150.02517.15
5.6.170.0170.02117.34
5.6.160.0100.04417.31
5.6.150.0100.02016.45
5.6.140.0080.04316.15
5.6.130.0020.04316.09
5.6.120.0080.03217.85
5.6.110.0080.04517.58
5.6.100.0040.04017.48
5.6.90.0120.04317.75
5.6.80.0020.05217.16
5.6.70.0000.00913.87
5.6.60.0030.01014.16
5.6.50.0090.00914.03
5.6.40.0070.01014.14
5.6.30.0080.00814.02
5.6.20.0060.01014.14
5.6.10.0000.01514.14
5.6.00.0090.00313.97
5.5.380.0030.00914.36
5.5.370.0070.01014.41
5.5.360.0070.00714.33
5.5.350.2100.02917.32
5.5.340.0110.03516.13
5.5.330.0110.03217.29
5.5.320.0230.03817.28
5.5.310.0130.02817.20
5.5.300.0080.04516.13
5.5.290.0050.04916.29
5.5.280.0170.03817.63
5.5.270.0040.02517.54
5.5.260.0070.04717.51
5.5.250.0050.02617.35
5.5.240.0050.04017.31
5.5.230.0060.00914.10
5.5.220.0160.00014.31
5.5.210.0040.01114.20
5.5.200.0110.00314.35
5.5.190.0070.00714.45
5.5.180.0120.00314.43
5.5.170.0030.01014.57
5.5.160.0060.00614.07
5.5.150.0060.00914.46
5.5.140.0120.00314.04
5.5.130.0060.00613.95
5.5.120.0030.01014.37
5.5.110.0000.01014.63
5.5.100.0080.00814.07
5.5.90.0030.01014.23
5.5.80.0000.01214.11
5.5.70.0060.00613.92
5.5.60.0030.01014.43
5.5.50.0100.00714.40
5.5.40.0110.00314.47
5.5.30.0060.00614.38
5.5.20.0100.00314.18
5.5.10.0070.00713.95
5.5.00.0090.00614.12
5.4.450.0530.02615.32
5.4.440.0320.02515.40
5.4.430.0350.02515.21
5.4.420.0130.02115.24
5.4.410.0320.02215.29
5.4.400.0820.02215.11
5.4.390.0640.02015.04
5.4.380.0210.03415.09
5.4.370.0200.03014.99
5.4.360.0200.03014.95
5.4.350.0200.02814.68
5.4.340.0200.02514.73
5.4.330.0040.00411.18
5.4.320.0080.02811.77
5.4.310.0080.01911.97
5.4.300.0050.02111.83
5.4.290.0060.02311.89
5.4.280.0070.02211.78
5.4.270.0060.02511.64
5.4.260.0060.02211.72
5.4.250.0030.02511.83
5.4.240.0020.02211.69
5.4.230.0050.02011.74
5.4.220.0040.02011.74
5.4.210.0060.01911.78
5.4.200.0020.02211.72
5.4.190.0040.02111.80
5.4.180.0060.02111.86
5.4.170.0060.02211.72
5.4.160.0050.02211.61
5.4.150.0030.02211.80
5.4.140.0060.02011.60
5.4.130.0070.02311.59
5.4.120.0050.02311.43
5.4.110.0060.02311.64
5.4.100.0070.02211.50
5.4.90.0030.02411.68
5.4.80.0050.02211.51
5.4.70.0050.02111.68
5.4.60.0080.01611.40
5.4.50.0080.01511.63
5.4.40.0020.02111.40
5.4.30.0080.01711.66
5.4.20.0050.02111.67
5.4.10.0020.02111.66
5.4.00.0020.02311.21
5.3.290.0030.02311.79
5.3.280.0040.02311.52
5.3.270.0060.02611.70
5.3.260.0040.02211.69
5.3.250.0060.02011.74
5.3.240.0070.01811.67
5.3.230.0040.02211.53
5.3.220.0040.02511.62
5.3.210.0050.02711.60
5.3.200.0060.02311.57
5.3.190.0050.02011.64
5.3.180.0040.02411.71
5.3.170.0020.02211.68
5.3.160.0030.02411.71
5.3.150.0030.02211.61
5.3.140.0070.01911.63
5.3.130.0040.02511.50
5.3.120.0060.02311.53
5.3.110.0060.01911.54
5.3.100.0060.01911.40
5.3.90.0080.02211.40
5.3.80.0050.02311.26
5.3.70.0070.02211.21
5.3.60.0080.02011.37
5.3.50.0080.02411.30
5.3.40.0040.02811.23
5.3.30.0040.02311.29
5.3.20.0060.02011.20
5.3.10.0050.01911.06
5.3.00.0030.02211.10
5.2.170.0070.0339.23
5.2.160.0030.0329.23
5.2.150.0040.0319.22
5.2.140.0030.0319.22
5.2.130.0070.0259.18
5.2.120.0050.0279.18
5.2.110.0060.0359.19
5.2.100.0060.0279.18
5.2.90.0030.0329.18
5.2.80.0050.0299.17
5.2.70.0030.0369.17
5.2.60.0050.0299.13
5.2.50.0050.0299.11
5.2.40.0030.0299.08
5.2.30.0080.0319.05
5.2.20.0040.0339.04
5.2.10.0030.0298.96
5.2.00.0060.0348.82
5.1.60.0040.0248.11
5.1.50.0050.0238.11
5.1.40.0030.0258.09
5.1.30.0030.0268.44
5.1.20.0030.0278.46
5.1.10.0050.0248.19
5.1.00.0090.0208.19
5.0.50.0030.0206.68
5.0.40.0020.0206.53
5.0.30.0030.0316.35
5.0.20.0040.0186.32
5.0.10.0050.0276.29
5.0.00.0040.0316.29
4.4.90.0020.0164.78
4.4.80.0010.0174.75
4.4.70.0020.0164.75
4.4.60.0020.0154.75
4.4.50.0050.0134.77
4.4.40.0050.0234.71
4.4.30.0030.0154.76
4.4.20.0030.0154.85
4.4.10.0020.0164.85
4.4.00.0040.0244.76
4.3.110.0010.0194.67
4.3.100.0020.0164.67
4.3.90.0040.0134.64
4.3.80.0020.0334.58
4.3.70.0020.0204.63
4.3.60.0030.0154.63
4.3.50.0010.0184.63
4.3.40.0010.0254.54
4.3.30.0010.0173.33
4.3.20.0010.0183.32
4.3.10.0000.0183.27
4.3.00.0130.02013.27

preferences:
44.61 ms | 401 KiB | 5 Q