Author Topic: Sequence  (Read 6193 times)

0 Members and 1 Guest are viewing this topic.

Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Sequence
« on: September 06, 2020, 09:27:47 pm »
Good evening everyone
Come again on this forum, ask for help on this program to show sequence starting with 3 until 09 dozens.
I spent two nights trying to get him to show and count how many times a sequence of 03 dozens or more came out. I did it shows, but I'm having a hard time getting him to count the strings.
Follow code for anyone who can help me.
Sequencia_11 is exactly what I want, but I'm having trouble making him count each sequence.
Sequencia_01 counts the sequences, but does not show all sequences on the screen.
Thank you very much, for all the attention I've had at other times.

Carlos,
* Sequencia_11 Forum.bas (Filesize: 5.03 KB, Downloads: 106)
* Sequencia_01_forum.bas (Filesize: 4.91 KB, Downloads: 99)
* seque.txt (Filesize: 91.15 KB, Downloads: 119)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Sequence
« Reply #1 on: September 06, 2020, 10:45:57 pm »
Hi @carloscordeiro

Are you just trying to add up the numbers in a record or data line in that txt file?

Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Re: Sequence
« Reply #2 on: September 07, 2020, 12:48:06 am »
Thank you Bplus for responding.

I'm not just trying to add up the numbers of a record or data line in that txt file. I am trying to know in each line or record, how many 3 tens sequences there are in each line or record
Example: line "01 04 06 07 08 09 10 11 12 14 16 17 22 23 24" in this line there is a sequence of 07 tens and another of 3 tens or more. I want to do this for all lines in the.txt file.

I managed to do it with prime numbers using the same file.txt. Unfortunately I am having difficulty with the same sequence of numbers.
I'll send the prime number for you to get an idea.
* Prime 2 a 9.txt (Filesize: 5.68 KB, Downloads: 121)
* prime.txt (Filesize: 91.15 KB, Downloads: 96)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Sequence
« Reply #3 on: September 07, 2020, 01:11:18 am »
Yes, I figured out that you were looking for runs:

Here is the best one:
 
Highest seq 12 on line 949.PNG


Dang you want all of the runs > 2 from each line, I just counted the best in each line.
Back to drawing board :)

Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Re: Sequence
« Reply #4 on: September 07, 2020, 01:30:46 am »
This, I want to show the sequences on the screen, regardless of the tens and together shows how many came out. As in prime numbers.
My difficulty is to show the sequence and count them at the same time
Sequence.jpg
* Sequence.jpg (Filesize: 60.25 KB, Dimensions: 565x246, Views: 191)
« Last Edit: September 07, 2020, 01:32:45 am by carloscordeiro »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Sequence
« Reply #5 on: September 07, 2020, 01:44:09 am »
Hi @carloscordeiro

Do you have a method to your coloring madness? How about a color for each sequence length so it's color coded?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Sequence
« Reply #6 on: September 07, 2020, 02:37:25 am »
News flash the highest sequence is 14!
 
Highest seq is 14! line 782.PNG


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Sequence
« Reply #7 on: September 07, 2020, 04:18:57 am »
OK here we go!

This is a two part program. The first has to be run only once to Analyze the Seque.txt data file. It writes a Seque Analysis.txt file that has all the data you need ready to display.

Code: QB64: [Select]
  1. OPEN "Seque.txt" FOR INPUT AS #1
  2. OPEN "seque analysis.txt" FOR OUTPUT AS #2 'counts seq and start position
  3. DIM sq(1 TO 15) AS INTEGER
  4.     seq = 1: starts = 1: saveseq = 0: lineNum = lineNum + 1: lc$ = SPACE$(15)
  5.     LINE INPUT #1, fl$
  6.     FOR i = 1 TO 15
  7.         n = VAL(MID$(fl$, i * 3 - 2, 3))
  8.         PRINT n;
  9.         IF i > 1 THEN
  10.             IF n = lastn + 1 THEN 'start ofr cont seq
  11.                 seq = seq + 1
  12.             ELSE 'seq ended if it even started
  13.                 sq(seq) = sq(seq) + 1
  14.                 MID$(lc$, starts, seq) = STRING$(seq, HEX$(seq))
  15.                 seq = 1
  16.                 starts = i
  17.             END IF
  18.         END IF
  19.         lastn = n
  20.     NEXT
  21.     sq(seq) = sq(seq) + 1
  22.     MID$(lc$, starts, seq) = STRING$(seq, HEX$(seq))
  23.     PRINT lc$
  24.     b$ = ""
  25.     FOR i = 1 TO 15
  26.         b$ = b$ + STR$(sq(i))
  27.     NEXT
  28.     PRINT #2, fl$ + " " + lc$ + b$
  29.     'PRINT "asleep"
  30.     'SLEEP
  31. 'PRINT #2, "Highest sequence is " + _TRIM$(STR$(highseq)) + " on line #" + _TRIM$(STR$(saveLineNum))
  32. PRINT "File: seque analysis.txt is ready!"
  33.  
  34. 'hint
  35. 'FOR i = 0 TO 15
  36. '    PRINT HEX$(i), VAL("&H" + HEX$(i))
  37. 'NEXT
  38.  
  39.  

