3v4l.org

run code in 300+ PHP versions simultaneously
<?php function calc($o) { $wyniki = array(); foreach($o as $x) { $wyniki[] = ($x*$x) - (2*$x) + 2; } return $wyniki; } function proc($wyniki, $suma) { $proc = array(); foreach($wyniki as $y) { $proc[] = $y / $suma * 100; } return $proc; } function krzyzowanie($para) { $dzieci = array(); $start = rand(1,4); $ile = 5 - $start; $dzieci[] = substr_replace($para[0],substr($para[1],-$ile),$start,$ile); $dzieci[] = substr_replace($para[1],substr($para[0],-$ile),$start,$ile); return $dzieci; } function ruletka($ruletka, $l, $nr) { $i=0; do{ $ruletka[] = $obin[$nr]; $i++; }while ($i>=$l); return $ruletka; } $o = array(3,8,14,19,24,29); //shuffle($o); $ob = array(); $obin = array(); foreach($o as $b) { $ob[] = decbin($b); } foreach($ob as $c) { $obin[] = str_pad($c, 5, "0", STR_PAD_LEFT); } $wyniki = calc($o); // wartosci osobnikow po przeliczeniu przez funkcje $suma = array_sum($wyniki); // suma^ $procent = proc($wyniki, $suma); // zmienna okreslajaca prawdopodobienstwo wylosowania osobnika $zaokraglone = array(); foreach($procent as $k) { $k = $k*100; $zaokraglone[] = intval($k); } $ruletka = array(); //tablica z 10000 elementow, z niej losowane sa pary rodzicow $ruletka = ruletka($ruletka, $zaokragone[0], 0); $ruletka = ruletka($ruletka, $zaokragone[1], 1); $ruletka = ruletka($ruletka, $zaokragone[2], 2); $ruletka = ruletka($ruletka, $zaokragone[3], 3); $ruletka = ruletka($ruletka, $zaokragone[4], 4); $ruletka = ruletka($ruletka, $zaokragone[5], 5); $para1 = array(); $para3 = array(); $para3 = array(); $para1[] = array_rand($ruletka); $para1[] = array_rand($ruletka); while ($para1[0] == $para1[1]) { $para1[1] = array_rand($ruletka); } $para2[] = array_rand($ruletka); $para2[] = array_rand($ruletka); while ($para2[0] == $para2[1]) { $para2[1] = array_rand($ruletka); } $para3[] = array_rand($ruletka); $para3[] = array_rand($ruletka); while ($para3[0] == $para3[1]) { $para3[1] = array_rand($ruletka); } $dzieci1 = krzyzowanie($para1); $dzieci2 = krzyzowanie($para2); $dzieci3 = krzyzowanie($para3); //echo "Osobniki: "; //print_r($o); //echo "\nWyniki funkcji dopasowania: "; //print_r($wyniki); //echo $suma; //echo "\nProcentowo: "; //print_r($procent); //print_r($obin); //echo "\nLosowo dobrane pary osobnikow - rodzice: "; //print_r($pary); //echo "\n\n---------------------------------------------------------"; //echo "\nDzieci po operacji krzyzowania: "; //print_r($dzieci1); //print_r($dzieci2); //print_r($dzieci3); $dzieci_dec[] = bindec($dzieci1[0]); $dzieci_dec[] = bindec($dzieci1[1]); $dzieci_dec[] = bindec($dzieci2[0]); $dzieci_dec[] = bindec($dzieci2[1]); $dzieci_dec[] = bindec($dzieci3[0]); $dzieci_dec[] = bindec($dzieci3[1]); //print_r($dzieci_dec); $wyniki_d = calc($dzieci_dec); $suma_d = array_sum($wyniki_d); $procent_d = proc($wyniki_d, $suma_d); //print_r($wyniki_d); //echo $suma_d; //print_r($procent_d); ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 23
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 23
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 23
2 jumps found. (Code = 77) Position 1 = 39, Position 2 = 46
Branch analysis from position: 39
2 jumps found. (Code = 78) Position 1 = 40, Position 2 = 46
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 109
Branch analysis from position: 109
2 jumps found. (Code = 44) Position 1 = 113, Position 2 = 104
Branch analysis from position: 113
1 jumps found. (Code = 42) Position 1 = 129
Branch analysis from position: 129
2 jumps found. (Code = 44) Position 1 = 133, Position 2 = 124
Branch analysis from position: 133
1 jumps found. (Code = 42) Position 1 = 149
Branch analysis from position: 149
2 jumps found. (Code = 44) Position 1 = 153, Position 2 = 144
Branch analysis from position: 153
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 144
2 jumps found. (Code = 44) Position 1 = 153, Position 2 = 144
Branch analysis from position: 153
Branch analysis from position: 144
Branch analysis from position: 124
2 jumps found. (Code = 44) Position 1 = 133, Position 2 = 124
Branch analysis from position: 133
Branch analysis from position: 124
Branch analysis from position: 104
2 jumps found. (Code = 44) Position 1 = 113, Position 2 = 104
Branch analysis from position: 113
Branch analysis from position: 104
Branch analysis from position: 46
Branch analysis from position: 23
Branch analysis from position: 11
filename:       /in/YqNZ2
function name:  (null)
number of ops:  215
compiled vars:  !0 = $o, !1 = $ob, !2 = $obin, !3 = $b, !4 = $c, !5 = $wyniki, !6 = $suma, !7 = $procent, !8 = $zaokraglone, !9 = $k, !10 = $ruletka, !11 = $zaokragone, !12 = $para1, !13 = $para3, !14 = $para2, !15 = $dzieci1, !16 = $dzieci2, !17 = $dzieci3, !18 = $dzieci_dec, !19 = $wyniki_d, !20 = $suma_d, !21 = $procent_d
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   ASSIGN                                                   !0, <array>
   46     1        ASSIGN                                                   !1, <array>
   47     2        ASSIGN                                                   !2, <array>
   49     3      > FE_RESET_R                                       $25     !0, ->11
          4    > > FE_FETCH_R                                               $25, !3, ->11
   51     5    >   INIT_FCALL                                               'decbin'
          6        SEND_VAR                                                 !3
          7        DO_ICALL                                         $27     
          8        ASSIGN_DIM                                               !1
          9        OP_DATA                                                  $27
   49    10      > JMP                                                      ->4
         11    >   FE_FREE                                                  $25
   53    12      > FE_RESET_R                                       $28     !1, ->23
         13    > > FE_FETCH_R                                               $28, !4, ->23
   55    14    >   INIT_FCALL                                               'str_pad'
         15        SEND_VAR                                                 !4
         16        SEND_VAL                                                 5
         17        SEND_VAL                                                 '0'
         18        SEND_VAL                                                 0
         19        DO_ICALL                                         $30     
         20        ASSIGN_DIM                                               !2
         21        OP_DATA                                                  $30
   53    22      > JMP                                                      ->13
         23    >   FE_FREE                                                  $28
   58    24        INIT_FCALL                                               'calc'
         25        SEND_VAR                                                 !0
         26        DO_FCALL                                      0  $31     
         27        ASSIGN                                                   !5, $31
   59    28        INIT_FCALL                                               'array_sum'
         29        SEND_VAR                                                 !5
         30        DO_ICALL                                         $33     
         31        ASSIGN                                                   !6, $33
   60    32        INIT_FCALL                                               'proc'
         33        SEND_VAR                                                 !5
         34        SEND_VAR                                                 !6
         35        DO_FCALL                                      0  $35     
         36        ASSIGN                                                   !7, $35
   62    37        ASSIGN                                                   !8, <array>
   63    38      > FE_RESET_R                                       $38     !7, ->46
         39    > > FE_FETCH_R                                               $38, !9, ->46
   65    40    >   MUL                                              ~39     !9, 100
         41        ASSIGN                                                   !9, ~39
   66    42        CAST                                          4  ~42     !9
         43        ASSIGN_DIM                                               !8
         44        OP_DATA                                                  ~42
   63    45      > JMP                                                      ->39
         46    >   FE_FREE                                                  $38
   69    47        ASSIGN                                                   !10, <array>
   70    48        INIT_FCALL                                               'ruletka'
         49        SEND_VAR                                                 !10
         50        FETCH_DIM_R                                      ~44     !11, 0
         51        SEND_VAL                                                 ~44
         52        SEND_VAL                                                 0
         53        DO_FCALL                                      0  $45     
         54        ASSIGN                                                   !10, $45
   71    55        INIT_FCALL                                               'ruletka'
         56        SEND_VAR                                                 !10
         57        FETCH_DIM_R                                      ~47     !11, 1
         58        SEND_VAL                                                 ~47
         59        SEND_VAL                                                 1
         60        DO_FCALL                                      0  $48     
         61        ASSIGN                                                   !10, $48
   72    62        INIT_FCALL                                               'ruletka'
         63        SEND_VAR                                                 !10
         64        FETCH_DIM_R                                      ~50     !11, 2
         65        SEND_VAL                                                 ~50
         66        SEND_VAL                                                 2
         67        DO_FCALL                                      0  $51     
         68        ASSIGN                                                   !10, $51
   73    69        INIT_FCALL                                               'ruletka'
         70        SEND_VAR                                                 !10
         71        FETCH_DIM_R                                      ~53     !11, 3
         72        SEND_VAL                                                 ~53
         73        SEND_VAL                                                 3
         74        DO_FCALL                                      0  $54     
         75        ASSIGN                                                   !10, $54
   74    76        INIT_FCALL                                               'ruletka'
         77        SEND_VAR                                                 !10
         78        FETCH_DIM_R                                      ~56     !11, 4
         79        SEND_VAL                                                 ~56
         80        SEND_VAL                                                 4
         81        DO_FCALL                                      0  $57     
         82        ASSIGN                                                   !10, $57
   75    83        INIT_FCALL                                               'ruletka'
         84        SEND_VAR                                                 !10
         85        FETCH_DIM_R                                      ~59     !11, 5
         86        SEND_VAL                                                 ~59
         87        SEND_VAL                                                 5
         88        DO_FCALL                                      0  $60     
         89        ASSIGN                                                   !10, $60
   77    90        ASSIGN                                                   !12, <array>
   78    91        ASSIGN                                                   !13, <array>
   79    92        ASSIGN                                                   !13, <array>
   80    93        INIT_FCALL                                               'array_rand'
         94        SEND_VAR                                                 !10
         95        DO_ICALL                                         $66     
         96        ASSIGN_DIM                                               !12
         97        OP_DATA                                                  $66
   81    98        INIT_FCALL                                               'array_rand'
         99        SEND_VAR                                                 !10
        100        DO_ICALL                                         $68     
        101        ASSIGN_DIM                                               !12
        102        OP_DATA                                                  $68
   82   103      > JMP                                                      ->109
   84   104    >   INIT_FCALL                                               'array_rand'
        105        SEND_VAR                                                 !10
        106        DO_ICALL                                         $70     
        107        ASSIGN_DIM                                               !12, 1
        108        OP_DATA                                                  $70
   82   109    >   FETCH_DIM_R                                      ~71     !12, 0
        110        FETCH_DIM_R                                      ~72     !12, 1
        111        IS_EQUAL                                                 ~71, ~72
        112      > JMPNZ                                                    ~73, ->104
   86   113    >   INIT_FCALL                                               'array_rand'
        114        SEND_VAR                                                 !10
        115        DO_ICALL                                         $75     
        116        ASSIGN_DIM                                               !14
        117        OP_DATA                                                  $75
   87   118        INIT_FCALL                                               'array_rand'
        119        SEND_VAR                                                 !10
        120        DO_ICALL                                         $77     
        121        ASSIGN_DIM                                               !14
        122        OP_DATA                                                  $77
   88   123      > JMP                                                      ->129
   90   124    >   INIT_FCALL                                               'array_rand'
        125        SEND_VAR                                                 !10
        126        DO_ICALL                                         $79     
        127        ASSIGN_DIM                                               !14, 1
        128        OP_DATA                                                  $79
   88   129    >   FETCH_DIM_R                                      ~80     !14, 0
        130        FETCH_DIM_R                                      ~81     !14, 1
        131        IS_EQUAL                                                 ~80, ~81
        132      > JMPNZ                                                    ~82, ->124
   92   133    >   INIT_FCALL                                               'array_rand'
        134        SEND_VAR                                                 !10
        135        DO_ICALL                                         $84     
        136        ASSIGN_DIM                                               !13
        137        OP_DATA                                                  $84
   93   138        INIT_FCALL                                               'array_rand'
        139        SEND_VAR                                                 !10
        140        DO_ICALL                                         $86     
        141        ASSIGN_DIM                                               !13
        142        OP_DATA                                                  $86
   94   143      > JMP                                                      ->149
   96   144    >   INIT_FCALL                                               'array_rand'
        145        SEND_VAR                                                 !10
        146        DO_ICALL                                         $88     
        147        ASSIGN_DIM                                               !13, 1
        148        OP_DATA                                                  $88
   94   149    >   FETCH_DIM_R                                      ~89     !13, 0
        150        FETCH_DIM_R                                      ~90     !13, 1
        151        IS_EQUAL                                                 ~89, ~90
        152      > JMPNZ                                                    ~91, ->144
   99   153    >   INIT_FCALL                                               'krzyzowanie'
        154        SEND_VAR                                                 !12
        155        DO_FCALL                                      0  $92     
        156        ASSIGN                                                   !15, $92
  100   157        INIT_FCALL                                               'krzyzowanie'
        158        SEND_VAR                                                 !14
        159        DO_FCALL                                      0  $94     
        160        ASSIGN                                                   !16, $94
  101   161        INIT_FCALL                                               'krzyzowanie'
        162        SEND_VAR                                                 !13
        163        DO_FCALL                                      0  $96     
        164        ASSIGN                                                   !17, $96
  119   165        INIT_FCALL                                               'bindec'
        166        FETCH_DIM_R                                      ~99     !15, 0
        167        SEND_VAL                                                 ~99
        168        DO_ICALL                                         $100    
        169        ASSIGN_DIM                                               !18
        170        OP_DATA                                                  $100
  120   171        INIT_FCALL                                               'bindec'
        172        FETCH_DIM_R                                      ~102    !15, 1
        173        SEND_VAL                                                 ~102
        174        DO_ICALL                                         $103    
        175        ASSIGN_DIM                                               !18
        176        OP_DATA                                                  $103
  121   177        INIT_FCALL                                               'bindec'
        178        FETCH_DIM_R                                      ~105    !16, 0
        179        SEND_VAL                                                 ~105
        180        DO_ICALL                                         $106    
        181        ASSIGN_DIM                                               !18
        182        OP_DATA                                                  $106
  122   183        INIT_FCALL                                               'bindec'
        184        FETCH_DIM_R                                      ~108    !16, 1
        185        SEND_VAL                                                 ~108
        186        DO_ICALL                                         $109    
        187        ASSIGN_DIM                                               !18
        188        OP_DATA                                                  $109
  123   189        INIT_FCALL                                               'bindec'
        190        FETCH_DIM_R                                      ~111    !17, 0
        191        SEND_VAL                                                 ~111
        192        DO_ICALL                                         $112    
        193        ASSIGN_DIM                                               !18
        194        OP_DATA                                                  $112
  124   195        INIT_FCALL                                               'bindec'
        196        FETCH_DIM_R                                      ~114    !17, 1
        197        SEND_VAL                                                 ~114
        198        DO_ICALL                                         $115    
        199        ASSIGN_DIM                                               !18
        200        OP_DATA                                                  $115
  128   201        INIT_FCALL                                               'calc'
        202        SEND_VAR                                                 !18
        203        DO_FCALL                                      0  $116    
        204        ASSIGN                                                   !19, $116
  129   205        INIT_FCALL                                               'array_sum'
        206        SEND_VAR                                                 !19
        207        DO_ICALL                                         $118    
        208        ASSIGN                                                   !20, $118
  130   209        INIT_FCALL                                               'proc'
        210        SEND_VAR                                                 !19
        211        SEND_VAR                                                 !20
        212        DO_FCALL                                      0  $120    
        213        ASSIGN                                                   !21, $120
  134   214      > RETURN                                                   1

