Author Topic: Pattern Searching  (Read 3386 times)

0 Members and 1 Guest are viewing this topic.

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Pattern Searching
« on: April 29, 2021, 10:18:56 am »
Just wondering how I may be able to search out patterns in my data files. I basically have over 50 patterns that I'm searching out, and the most simplistic approach for me was to use multiple "If statements to find a match. While this has turned out to be accurate but the larger the data files grow the slower this becomes. Would you guys and girls out there have better pattern search routine than multiple "if's"?

Here is an idea of the code I'm presently using.
Code: QB64: [Select]
  1. ' Pattern Search Routine
  2.  
  3.  
  4.     Input #1, firstdat, seconddat, thirddat, forthdat, fifthdat, sixthdat, bonusdat
  5.     DataLineCount = DataCount + 1
  6.  
  7.  
  8.  
  9.     If firstdat >= le1 And firstdat <= ue1 Then range1 = range1 + 1
  10.     If seconddat >= le2 And seconddat <= ue2 Then range2 = range2 + 1
  11.     If thirddat >= le3 And thirddat <= ue3 Then range3 = range3 + 1
  12.     If forthdat >= le4 And forthdat <= ue4 Then range4 = range4 + 1
  13.     If fifthdat >= le5 And fifthdat <= ue5 Then range5 = range5 + 1
  14.     If sixthdat >= le6 And sixthdat <= ue6 Then range6 = range6 + 1
  15.  
  16.  
  17.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le1 And seconddat <= ue1 And thirddat >= le1 And thirddat <= ue1 And forthdat >= le1 And forthdat <= ue1 And fifthdat >= le1 And fifthdat <= ue1 And sixthdat >= le1 And sixthdat <= ue1 And DrawCount <= 104 Then
  18.         Y1P1 = Y1P1 + 1 'P1 = a,a,a,a,a,a
  19.     End If
  20.  
  21.  
  22.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le1 And seconddat <= ue1 And thirddat >= le1 And thirddat <= ue1 And forthdat >= le1 And forthdat <= ue1 And fifthdat >= le1 And fifthdat <= ue1 And sixthdat >= le2 And sixthdat <= ue2 And DrawCount <= 104 Then
  23.         Y1P2 = Y1P2 + 1 'P2 = a,a,a,a,a,b
  24.     End If
  25.  
  26.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le1 And seconddat <= ue1 And thirddat >= le1 And thirddat <= ue1 And forthdat >= le1 And forthdat <= ue1 And fifthdat >= le2 And fifthdat <= ue2 And sixthdat >= le2 And sixthdat <= ue2 And DrawCount <= 104 Then
  27.         Y1P3 = Y1P3 + 1 'P3 = a,a,a,a,b,b
  28.     End If
  29.  
  30.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le1 And seconddat <= ue1 And thirddat >= le1 And thirddat <= ue1 And forthdat >= le2 And forthdat <= ue2 And fifthdat >= le2 And fifthdat <= ue2 And sixthdat >= le2 And sixthdat <= ue2 And DrawCount <= 104 Then
  31.         Y1P4 = Y1P4 + 1 'P4 = a,a,a,b,b,b
  32.     End If
  33.  
  34.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le1 And seconddat <= ue1 And thirddat >= le2 And thirddat <= ue2 And forthdat >= le2 And forthdat <= ue2 And fifthdat >= le2 And fifthdat <= ue2 And sixthdat >= le2 And sixthdat <= ue2 And DrawCount <= 104 Then
  35.         Y1P5 = Y1P5 + 1 'P5 = a,a,b,b,b,b
  36.     End If
  37.  
  38.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le2 And thirddat <= ue2 And forthdat >= le2 And forthdat <= ue2 And fifthdat >= le2 And fifthdat <= ue2 And sixthdat >= le2 And sixthdat <= ue2 And DrawCount <= 104 Then
  39.         Y1P6 = Y1P6 + 1 'P6 = a,b,b,b,b,b
  40.     End If
  41.  
  42.     If firstdat >= le2 And firstdat <= ue2 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le2 And thirddat <= ue2 And forthdat >= le2 And forthdat <= ue2 And fifthdat >= le2 And fifthdat <= ue2 And sixthdat >= le2 And sixthdat <= ue2 And DrawCount <= 104 Then
  43.         Y1P7 = Y1P7 + 1 'P7 = b,b,b,b,b,b
  44.     End If
  45.  
  46.     If firstdat >= le2 And firstdat <= ue2 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le2 And thirddat <= ue2 And forthdat >= le2 And forthdat <= ue2 And fifthdat >= le2 And fifthdat <= ue2 And sixthdat >= le3 And sixthdat <= ue3 And DrawCount <= 104 Then
  47.         Y1P8 = Y1P8 + 1 'P8 = b,b,b,b,b,c
  48.     End If
  49.  
  50.     If firstdat >= le2 And firstdat <= ue2 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le2 And thirddat <= ue2 And forthdat >= le2 And forthdat <= ue2 And fifthdat >= le3 And fifthdat <= ue3 And sixthdat >= le3 And sixthdat <= ue3 And DrawCount <= 104 Then
  51.         Y1P9 = Y1P9 + 1 'P9 = b,b,b,b,c,c
  52.     End If
  53.  
  54.     If firstdat >= le2 And firstdat <= ue2 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le2 And thirddat <= ue2 And forthdat >= le3 And forthdat <= ue3 And fifthdat >= le3 And fifthdat <= ue3 And sixthdat >= le3 And sixthdat <= ue3 And DrawCount <= 104 Then
  55.         Y1P10 = Y1P10 + 1 'P10 = b,b,b,c,c,c
  56.     End If
  57.  
  58.     If firstdat >= le2 And firstdat <= ue2 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le3 And forthdat <= ue3 And fifthdat >= le3 And fifthdat <= ue3 And sixthdat >= le3 And sixthdat <= ue3 And DrawCount <= 104 Then
  59.         Y1P11 = Y1P11 + 1 'P11 = b,b,c,c,c,c
  60.     End If
  61.  
  62.     If firstdat >= le2 And firstdat <= ue2 And seconddat >= le3 And seconddat <= ue3 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le3 And forthdat <= ue3 And fifthdat >= le3 And fifthdat <= ue3 And sixthdat >= le3 And sixthdat <= ue3 And DrawCount <= 104 Then
  63.         Y1P12 = Y1P12 + 1 'P12 = b,c,c,c,c,c
  64.     End If
  65.  
  66.     If firstdat >= le3 And firstdat <= ue3 And seconddat >= le3 And seconddat <= ue3 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le3 And forthdat <= ue3 And fifthdat >= le3 And fifthdat <= ue3 And sixthdat >= le3 And sixthdat <= ue3 And DrawCount <= 104 Then
  67.         Y1P13 = Y1P13 + 1 'P13 = c,c,c,c,c,c
  68.     End If
  69.  
  70.     If firstdat >= le3 And firstdat <= ue3 And seconddat >= le3 And seconddat <= ue3 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le3 And forthdat <= ue3 And fifthdat >= le3 And fifthdat <= ue3 And sixthdat >= le4 And sixthdat <= ue4 And DrawCount <= 104 Then
  71.         Y1P14 = Y1P14 + 1 'P14 = c,c,c,c,c,d
  72.     End If
  73.  
  74.     If firstdat >= le3 And firstdat <= ue3 And seconddat >= le3 And seconddat <= ue3 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le3 And forthdat <= ue3 And fifthdat >= le4 And fifthdat <= ue4 And sixthdat >= le4 And sixthdat <= ue4 And DrawCount <= 104 Then
  75.         Y1P15 = Y1P15 + 1 'P15 = c,c,c,c,d,d
  76.     End If
  77.  
  78.     If firstdat >= le3 And firstdat <= ue3 And seconddat >= le3 And seconddat <= ue3 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le4 And fifthdat <= ue4 And sixthdat >= le4 And sixthdat <= ue4 And DrawCount <= 104 Then
  79.         Y1P16 = Y1P16 + 1 'P16 = c,c,c,d,d,d
  80.     End If
  81.  
  82.     If firstdat >= le3 And firstdat <= ue3 And seconddat >= le3 And seconddat <= ue3 And thirddat >= le4 And thirddat <= ue4 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le4 And fifthdat <= ue4 And sixthdat >= le4 And sixthdat <= ue4 And DrawCount <= 104 Then
  83.         Y1P17 = Y1P17 + 1 'P17 = c,c,d,d,d,d
  84.     End If
  85.  
  86.     If firstdat >= le3 And firstdat <= ue3 And seconddat >= le4 And seconddat <= ue4 And thirddat >= le4 And thirddat <= ue4 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le4 And fifthdat <= ue4 And sixthdat >= le4 And sixthdat <= ue4 And DrawCount <= 104 Then
  87.         Y1P18 = Y1P18 + 1 'P18 = c,d,d,d,d,d
  88.     End If
  89.  
  90.     If firstdat >= le4 And firstdat <= ue4 And seconddat >= le4 And seconddat <= ue4 And thirddat >= le4 And thirddat <= ue4 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le4 And fifthdat <= ue4 And sixthdat >= le4 And sixthdat <= ue4 And DrawCount <= 104 Then
  91.         Y1P19 = Y1P19 + 1 'P19 = d,d,d,d,d,d
  92.     End If
  93.  
  94.     If firstdat >= le4 And firstdat <= ue4 And seconddat >= le4 And seconddat <= ue4 And thirddat >= le4 And thirddat <= ue4 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le4 And fifthdat <= ue4 And sixthdat >= le5 And sixthdat <= ue5 And DrawCount <= 104 Then
  95.         Y1P20 = Y1P20 + 1 'P20 = d,d,d,d,d,e
  96.     End If
  97.  
  98.  
  99.     If firstdat >= le4 And firstdat <= ue4 And seconddat >= le4 And seconddat <= ue4 And thirddat >= le4 And thirddat <= ue4 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le5 And fifthdat <= ue5 And sixthdat >= le5 And sixthdat <= ue5 And DrawCount <= 104 Then
  100.         Y1P21 = Y1P21 + 1 'P21 = d,d,d,d,e,e
  101.     End If
  102.  
  103.     If firstdat >= le4 And firstdat <= ue4 And seconddat >= le4 And seconddat <= ue4 And thirddat >= le4 And thirddat <= ue4 And forthdat >= le5 And forthdat <= ue5 And fifthdat >= le5 And fifthdat <= ue5 And sixthdat >= le5 And sixthdat <= ue5 And DrawCount <= 104 Then
  104.         Y1P22 = Y1P22 + 1 'P22 = d,d,d,e,e,e
  105.     End If
  106.  
  107.     If firstdat >= le4 And firstdat <= ue4 And seconddat >= le4 And seconddat <= ue4 And thirddat >= le5 And thirddat <= ue5 And forthdat >= le5 And forthdat <= ue5 And fifthdat >= le5 And fifthdat <= ue5 And sixthdat >= le5 And sixthdat <= ue5 And DrawCount <= 104 Then
  108.         Y1P23 = Y1P23 + 1 'P23 = d,d,e,e,e,e
  109.     End If
  110.  
  111.     If firstdat >= le4 And firstdat <= ue4 And seconddat >= le5 And seconddat <= ue5 And thirddat >= le5 And thirddat <= ue5 And forthdat >= le5 And forthdat <= ue5 And fifthdat >= le5 And fifthdat <= ue5 And sixthdat >= le5 And sixthdat <= ue5 And DrawCount <= 104 Then
  112.         Y1P24 = Y1P24 + 1 'P24 = d,e,e,e,e,e
  113.     End If
  114.  
  115.     If firstdat >= le5 And firstdat <= ue5 And seconddat >= le5 And seconddat <= ue5 And thirddat >= le5 And thirddat <= ue5 And forthdat >= le5 And forthdat <= ue5 And fifthdat >= le5 And fifthdat <= ue5 And sixthdat >= le5 And sixthdat <= ue5 And DrawCount <= 104 Then
  116.         Y1P25 = Y1P25 + 1 'P25 = e,e,e,e,e,e
  117.     End If
  118.  
  119.     If firstdat >= le5 And firstdat <= ue5 And seconddat >= le5 And seconddat <= ue5 And thirddat >= le5 And thirddat <= ue5 And forthdat >= le5 And forthdat <= ue5 And fifthdat >= le5 And fifthdat <= ue5 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount <= 104 Then
  120.         Y1P26 = Y1P26 + 1 'P26 = e,e,e,e,e,f
  121.     End If
  122.  
  123.     If firstdat >= le5 And firstdat <= ue5 And seconddat >= le5 And seconddat <= ue5 And thirddat >= le5 And thirddat <= ue5 And forthdat >= le5 And forthdat <= ue5 And fifthdat >= le6 And fifthdat <= ue6 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount <= 104 Then
  124.         Y1P27 = Y1P27 + 1 'P27 = e,e,e,e,f,f
  125.     End If
  126.  
  127.     If firstdat >= le5 And firstdat <= ue5 And seconddat >= le5 And seconddat <= ue5 And thirddat >= le5 And thirddat <= ue5 And forthdat >= le6 And forthdat <= ue6 And fifthdat >= le6 And fifthdat <= ue6 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount <= 104 Then
  128.         Y1P28 = Y1P28 + 1 'P28 = e,e,e,f,f,f
  129.     End If
  130.  
  131.     If firstdat >= le5 And firstdat <= ue5 And seconddat >= le5 And seconddat <= ue5 And thirddat >= le6 And thirddat <= ue6 And forthdat >= le6 And forthdat <= ue6 And fifthdat >= le6 And fifthdat <= ue6 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount <= 104 Then
  132.         Y1P29 = Y1P29 + 1 'P29 = e,e,f,f,f,f
  133.     End If
  134.  
  135.     If firstdat >= le5 And firstdat <= ue5 And seconddat >= le6 And seconddat <= ue6 And thirddat >= le6 And thirddat <= ue6 And forthdat >= le6 And forthdat <= ue6 And fifthdat >= le6 And fifthdat <= ue6 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount <= 104 Then
  136.         Y1P30 = Y1P30 + 1 'P30 = e,f,f,f,f,f
  137.     End If
  138.  
  139.     If firstdat >= le6 And firstdat <= ue6 And seconddat >= le6 And seconddat <= ue6 And thirddat >= le6 And thirddat <= ue6 And forthdat >= le6 And forthdat <= ue6 And fifthdat >= le6 And fifthdat <= ue6 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount <= 104 Then
  140.         Y1P31 = Y1P31 + 1 'P31 = f,f,f,f,f,f
  141.     End If
  142.  
  143.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le5 And fifthdat <= ue5 And sixthdat >= le6 And sixthdat <= ue6 Then
  144.         HISP32 = HISP32 + 1 'HISP32 = a,b,c,d,e,f
  145.     End If
  146.  
  147.  
  148.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le5 And fifthdat <= ue5 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount <= 104 Then
  149.         Y1P32 = Y1P32 + 1 'P32 = a,b,c,d,e,f
  150.     End If
  151.  
  152.  
  153.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le5 And fifthdat <= ue5 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount >= count - PrezCycle And DrawCount <= count Then
  154.         PCP32 = PCP32 + 1 'PCP32 = a,b,c,d,e,f
  155.     End If
  156.  
  157.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le5 And fifthdat <= ue5 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount >= count - (PrezCycle + 104) And DrawCount <= count - PrezCycle Then
  158.         FullCP32 = FullCP32 + 1 'FullCP32 = a,b,c,d,e,f
  159.     End If
  160.  
  161.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le1 And seconddat <= ue1 And thirddat >= le2 And thirddat <= ue2 And forthdat >= le3 And forthdat <= ue3 And fifthdat >= le4 And fifthdat <= ue4 And sixthdat >= le5 And sixthdat <= ue5 And DrawCount <= 104 Then
  162.         Y1P33 = Y1P33 + 1 'P33 = a,a,b,c,d,e
  163.     End If
  164.  
  165.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le2 And thirddat <= ue2 And forthdat >= le3 And forthdat <= ue3 And fifthdat >= le4 And fifthdat <= ue4 And sixthdat >= le5 And sixthdat <= ue5 And DrawCount <= 104 Then
  166.         Y1P34 = Y1P34 + 1 'P34 = a,b,b,c,d,e
  167.     End If
  168.  
  169.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le3 And forthdat <= ue3 And fifthdat >= le4 And fifthdat <= ue4 And sixthdat >= le5 And sixthdat <= ue5 And DrawCount <= 104 Then
  170.         Y1P35 = Y1P35 + 1 'P35 = a,b,c,c,d,e
  171.     End If
  172.  
  173.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le4 And fifthdat <= ue4 And sixthdat >= le5 And sixthdat <= ue5 Then
  174.         HISP36 = HISP36 + 1 'HISP36 = a,b,c,d,d,e
  175.     End If
  176.  
  177.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le5 And fifthdat <= ue5 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount >= count - PrezCycle And DrawCount <= count Then
  178.         PCP36 = PCP36 + 1 'PCP36 = a,b,c,d,e,f
  179.     End If
  180.  
  181.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le5 And fifthdat <= ue5 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount >= count - (PrezCycle + 104) And DrawCount <= count - PrezCycle Then
  182.         FullCP36 = FullCP36 + 1 'FullCP36 = a,b,c,d,e,f
  183.     End If
  184.  
  185.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le4 And fifthdat <= ue4 And sixthdat >= le5 And sixthdat <= ue5 And DrawCount <= 104 Then
  186.         Y1P36 = Y1P36 + 1 'P36 = a,b,c,d,d,e
  187.     End If
  188.  
  189.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le5 And fifthdat <= ue5 And sixthdat >= le5 And sixthdat <= ue5 Then
  190.         HISP37 = HISP37 + 1 'HISP37 = a,b,c,d,e,e
  191.     End If
  192.  
  193.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le5 And fifthdat <= ue5 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount >= count - PrezCycle And DrawCount <= count Then
  194.         PCP37 = PCP37 + 1 'PCP37 = a,b,c,d,e,f
  195.     End If
  196.  
  197.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le5 And fifthdat <= ue5 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount >= count - (PrezCycle + 104) And DrawCount <= count - PrezCycle Then
  198.         FullCP37 = FullCP37 + 1 'FullCP37 = a,b,c,d,e,f
  199.     End If
  200.  
  201.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le5 And fifthdat <= ue5 And sixthdat >= le5 And sixthdat <= ue5 And DrawCount <= 104 Then
  202.         Y1P37 = Y1P37 + 1 'P37 = a,b,c,d,e,e
  203.     End If
  204.  
  205.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le1 And seconddat <= ue1 And thirddat >= le2 And thirddat <= ue2 And forthdat >= le3 And forthdat <= ue3 And fifthdat >= le4 And fifthdat <= ue4 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount <= 104 Then
  206.         Y1P38 = Y1P38 + 1 'P38 = a,a,b,c,d,f
  207.     End If
  208.  
  209.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le2 And thirddat <= ue2 And forthdat >= le3 And forthdat <= ue3 And fifthdat >= le4 And fifthdat <= ue4 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount <= 104 Then
  210.         Y1P39 = Y1P39 + 1 'P39 = a,b,b,c,d,f
  211.     End If
  212.  
  213.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le3 And forthdat <= ue3 And fifthdat >= le4 And fifthdat <= ue4 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount <= 104 Then
  214.         Y1P40 = Y1P40 + 1 'P40 = a,b,c,c,d,f
  215.     End If
  216.  
  217.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le4 And fifthdat <= ue4 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount <= 104 Then
  218.         Y1P41 = Y1P41 + 1 'P41 = a,b,c,d,d,f
  219.     End If
  220.  
  221.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le6 And fifthdat <= ue6 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount <= 104 Then
  222.         Y1P42 = Y1P42 + 1 'P42 = a,b,c,d,f,f
  223.     End If
  224.  
  225.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le3 And seconddat <= ue3 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le5 And fifthdat <= ue5 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount <= 104 Then
  226.         Y1P43 = Y1P43 + 1 'P43 = a,c,c,d,e,f
  227.     End If
  228.  
  229.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le3 And seconddat <= ue3 And thirddat >= le4 And thirddat <= ue4 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le5 And fifthdat <= ue5 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount <= 104 Then
  230.         Y1P44 = Y1P44 + 1 'P44 = a,c,d,d,e,f
  231.     End If
  232.  
  233.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le3 And seconddat <= ue3 And thirddat >= le4 And thirddat <= ue4 And forthdat >= le5 And forthdat <= ue5 And fifthdat >= le5 And fifthdat <= ue5 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount <= 104 Then
  234.         Y1P45 = Y1P45 + 1 'P45 = a,c,d,e,e,f
  235.     End If
  236.  
  237.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le3 And seconddat <= ue3 And thirddat >= le4 And thirddat <= ue4 And forthdat >= le5 And forthdat <= ue5 And fifthdat >= le6 And fifthdat <= ue6 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount <= 104 Then
  238.         Y1P46 = Y1P46 + 1 'P46 = a,c,d,e,f,f
  239.     End If
  240.  
  241.  
  242.     If firstdat >= le2 And firstdat <= ue2 And seconddat >= le1 And seconddat <= ue1 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le5 And fifthdat <= ue5 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount <= 104 Then
  243.         Y1P47 = Y1P47 + 1 'P47 = b,a,c,d,e,f
  244.     End If
  245.  
  246.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le3 And seconddat <= ue3 And thirddat >= le2 And thirddat <= ue2 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le5 And fifthdat <= ue5 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount <= 104 Then
  247.         Y1P48 = Y1P48 + 1 'P48 = a,c,b,d,e,f
  248.     End If
  249.  
  250.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le4 And thirddat <= ue4 And forthdat >= le3 And forthdat <= ue3 And fifthdat >= le5 And fifthdat <= ue5 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount <= 104 Then
  251.         Y1P49 = Y1P49 + 1 'P49 = a,b,d,c,e,f
  252.     End If
  253.  
  254.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le5 And forthdat <= ue5 And fifthdat >= le4 And fifthdat <= ue4 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount <= 104 Then
  255.         Y1P50 = Y1P50 + 1 'P50 = a,b,c,e,d,f
  256.     End If
  257.  
  258.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le3 And thirddat <= ue3 And forthdat >= le4 And forthdat <= ue4 And fifthdat >= le6 And fifthdat <= ue6 And sixthdat >= le5 And sixthdat <= ue5 And DrawCount <= 104 Then
  259.         Y1P51 = Y1P51 + 1 'P51 = a,b,c,d,f,e
  260.     End If
  261.  
  262.     If firstdat >= le2 And firstdat <= ue2 And seconddat >= le1 And seconddat <= ue1 And thirddat >= le4 And thirddat <= ue4 And forthdat >= le3 And forthdat <= ue3 And fifthdat >= le5 And fifthdat <= ue5 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount <= 104 Then
  263.         Y1P52 = Y1P52 + 1 'P52 = b,a,d,c,e,f
  264.     End If
  265.  
  266.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le3 And seconddat <= ue3 And thirddat >= le2 And thirddat <= ue2 And forthdat >= le5 And forthdat <= ue5 And fifthdat >= le4 And fifthdat <= ue4 And sixthdat >= le6 And sixthdat <= ue6 And DrawCount <= 104 Then
  267.         Y1P53 = Y1P53 + 1 'P53 = a,c,b,e,d,f
  268.     End If
  269.  
  270.     If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le4 And thirddat <= ue4 And forthdat >= le3 And forthdat <= ue3 And fifthdat >= le6 And fifthdat <= ue6 And sixthdat >= le5 And sixthdat <= ue5 And DrawCount <= 104 Then
  271.         Y1P54 = Y1P54 + 1 'P54 = a,b,d,c,f,e
  272.     End If
  273.  
  274.  
  275.  
  276.  
  277. Sound 2000, 36
  278. Locate 42, 40
  279. Print "     Finished the data search"
  280.  
  281.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Pattern Searching