I count 35 lines :)



Now this next file is for the big Color Coded show, it has a color for ever sequence number for 1 to 15 just like screen 12! But we need more room to list the sequence count status every line makes to the cumulative total.

Anyway here is code for the Show:
Code: QB64: [Select]
  1. _TITLE "sequence show" ' b+ 2020=09-07
  2. DIM d(1 TO 2029) AS STRING
  3. SCREEN _NEWIMAGE(1200, 720, 12)
  4. _DELAY .25
  5. OPEN "seque analysis.txt" FOR INPUT AS #1
  6. FOR i = 1 TO 2029
  7.     LINE INPUT #1, d(i)
  8. 'PRINT d(2029)  ' good
  9. page = 0
  10. nextPage:
  11. FOR p = 1 TO 40
  12.     IF page + p < 2030 THEN
  13.         n$ = _TRIM$(STR$(page + p))
  14.         blank$ = SPACE$(6)
  15.         MID$(blank$, 2, LEN(n$)) = n$
  16.         COLOR 15
  17.         PRINT blank$;
  18.         fl$ = MID$(d(page + p), 1, 45)
  19.         cs$ = MID$(d(page + p), 46, 15)
  20.         sc$ = MID$(d(page + p), 62)
  21.         FOR i = 1 TO 15
  22.             COLOR VAL("&H" + MID$(cs$, i, 1))
  23.             PRINT MID$(fl$, i * 3 - 2, 3);
  24.         NEXT
  25.         REDIM dat$(0)
  26.         Split sc$, " ", dat$()
  27.         PRINT SPACE$(3);
  28.         FOR i = LBOUND(dat$) TO UBOUND(dat$)
  29.             COLOR i + 1
  30.             blank$ = SPACE$(6)
  31.             MID$(blank$, 1, LEN(dat$(i))) = dat$(i)
  32.             PRINT blank$;
  33.         NEXT
  34.         PRINT
  35.     ELSE
  36.         COLOR 15
  37.         PRINT SPACE$(64) + "*** End of Data ***"
  38.         EXIT FOR
  39.     END IF
  40. PRINT SPACE$(55) + "press u for page Up, d for page Down "
  41. getpage:
  42. pageDir$ = ""
  43. WHILE UCASE$(pageDir$) <> "U" AND UCASE$(pageDir$) <> "D"
  44.     pageDir$ = INKEY$
  45.     _LIMIT 60
  46. IF UCASE$(pageDir$) = "U" THEN
  47.     IF page - 40 >= 0 THEN page = page - 40 ELSE BEEP
  48. ELSEIF UCASE$(pageDir$) = "D" THEN
  49.     IF page + 40 <= 2040 THEN page = page + 40 ELSE BEEP
  50.     IF pageDir$ <> "" THEN BEEP
  51.     GOTO getpage
  52. GOTO nextPage
  53.  
  54. SUB Split (SplitMeString AS STRING, delim AS STRING, loadMeArray() AS STRING)
  55.     DIM curpos AS LONG, arrpos AS LONG, LD AS LONG, dpos AS LONG 'fix use the Lbound the array already has
  56.     curpos = 1: arrpos = LBOUND(loadMeArray): LD = LEN(delim)
  57.     dpos = INSTR(curpos, SplitMeString, delim)
  58.     DO UNTIL dpos = 0
  59.         loadMeArray(arrpos) = MID$(SplitMeString, curpos, dpos - curpos)
  60.         arrpos = arrpos + 1
  61.         IF arrpos > UBOUND(loadMeArray) THEN REDIM _PRESERVE loadMeArray(LBOUND(loadMeArray) TO UBOUND(loadMeArray) + 1000) AS STRING
  62.         curpos = dpos + LD
  63.         dpos = INSTR(curpos, SplitMeString, delim)
  64.     LOOP
  65.     loadMeArray(arrpos) = MID$(SplitMeString, curpos)
  66.     REDIM _PRESERVE loadMeArray(LBOUND(loadMeArray) TO arrpos) AS STRING 'get the ubound correct
  67.  
  68. 'hint
  69. 'FOR i = 0 TO 15
  70. '    PRINT HEX$(i), VAL("&H" + HEX$(i))
  71. 'NEXT
  72.  
  73.  
