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; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 35
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 29
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fTRih
function name:  (null)
number of ops:  41
compiled vars:  !0 = $inputNumber, !1 = $inputString, !2 = $numeralReadings, !3 = $numeralExceptions, !4 = $inp1, !5 = $inp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   ASSIGN                                                   !0, 2025
   57     1        CAST                                          6  ~7      !0
          2        ASSIGN                                                   !1, ~7
   59     3        ASSIGN                                                   !2, <array>
   80     4        ASSIGN                                                   !3, <array>
   97     5        IS_SMALLER                                               10000, !1
          6      > JMPZ                                                     ~11, ->35
   98     7    >   INIT_FCALL                                               'floor'
          8        DIV                                              ~12     !1, 1000
          9        SEND_VAL                                                 ~12
         10        DO_ICALL                                         $13     
         11        ASSIGN                                                   !4, $13
   99    12        MUL                                              ~15     !4, 1000
         13        SUB                                              ~16     !1, ~15
         14        ASSIGN                                                   !5, ~16
  100    15        IS_NOT_IDENTICAL                                         !5, 0
         16      > JMPZ                                                     ~18, ->29
  101    17    >   INIT_FCALL_BY_NAME                                       'read'
         18        SEND_VAR_EX                                              !4
         19        SEND_VAR_EX                                              !2
         20        SEND_VAR_EX                                              !3
         21        SEND_VAL_EX                                              <false>
         22        DO_FCALL                                      0          
  102    23        INIT_FCALL_BY_NAME                                       'read'
         24        SEND_VAR_EX                                              !5
         25        SEND_VAR_EX                                              !2
         26        SEND_VAR_EX                                              !3
         27        DO_FCALL                                      0          
         28      > JMP                                                      ->34
  104    29    >   INIT_FCALL_BY_NAME                                       'read'
         30        SEND_VAR_EX                                              !1
         31        SEND_VAR_EX                                              !2
         32        SEND_VAR_EX                                              !3
         33        DO_FCALL                                      0          
         34    > > JMP                                                      ->40
  107    35    >   INIT_FCALL_BY_NAME                                       'read'
         36        SEND_VAR_EX                                              !1
         37        SEND_VAR_EX                                              !2
         38        SEND_VAR_EX                                              !3
         39        DO_FCALL                                      0          
  158    40    > > RETURN                                                   1

Function read:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 71
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 71
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 70
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 26
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 40
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 52
Branch analysis from position: 42
2 jumps found. (Code = 46) Position 1 = 44, Position 2 = 46
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 48
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 46
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 70
Branch analysis from position: 55
2 jumps found. (Code = 46) Position 1 = 57, Position 2 = 59
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 61
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 61
2 jumps found. (Code = 43) Position 1 = 66, Position 2 = 69
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 69
Branch analysis from position: 59
Branch analysis from position: 70
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 26
Branch analysis from position: 31
Branch analysis from position: 26
Branch analysis from position: 70
Branch analysis from position: 17
Branch analysis from position: 71
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 71
filename:       /in/fTRih
function name:  read
number of ops:  74
compiled vars:  !0 = $inputStr, !1 = $numeralReadings, !2 = $numeralExceptions, !3 = $parse1, !4 = $splitString, !5 = $returnString, !6 = $appendIchi, !7 = $firstNumber, !8 = $number, !9 = $key, !10 = $int, !11 = $a, !12 = $i, !13 = $tempNumber
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  110     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      <true>
  112     4        INIT_FCALL                                               'str_split'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $14     
          7        ASSIGN                                                   !4, $14
  113     8        ASSIGN                                                   !5, ''
  114     9        ASSIGN                                                   !6, <false>
  115    10        ASSIGN                                                   !7, null
  117    11      > FE_RESET_R                                       $19     !4, ->71
         12    > > FE_FETCH_R                                       ~20     $19, !8, ->71
         13    >   ASSIGN                                                   !9, ~20
  119    14        IS_EQUAL                                                 !7, null
         15      > JMPZ                                                     ~22, ->17
  120    16    >   ASSIGN                                                   !7, !8
  123    17    >   IS_NOT_IDENTICAL                                         !8, 0
         18      > JMPZ                                                     ~24, ->70
  124    19    >   ASSIGN                                                   !10, 1
  125    20        COUNT                                            ~26     !4
         21        SUB                                              ~27     ~26, 1
         22        SUB                                              ~28     ~27, !9
         23        ASSIGN                                                   !11, ~28
  126    24        ASSIGN                                                   !12, 0
         25      > JMP                                                      ->29
  127    26    >   MUL                                              ~31     !10, 10
         27        ASSIGN                                                   !10, ~31
  126    28        PRE_INC                                                  !12
         29    >   IS_SMALLER                                               !12, !11
         30      > JMPNZ                                                    ~34, ->26
  130    31    >   CAST                                          4  ~35     !8
         32        MUL                                              ~36     !10, ~35
         33        ASSIGN                                                   !13, ~36
  131    34        ISSET_ISEMPTY_DIM_OBJ                         0          !2, !13
         35      > JMPZ                                                     ~38, ->40
  132    36    >   FETCH_DIM_R                                      ~39     !2, !13
         37        CONCAT                                           ~40     ~39, '+'
         38        ASSIGN_OP                                     8          !5, ~40
  133    39      > JMP                                                      ->12
  136    40    >   ISSET_ISEMPTY_DIM_OBJ                         0          !1, !13
         41      > JMPZ                                                     ~42, ->52
  137    42    >   BOOL_NOT                                         ~43     !3
         43      > JMPZ_EX                                          ~43     ~43, ->46
         44    >   IS_EQUAL                                         ~44     !13, 1
         45        BOOL                                             ~43     ~44
         46    > > JMPZ                                                     ~43, ->48
  138    47    > > JMP                                                      ->12
  140    48    >   FETCH_DIM_R                                      ~45     !1, !13
         49        CONCAT                                           ~46     ~45, '+'
         50        ASSIGN_OP                                     8          !5, ~46
  141    51      > JMP                                                      ->12
  144    52    >   CAST                                          4  ~48     !8
         53        ISSET_ISEMPTY_DIM_OBJ                         0          !1, ~48
         54      > JMPZ                                                     ~49, ->70
  145    55    >   BOOL_NOT                                         ~50     !3
         56      > JMPZ_EX                                          ~50     ~50, ->59
         57    >   IS_EQUAL                                         ~51     !13, 1
         58        BOOL                                             ~50     ~51
         59    > > JMPZ                                                     ~50, ->61
  146    60    > > JMP                                                      ->12
  148    61    >   CAST                                          4  ~52     !8
         62        FETCH_DIM_R                                      ~53     !1, ~52
         63        ASSIGN_OP                                     8          !5, ~53
  149    64        IS_NOT_IDENTICAL                                         !10, 1
         65      > JMPZ                                                     ~55, ->69
  150    66    >   FETCH_DIM_R                                      ~56     !1, !10
         67        CONCAT                                           ~57     '-', ~56
         68        ASSIGN_OP                                     8          !5, ~57
  152    69    >   ASSIGN_OP                                     8          !5, '+'
  117    70    > > JMP                                                      ->12
         71    >   FE_FREE                                                  $19
  157    72        ECHO                                                     !5
  158    73      > RETURN                                                   null

End of function read

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.5 ms | 1408 KiB | 17 Q