« Reply #1 on: April 29, 2021, 10:55:58 am »
Hi @Dimster

Does the order of the data matter? I am wondering if you are testing permutations or combinations, in combos a,a,b = a,b,a = b,a,a but in permutations that's 3 different things.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Pattern Searching
« Reply #2 on: April 29, 2021, 11:33:32 am »
One way I'd speed this up is to short circuit your IF statements.

Instead of: 

If firstdat >= le1 And firstdat <= ue1 And seconddat >= le1 And seconddat <= ue1 And thirddat >= le1 And thirddat <= ue1 And forthdat >= le1 And forthdat <= ue1 And fifthdat >= le1 And fifthdat <= ue1 And sixthdat >= le1 And sixthdat <= ue1 And DrawCount <= 104 Then
        Y1P1 = Y1P1 + 1 'P1 = a,a,a,a,a,a
    End If

I'd go with:
If DrawCount <= 104 THEN
   If firstdat >= le1 And firstdat <= ue1 THEN
      If seconddat >= le1 And seconddat <= ue1 THEN
          If thirddat >= le1 And thirddat <= ue1 THEN
              If forthdat >= le1 And forthdat <= ue1 THEN
                   If fifthdat >= le1 And fifthdat <= ue1 THEN
                       If sixthdat >= le1 And sixthdat <= ue1 Then
                           Y1P1 = Y1P1 + 1 'P1 = a,a,a,a,a,a