That program ran a little longer as I had to bring in the big gun, Split SUB ;-))

And here is what the final page on the Big Screen looks like:
 
Sequence Show.PNG


Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Re: Sequence
« Reply #8 on: September 07, 2020, 04:54:58 pm »
Hi Bplus
You understood what I want, it was perfect.  Now I wanted to change the appearance of the screen a little
As it is an advanced schedule, I am not familiar. I can only create simple programs.
I want to change the list of times a sequence goes out to an accountant.
Leave only the file numbers with the colors running on the screen.

(((((((Hello @carloscordeiro.

Do you have a method for your crazy coloring? How about a color for each string length so that it is color-coded?)))))))


I hadn't thought about this hypothesis, I was putting the colors at random.

I really liked the size of the screen, it got a lot of space, but a learning experience.

I'll try to draw the screen here and send it to you if there is a possibility to put a counter.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Sequence
« Reply #9 on: September 07, 2020, 05:04:24 pm »
Hi Bplus
You understood what I want, it was perfect.  Now I wanted to change the appearance of the screen a little
As it is an advanced schedule, I am not familiar. I can only create simple programs.
I want to change the list of times a sequence goes out to an accountant.
Leave only the file numbers with the colors running on the screen.

(((((((Hello @carloscordeiro.

Do you have a method for your crazy coloring? How about a color for each string length so that it is color-coded?)))))))


I hadn't thought about this hypothesis, I was putting the colors at random.

I really liked the size of the screen, it got a lot of space, but a learning experience.

I'll try to draw the screen here and send it to you if there is a possibility to put a counter.

Hey @carloscordeiro

Have you figured out what the numbers on the right side are. They are cumulative totals of ALL sequence lengths including 1, 2, 3, .... all color coded to the QB color = length.

We could also do totals for each line. Then maybe do a cumulative total by a page number at the bottom of page?

Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Re: Sequence
« Reply #10 on: September 07, 2020, 06:53:28 pm »
It would be like the attached image that I want to show.
I only drew 3 lines, but it would be for all lines
Tela.jpg
* Tela.jpg (Filesize: 554.07 KB, Dimensions: 1205x1051, Views: 187)

Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Re: Sequence
« Reply #11 on: September 07, 2020, 06:55:28 pm »
I also wanted a standard color for the numbers that are not in the sequence, I mean, outside the sequences.

Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Re: Sequence
« Reply #12 on: September 07, 2020, 07:01:47 pm »
Image counter correction
Tela.jpg
* Tela.jpg (Filesize: 522.5 KB, Dimensions: 1205x1051, Views: 192)
« Last Edit: September 07, 2020, 07:05:08 pm by carloscordeiro »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Sequence
« Reply #13 on: September 07, 2020, 07:43:07 pm »
Looks like you have it your way!