Function calc:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 11
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/YqNZ2
function name:  calc
number of ops:  14
compiled vars:  !0 = $o, !1 = $wyniki, !2 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, <array>
    5     2      > FE_RESET_R                                       $4      !0, ->11
          3    > > FE_FETCH_R                                               $4, !2, ->11
    7     4    >   MUL                                              ~6      !2, !2
          5        MUL                                              ~7      !2, 2
          6        SUB                                              ~8      ~6, ~7
          7        ADD                                              ~9      ~8, 2
          8        ASSIGN_DIM                                               !1
          9        OP_DATA                                                  ~9
    5    10      > JMP                                                      ->3
         11    >   FE_FREE                                                  $4
    9    12      > RETURN                                                   !1
   10    13*     > RETURN                                                   null

End of function calc

Function proc:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/YqNZ2
function name:  proc
number of ops:  13
compiled vars:  !0 = $wyniki, !1 = $suma, !2 = $proc, !3 = $y
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   14     2        ASSIGN                                                   !2, <array>
   16     3      > FE_RESET_R                                       $5      !0, ->10
          4    > > FE_FETCH_R                                               $5, !3, ->10
   18     5    >   DIV                                              ~7      !3, !1
          6        MUL                                              ~8      ~7, 100
          7        ASSIGN_DIM                                               !2
          8        OP_DATA                                                  ~8
   16     9      > JMP                                                      ->4
         10    >   FE_FREE                                                  $5
   20    11      > RETURN                                                   !2
   21    12*     > RETURN                                                   null