Lots of:            End If

As soon as the first FALSE occurs, there's no reason to check further conditions.  For example, if DrawCount = 110, you don't have to check your data against anything.  You just skipped 12 IF condition comparisons!
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Pattern Searching
« Reply #3 on: April 29, 2021, 11:40:15 am »
Second step would be to consolidate your logic.

Instead of:

Code: [Select]

    If firstdat >= le1 And firstdat <= ue1 And seconddat >= le1 And seconddat <= ue1 And thirddat >= le1 And thirddat <= ue1 And forthdat >= le1 And forthdat <= ue1 And fifthdat >= le2 And fifthdat <= ue2 And sixthdat >= le2 And sixthdat <= ue2 And DrawCount <= 104 Then
        Y1P3 = Y1P3 + 1 'P3 = a,a,a,a,b,b
    End If
 
    If firstdat >= le1 And firstdat <= ue1 And seconddat >= le1 And seconddat <= ue1 And thirddat >= le1 And thirddat <= ue1 And forthdat >= le2 And forthdat <= ue2 And fifthdat >= le2 And fifthdat <= ue2 And sixthdat >= le2 And sixthdat <= ue2 And DrawCount <= 104 Then
        Y1P4 = Y1P4 + 1 'P4 = a,a,a,b,b,b
    End If
 
    If firstdat >= le1 And firstdat <= ue1 And seconddat >= le1 And seconddat <= ue1 And thirddat >= le2 And thirddat <= ue2 And forthdat >= le2 And forthdat <= ue2 And fifthdat >= le2 And fifthdat <= ue2 And sixthdat >= le2 And sixthdat <= ue2 And DrawCount <= 104 Then
        Y1P5 = Y1P5 + 1 'P5 = a,a,b,b,b,b
    End If
 
    If firstdat >= le1 And firstdat <= ue1 And seconddat >= le2 And seconddat <= ue2 And thirddat >= le2 And thirddat <= ue2 And forthdat >= le2 And forthdat <= ue2 And fifthdat >= le2 And fifthdat <= ue2 And sixthdat >= le2 And sixthdat <= ue2 And DrawCount <= 104 Then
        Y1P6 = Y1P6 + 1 'P6 = a,b,b,b,b,b
    End If
 

