Author Topic: Integral of letters: all combinations of letters of all words  (Read 3733 times)

0 Members and 1 Guest are viewing this topic.

Offline DANILIN

  • Forum Regular
  • Posts: 128
    • View Profile
    • Danilin youtube
Integral of letters: all combinations of letters of all words
« on: October 07, 2020, 02:45:01 pm »
Integral of letters: all combinations of letters of all words

Given a dictionary of thousands of words without extra characters
12345.txt

My program decomposes each word into letters
and creates a table 54321.txt
number of combinations of all letters

 
komblife.gif


=26*25/2 = 25*13 = 325

While sorting is not implemented
I ordered in Excel:

Code: [Select]
1 18912 E S
2 17898 I N
3 14121 A E
4 13913 E R
5 13057 E N
6 12980 I S
7 12694 A N
8 12372 A I
9 12010 A T
10 11760 R S

Code: QB64: [Select]
  1. 'izhitsa.bas
  2. DIM a(26, 26)
  3. OPEN "12345.txt" FOR INPUT AS #1
  4. OPEN "54321.txt" FOR OUTPUT AS #2
  5.  
  6. FOR a = 1 TO 45400
  7.     INPUT #1, s$: s = LEN(s$) ': PRINT s$ ' or all words in memory
  8.  
  9.     FOR x = 1 TO s - 1: FOR y = x + 1 TO s
  10.             v = ASC(MID$(s$, x, 1)) - 64
  11.             w = ASC(MID$(s$, y, 1)) - 64
  12. a(v, w) = a(v, w) + 1: NEXT: NEXT: NEXT
  13.  
  14. z = 1: FOR i = 1 TO 25: FOR j = i + 1 TO 26
  15.         PRINT z, a(i, j), CHR$(i + 64), CHR$(j + 64)
  16.         PRINT #2, z; CHR$(9); a(i, j); CHR$(9); CHR$(i + 64); CHR$(9); CHR$(j + 64)
  17. z = z + 1: NEXT: PRINT: PRINT #2,: NEXT
* 12345.zip (Filesize: 124.18 KB, Downloads: 203)
« Last Edit: October 07, 2020, 02:54:14 pm by DANILIN »
Russia looks world from future. big data is peace data.
https://youtube.com/playlist?list=PLBBTP9oVY7IagpH0g9FNUQ8JqmHwxDDDB
i never recommend anything to anyone and always write only about myself

Offline DANILIN

  • Forum Regular
  • Posts: 128
    • View Profile
    • Danilin youtube
Re: Integral of letters: all combinations of letters of all words
« Reply #1 on: October 12, 2020, 02:15:24 am »
Repeated letters are removed from words
and an intermediate file is created to control

Code: QB64: [Select]
  1. 'izhitsa.bas
  2. '=26*25/2 = 13*25 = 325
  3. DIM a(26, 26)
  4. OPEN "12345.txt" FOR INPUT AS #1
  5. OPEN "135.txt" FOR OUTPUT AS #2
  6. OPEN "54321.txt" FOR OUTPUT AS #3
  7. start = TIMER
  8. z = 1: FOR a = 1 TO 45400
  9.     INPUT #1, s$: s = LEN(s$)
  10.  
  11. FOR m = 1 TO s-1: FOR n = m+1 TO s
  12. IF MID$(s$,m,1) = MID$(s$,n,1) THEN s$ = MID$(s$,1,n-1) + MID$(s$,n+1,LEN(s$))
  13. NEXT: NEXT: s = LEN(s$): LOCATE 1, 1: PRINT z, s$; "          ";: PRINT #2, s$, s: z = z+1
  14.  
  15. FOR x = 1 TO s-1: FOR y = x+1 TO s
  16.             v = ASC(MID$(s$, x, 1))-64
  17.             w = ASC(MID$(s$, y, 1))-64
  18.     a(v, w) = a(v, w)+1: NEXT: NEXT
  19. NEXT: finish = TIMER
  20.  
  21. z = 1: FOR i = 1 TO 25: FOR j = i+1 TO 26
  22.         PRINT z, a(i, j), CHR$(i+64), CHR$(j+64)
  23.         PRINT #3, z; CHR$(9); a(i, j); CHR$(9); CHR$(i+64); CHR$(9); CHR$(j+64)
  24. z = z+1: NEXT: PRINT: PRINT #3,: NEXT
  25. PRINT finish-start
  26. PRINT #2, finish-start