End of function proc

Function krzyzowanie:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YqNZ2
function name:  krzyzowanie
number of ops:  41
compiled vars:  !0 = $para, !1 = $dzieci, !2 = $start, !3 = $ile
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   26     1        ASSIGN                                                   !1, <array>
   27     2        INIT_FCALL                                               'rand'
          3        SEND_VAL                                                 1
          4        SEND_VAL                                                 4
          5        DO_ICALL                                         $5      
          6        ASSIGN                                                   !2, $5
   28     7        SUB                                              ~7      5, !2
          8        ASSIGN                                                   !3, ~7
   29     9        INIT_FCALL                                               'substr_replace'
         10        FETCH_DIM_R                                      ~10     !0, 0
         11        SEND_VAL                                                 ~10
         12        INIT_FCALL                                               'substr'
         13        FETCH_DIM_R                                      ~11     !0, 1
         14        SEND_VAL                                                 ~11
         15        MUL                                              ~12     !3, -1
         16        SEND_VAL                                                 ~12
         17        DO_ICALL                                         $13     
         18        SEND_VAR                                                 $13
         19        SEND_VAR                                                 !2
         20        SEND_VAR                                                 !3
         21        DO_ICALL                                         $14     
         22        ASSIGN_DIM                                               !1
         23        OP_DATA                                                  $14
   30    24        INIT_FCALL                                               'substr_replace'
         25        FETCH_DIM_R                                      ~16     !0, 1
         26        SEND_VAL                                                 ~16
         27        INIT_FCALL                                               'substr'
         28        FETCH_DIM_R                                      ~17     !0, 0
         29        SEND_VAL                                                 ~17
         30        MUL                                              ~18     !3, -1
         31        SEND_VAL                                                 ~18
         32        DO_ICALL                                         $19     
         33        SEND_VAR                                                 $19
         34        SEND_VAR                                                 !2
         35        SEND_VAR                                                 !3
         36        DO_ICALL                                         $20     
         37        ASSIGN_DIM                                               !1
         38        OP_DATA                                                  $20
   31    39      > RETURN                                                   !1
   32    40*     > RETURN                                                   null

End of function krzyzowanie

Function ruletka:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 4
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
filename:       /in/YqNZ2
function name:  ruletka
number of ops:  12
compiled vars:  !0 = $ruletka, !1 = $l, !2 = $nr, !3 = $i, !4 = $obin
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   36     3        ASSIGN                                                   !3, 0
   38     4    >   FETCH_DIM_R                                      ~7      !4, !2
          5        ASSIGN_DIM                                               !0
          6        OP_DATA                                                  ~7
   39     7        PRE_INC                                                  !3
   40     8        IS_SMALLER_OR_EQUAL                                      !1, !3
          9      > JMPNZ                                                    ~9, ->4
   41    10    > > RETURN                                                   !0
   42    11*     > RETURN                                                   null

End of function ruletka

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.11 ms | 1427 KiB | 42 Q