ALL 6 of those start with the same logic:   If firstdat >= le1 And firstdat <= ue1 THEN...

Simply check those conditions once and be done with it.  If firstdat < le1, you're not going to increment YIP1, YIP2, YIP3, YIP4, YIP5, OR YIP6.

ONE logic check eliminates them all here...



An event better example is DrawCount.  Almost all your condition checks depend on DrawCount being less than 104...  Just check it once and be done with it.  Save all those multiple condition checks.
« Last Edit: April 29, 2021, 11:44:27 am by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Pattern Searching
« Reply #4 on: April 29, 2021, 11:43:59 am »
DrawCount? where's that coming from?

I would like to know if these number ranges are from the same unit sources like a screen graphic all x and y stuff or are they independent numeric ranges like horse race jockey win/loss%, race track conditions muddy to dry, length of race...

But as Steve is picking up on, there appears to be too much repeat testing.
« Last Edit: April 29, 2021, 11:45:44 am by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Pattern Searching
« Reply #5 on: April 29, 2021, 11:50:19 am »
DrawCount? where's that coming from?

We're not seeing the whole program; just the comparison routine from it.  (Notice there's also no OPEN statement before the EOF(1)?)  DrawCount has to be established BEFORE this point in the program, so we should be able to check if it's less than 104 before anything else.  As far as I can tell, there's absolutely no point in the WHILE loop which changes its value...