Here is what I did:
Code: QB64: [Select]
  1. _TITLE "sequence show mod #2" ' b+ 2020=09-07
  2. DIM d(1 TO 2029) AS STRING
  3. SCREEN _NEWIMAGE(700, 740, 12)
  4. _DELAY .25
  5. OPEN "seque analysis.txt" FOR INPUT AS #1
  6. FOR i = 1 TO 2029
  7.     LINE INPUT #1, d(i)
  8. 'PRINT d(2029)  ' good
  9. page = 0
  10. nextPage:
  11. FOR p = 1 TO 40
  12.     IF page + p < 2030 THEN
  13.         n$ = _TRIM$(STR$(page + p))
  14.         blank$ = SPACE$(6)
  15.         MID$(blank$, 2, LEN(n$)) = n$
  16.         COLOR 15
  17.         PRINT blank$;
  18.         fl$ = MID$(d(page + p), 1, 45)
  19.         cs$ = MID$(d(page + p), 46, 15)
  20.         sc$ = MID$(d(page + p), 62)
  21.         IF page = 0 AND p = 1 THEN
  22.             sc2$ = ""
  23.         ELSE
  24.             sc2$ = MID$(d(page + p - 1), 62)
  25.         END IF
  26.         FOR i = 1 TO 15
  27.             COLOR VAL("&H" + MID$(cs$, i, 1))
  28.             PRINT MID$(fl$, i * 3 - 2, 3);
  29.         NEXT
  30.         REDIM dat$(0), dat2$(0)
  31.         Split sc$, " ", dat$()
  32.         IF sc2$ <> "" THEN Split sc2$, " ", dat2$()
  33.         PRINT SPACE$(3);
  34.         FOR i = LBOUND(dat$) TO UBOUND(dat$)
  35.             COLOR i + 1
  36.             blank$ = SPACE$(2)
  37.             IF sc2$ <> "" THEN
  38.                 diff$ = _TRIM$(STR$(VAL(dat$(i)) - VAL(dat2$(i))))
  39.                 MID$(blank$, 1, LEN(diff$)) = diff$
  40.             ELSE
  41.                 MID$(blank$, 1, LEN(dat$(i))) = dat$(i)
  42.             END IF
  43.             PRINT blank$;
  44.         NEXT
  45.         PRINT
  46.     ELSE
  47.         COLOR 15
  48.         PRINT SPACE$(34) + "*** End of Data ***"
  49.         EXIT FOR
  50.     END IF
  51. FOR i = 1 TO 15
  52.     COLOR i
  53.     blank$ = SPACE$(10)
  54.     s$ = "seq of " + _TRIM$(STR$(i))
  55.     MID$(blank$, 2, LEN(s$)) = s$
  56.     PRINT blank$;
  57.     IF i = 8 THEN PRINT
  58. PRINT SPACE$(25) + "press u for page Up, d for page Down ";
  59. getpage:
  60. pageDir$ = ""
  61. WHILE UCASE$(pageDir$) <> "U" AND UCASE$(pageDir$) <> "D"
  62.     pageDir$ = INKEY$
  63.     _LIMIT 60
  64. IF UCASE$(pageDir$) = "U" THEN
  65.     IF page - 40 >= 0 THEN page = page - 40 ELSE BEEP
  66. ELSEIF UCASE$(pageDir$) = "D" THEN
  67.     IF page + 40 <= 2040 THEN page = page + 40 ELSE BEEP
  68.     IF pageDir$ <> "" THEN BEEP
  69.     GOTO getpage
  70. GOTO nextPage
  71.  
  72. SUB Split (SplitMeString AS STRING, delim AS STRING, loadMeArray() AS STRING)
  73.     DIM curpos AS LONG, arrpos AS LONG, LD AS LONG, dpos AS LONG 'fix use the Lbound the array already has
  74.     curpos = 1: arrpos = LBOUND(loadMeArray): LD = LEN(delim)
  75.     dpos = INSTR(curpos, SplitMeString, delim)
  76.     DO UNTIL dpos = 0
  77.         loadMeArray(arrpos) = MID$(SplitMeString, curpos, dpos - curpos)
  78.         arrpos = arrpos + 1
  79.         IF arrpos > UBOUND(loadMeArray) THEN REDIM _PRESERVE loadMeArray(LBOUND(loadMeArray) TO UBOUND(loadMeArray) + 1000) AS STRING
  80.         curpos = dpos + LD
  81.         dpos = INSTR(curpos, SplitMeString, delim)
  82.     LOOP
  83.     loadMeArray(arrpos) = MID$(SplitMeString, curpos)
  84.     REDIM _PRESERVE loadMeArray(LBOUND(loadMeArray) TO arrpos) AS STRING 'get the ubound correct
  85.  
  86. 'hint
  87. 'FOR i = 0 TO 15
  88. '    PRINT HEX$(i), VAL("&H" + HEX$(i))
  89. 'NEXT
  90.  
  91.  

 
sequence show #2.PNG


Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Re: Sequence
« Reply #14 on: September 07, 2020, 08:12:51 pm »
I didn't do Bplus, this is just a drawing I did on the windows paintd

I just added the columns in to be displayed

Insert the counter to be able to draw, so you would have an idea of what I want
* Sequencia_20 Forum.bas (Filesize: 5.97 KB, Downloads: 119)
« Last Edit: September 07, 2020, 10:14:57 pm by carloscordeiro »