Results:

Code: [Select]
10119 I N
9728 E S
8476 A E
8269 A N
7986 E R
....
4 Q X
3 G J
3 H J
2 G X
1 K Q
Russia looks world from future. big data is peace data.
https://youtube.com/playlist?list=PLBBTP9oVY7IagpH0g9FNUQ8JqmHwxDDDB
i never recommend anything to anyone and always write only about myself

Offline DANILIN

  • Forum Regular
  • Posts: 128
    • View Profile
    • Danilin youtube
Re: Integral of letters: all combinations of letters of all words
« Reply #2 on: November 30, 2020, 01:46:10 pm »
Improved counting of letters regardless of order of letters in alphabet

Practically: square matrix
has become a triangular matrix without main diagonal

And it is still possible to count repetitions of combinations

Code: QB64: [Select]
  1. 'izhitsaEN.bas
  2. '=26*25/2 = 13*25 = 325
  3. DIM a(26, 26)
  4. OPEN "12345.txt" FOR INPUT AS #1
  5. OPEN "135.txt" FOR OUTPUT AS #2
  6. OPEN "54321.txt" FOR OUTPUT AS #3
  7. start = TIMER
  8. z = 1: FOR a = 1 TO 45400
  9.     INPUT #1, s$: s = LEN(s$) ': PRINT s$ ' or all words in memory
  10.     FOR m = 1 TO s - 1: FOR n = m + 1 TO s
  11.             IF MID$(s$, m, 1) = MID$(s$, n, 1) THEN s$ = MID$(s$, 1, n - 1) + MID$(s$, n + 1, LEN(s$))
  12.     NEXT: NEXT: s = LEN(s$)
  13.     LOCATE 1, 1: PRINT z, s$; "          ";: PRINT #2, s$: z = z + 1
  14.  
  15.     FOR x = 1 TO s: FOR y = 1 TO s
  16.             v = ASC(MID$(s$, x, 1)) - 64
  17.             w = ASC(MID$(s$, y, 1)) - 64
  18.     a(v, w) = a(v, w) + 1: NEXT: NEXT
  19.  
  20.     FOR u = 1 TO 25: FOR v = u + 1 TO 26
  21.             a(u, v) = a(u, v) + a(v, u): a(v, u) = 0
  22.     NEXT: NEXT
  23. NEXT: finish = TIMER
  24.  
  25. z = 1: FOR i = 1 TO 25: FOR j = i + 1 TO 26
  26.         PRINT z, a(i, j), CHR$(i + 64), CHR$(j + 64)
  27.         PRINT #3, z; CHR$(9); a(i, j); CHR$(9); CHR$(i + 64); CHR$(9); CHR$(j + 64)
  28. z = z + 1: NEXT: PRINT: PRINT #3,: NEXT
  29. PRINT finish - start
  30. PRINT #2, finish - start

Code: [Select]
33648 E R
32356 E S
30022 E I
28976 A E
28664 I N
28102 E N
27824 E T
24862 I S
24138 A R
24024 I T
...
50 J Z
48 P Q
42 J W
42 X Z
28 W X
24 K X
18 Q X
10 J X
10 Q W
8 J Q
Russia looks world from future. big data is peace data.
https://youtube.com/playlist?list=PLBBTP9oVY7IagpH0g9FNUQ8JqmHwxDDDB
i never recommend anything to anyone and always write only about myself