IF DrawCount <= 104 THEN
     WHILE NOT EOF(1)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Pattern Searching
« Reply #6 on: April 29, 2021, 11:57:12 am »
I would like to know if these number ranges are from the same unit sources like a screen graphic all x and y stuff or are they independent numeric ranges like horse race jockey win/loss%, race track conditions muddy to dry, length of race...

I'm guessing we're doing some sort of lotto number analysis.  6 numbers, probably with values from 1 to 54, with a bonus ball.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Pattern Searching
« Reply #7 on: April 29, 2021, 12:02:22 pm »
I'm guessing we're doing some sort of lotto number analysis.  6 numbers, probably with values from 1 to 54, with a bonus ball.  ;)

Ha! Lotto, mathematicians call it a tax on mathematical ignorance ;-))

Fine to play with numbers though and pay in free time only.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Pattern Searching
« Reply #8 on: April 29, 2021, 12:58:00 pm »
Alzheimer's setting in boys? You both (steve and bplus) solved this over a year ago:

https://www.qb64.org/forum/index.php?topic=2122.msg113599

Follow that thread, or try to bite a chunk from the PDF I wrote about it (see attachment):

(Sup all?)



You're not done when it works, you're done when it's right.

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Pattern Searching
« Reply #9 on: April 29, 2021, 12:59:43 pm »
Thanks for these approaches. The Draw refers to data drawn in another part of the program. I have a section where various sources (internet, newspapers, library resources etc) provide specific information. As you know GIGO to an ai program is not such a good thing, so I try to be sure the data being inputted is support from at lease 2 or 3 different sources. Drawn Data v's Reliable Data.

Another part of the program I can input Ranges which allow me to look at the results of all the data in different limits. So the lower end (le) and an upper end (ue). Say I want to look a temperatures between 60 and 90 degrees, and then time of day between 1200 hrs and 1700 hrs, etc. The Pattern search is meant to give a look at the over all picture when each element changes.

Hope that gives a little more back ground. Heading back to the drawing board. Been considering Select Case. I haven't tried it because I thought the "IF's" may be faster than the "SELECT's"

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Pattern Searching
« Reply #10 on: April 29, 2021, 01:04:19 pm »
Hi StxAxTIC . I haven't read the entire thread you have posted but will do so. I'm getting an Error 404 when I try to gab the PDF.

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Pattern Searching
« Reply #11 on: April 29, 2021, 02:19:24 pm »
Hello Again  STxAxTIC : I've read through "Order from Chaos" and at first blush the suggestion is to convert numeric to string and adopt a sorting routine. Some of the article is identifying a flaw in RND. I'll read it again as I'm not quite sure if a Pattern Search of strings is faster than one of numeric values nor is a Sort Order coming to mind for the data I'm working with.

I'm trying to search 2 years of data - each line of data represents information that occurred in a period of 1 week - the DrawCount = 104 is 2 years of data collection (as an aside, the DrawCount and DataCount are the same 2yr period). To give a little more context to the data being collected, as I have mentioned before, I'm into the stock market. I'm up against very smart traders, very smart hedge fund managers and very smart ai trading programs. Plus I ain't getting any younger. So to keep pace I'm trying to develop an ai program to help track my portfolio of stocks and the factors that impact them week to week. Ultimately to help me see when I'm in trouble or heading for trouble by understanding how past events have impacted them. Data like temperature impact oil stocks, gas stocks, Costco and Home Depot. The longer the adverse or good temperature lasts can have a bearing on company's health and share price.


All the data i'm collecting is stored numerically as everything I'm reading about ai programs comes with numeric formulas. I suppose Temp = 90 is easily convert to Temp$=STR$(Temp) but it feels like I'm giving up some accuracy in the conversion to and then back from.