Author Topic: Codeword solver  (Read 2050 times)

0 Members and 1 Guest are viewing this topic.

Offline david_uwi

  • Newbie
  • Posts: 71
    • View Profile
Codeword solver
« on: July 06, 2020, 07:18:43 am »
Code word is a type of puzzle that has appeared recently (maybe?).
It is like a crossword but there are no clues, instead the grid has numbers which correspond to letters of the alphabet (1 to 26 - not in order obviously).
You have to try to fit in words that will work in the grid and have one letter per number.
It is often difficult to get a start so I have written this program that will search a word list.
There are comment line at the beginning that explain the input.
As a hint longer words are often best as there are much fewer words with 10 letters than there are with 5 also the pattern of repeated and unique letters is larger. There is also a function to eliminate known letters, but this has not been tested.

Code: QB64: [Select]
  1. OPEN "c:\cw1\dictionary_english.dic" FOR INPUT AS #1
  2. DIM word$(320000)
  3. DIM q1 AS STRING * 1, q2 AS STRING * 1 'there are problems if these are not dimensioned
  4. DIM wdot(25) AS STRING * 1, wndot(25) AS STRING * 1, wndot1(25) AS STRING * 1
  5. DIM w2(7) AS STRING * 1, w3(7) AS STRING * 1, w4(7) AS STRING * 1, w5(7) AS STRING * 1
  6. DIM ex1 AS STRING * 1
  7. DIM r1$(20)
  8. SCREEN _NEWIMAGE(1000, 500, 2)
  9.  
  10. 'font1& = _LOADFONT("c:\windows\fonts\courbd.ttf", 20, "bold")  'courier bold
  11. 'font1& = _LOADFONT("c:\windows\fonts\times.ttf", 20, "bold") 'times bold
  12. font1& = _LOADFONT("c:\windows\fonts\cour.ttf", 20, "bold") 'courier regular
  13. _FONT font1& 'lets have a monospaced font - lines up better
  14.  
  15. 'either put in the numbers in the puzzle separated by "," OR
  16. 'put in "." for unknowns and the numbers 2,3,4,5 for duplicates
  17. '.2334.4N52.54 will work as will 13,8,21,21,4,16,4,N,3,8,10,3,4 [the N was a given letter]
  18. 'both will give differentiate
  19.  
  20. 'when letters are given (or known) they can be excluded by loading an exclusion list
  21. 'input ! followed by the letters, this can be added to by ! [more letters] and reset by just putting in !
  22.  
  23. ' **************************all duplicates MUST be put in**********************
  24. 'for crosswords this will not work!!!
  25. PRINT "loading word list....please wait"
  26. FOR i = 1 TO 319378
  27.     INPUT #1, word$(i) 'load list into RAM it is much faster
  28.    200 PRINT "input word  ";
  29.     LINE INPUT a$
  30.     f$ = a$
  31.     IF INSTR(a$, ",") <> 0 THEN GOSUB longform
  32.     IF LEFT$(a$, 1) = "!" THEN
  33.         IF LEN(a$) = 1 THEN ex$ = ""
  34.         IF LEN(a$) > 1 THEN ex$ = RIGHT$(a$, LEN(a$) - 1) + ex$
  35.         lex1 = LEN(ex$)
  36.         IF lex1 > 0 THEN PRINT "exclusion list  "; ex$
  37.         IF lex1 = 0 THEN PRINT "exclusion list reset"
  38.         GOTO 200
  39.     END IF
  40.     x1 = LEN(a$)
  41.     z$ = a$
  42.     'z$ original input string
  43.     'a$ input string with 2,3,..replaced by dots
  44.     'b$ test string from word list
  45.     FOR i = 1 TO x1
  46.         IF ASC(MID$(a$, i, 1)) < 56 THEN MID$(a$, i, 1) = "."
  47.     NEXT i
  48.     exq$ = ""
  49.     FOR i = 1 TO x1
  50.         IF MID$(a$, i, 1) <> "." THEN exq$ = exq$ + MID$(a$, i, 1)
  51.     NEXT i
  52.     IF a$ = "end" THEN EXIT DO
  53.     FOR ii = 1 TO 319378
  54.         b$ = word$(ii)
  55.         IF LEN(b$) = x1 THEN
  56.             FOR i = 1 TO x1
  57.                 q1 = MID$(a$, i, 1)
  58.                 IF q1 <> "." THEN
  59.                     q2 = MID$(b$, i, 1)
  60.                     IF q1 <> q2 THEN 20
  61.                 END IF
  62.             NEXT i
  63.             k2 = 0
  64.             FOR i = 1 TO x1
  65.                 q1 = MID$(z$, i, 1)
  66.                 IF q1 = "2" THEN
  67.                     k2 = k2 + 1
  68.                     w2(k2) = MID$(b$, i, 1)
  69.                 END IF
  70.             NEXT i
  71.             k3 = 0
  72.             FOR i = 1 TO x1
  73.                 q1 = MID$(z$, i, 1)
  74.                 IF q1 = "3" THEN
  75.                     k3 = k3 + 1
  76.                     w3(k3) = MID$(b$, i, 1)
  77.                 END IF
  78.             NEXT i
  79.             k4 = 0
  80.             FOR i = 1 TO x1
  81.                 q1 = MID$(z$, i, 1)
  82.                 IF q1 = "4" THEN
  83.                     k4 = k4 + 1
  84.                     w4(k4) = MID$(b$, i, 1)
  85.                 END IF
  86.             NEXT i
  87.             k5 = 0
  88.             FOR i = 1 TO x1
  89.                 q1 = MID$(z$, i, 1)
  90.                 IF q1 = "5" THEN
  91.                     k5 = k5 + 1
  92.                     w5(k5) = MID$(b$, i, 1)
  93.                 END IF
  94.             NEXT i
  95.  
  96.             kdot = 0
  97.             FOR i = 1 TO x1
  98.                 q1 = MID$(z$, i, 1)
  99.                 IF q1 = "." THEN
  100.                     kdot = kdot + 1
  101.                     wdot(kdot) = MID$(b$, i, 1)
  102.                 END IF
  103.             NEXT i
  104.             kndot = 0
  105.             FOR i = 1 TO x1
  106.                 q1 = MID$(z$, i, 1)
  107.                 IF q1 <> "." THEN
  108.                     kndot = kndot + 1
  109.                     wndot(kndot) = MID$(b$, i, 1)
  110.                 END IF
  111.             NEXT i
  112.             kndot1 = 0
  113.             FOR i = 1 TO x1
  114.                 q1 = MID$(a$, i, 1)
  115.                 IF q1 <> "." THEN
  116.                     kndot1 = kndot1 + 1
  117.                     wndot1(kndot1) = MID$(a$, i, 1)
  118.                 END IF
  119.             NEXT i
  120.  
  121.             'PRINT k2; k3; w2$(1): INPUT sa$
  122.             'make sure all dots are different
  123.             IF k2 <> 0 THEN
  124.                 FOR i = 1 TO k2 - 1
  125.                     IF w2(i) <> w2(i + 1) THEN 20
  126.                 NEXT i
  127.             END IF
  128.  
  129.             IF k3 <> 0 THEN
  130.                 FOR i = 1 TO k3 - 1
  131.                     IF w3(i) <> w3(i + 1) THEN 20
  132.                 NEXT i
  133.             END IF
  134.             IF k4 <> 0 THEN
  135.                 FOR i = 1 TO k4 - 1
  136.                     IF w4(i) <> w4(i + 1) THEN 20
  137.                 NEXT i
  138.             END IF
  139.             IF k5 <> 0 THEN
  140.                 FOR i = 1 TO k5 - 1
  141.                     IF w5(i) <> w5(i + 1) THEN 20
  142.                 NEXT i
  143.             END IF
  144.  
  145.             'now checking if any of the dots are the same as inputted letters
  146.             IF kdot <> 0 THEN
  147.                 FOR i = 1 TO kdot - 1
  148.                     FOR j = i + 1 TO kdot
  149.  
  150.                         IF wdot(i) = wdot(j) THEN 20
  151.                     NEXT j
  152.                 NEXT i
  153.             END IF
  154.             FOR i = 1 TO kdot
  155.                 FOR j = 1 TO kndot
  156.  
  157.                     IF wdot(i) = wndot(j) THEN 20
  158.                 NEXT j
  159.             NEXT i
  160.             'now checking for duplicates in repeated letters
  161.             x2 = INSTR(z$, "2")
  162.             x3 = INSTR(z$, "3")
  163.             x4 = INSTR(z$, "4")
  164.             x5 = INSTR(z$, "5")
  165.             IF x3 <> 0 THEN
  166.                 IF MID$(b$, x2, 1) = MID$(b$, x3, 1) THEN 20
  167.             END IF
  168.             IF x4 <> 0 THEN
  169.                 IF MID$(b$, x2, 1) = MID$(b$, x4, 1) THEN 20
  170.                 IF MID$(b$, x3, 1) = MID$(b$, x4, 1) THEN 20
  171.             END IF
  172.             IF k5 <> 0 THEN
  173.                 IF MID$(b$, x2, 1) = MID$(b$, x5, 1) THEN 20
  174.                 IF MID$(b$, x3, 1) = MID$(b$, x5, 1) THEN 20
  175.                 IF MID$(b$, x4, 1) = MID$(b$, x5, 1) THEN 20
  176.  
  177.             END IF
  178.             'now check if any of the given letters are the same as multiples
  179.             IF x2 <> 0 THEN
  180.                 FOR j = 1 TO kndot1
  181.                     IF MID$(b$, x2, 1) = wndot1(j) THEN 20
  182.                 NEXT j
  183.             END IF
  184.             IF x3 <> 0 THEN
  185.                 FOR j = 1 TO kndot1
  186.                     IF MID$(b$, x3, 1) = wndot1(j) THEN 20
  187.                 NEXT j
  188.             END IF
  189.             IF x4 <> 0 THEN
  190.                 FOR j = 1 TO kndot1
  191.                     IF MID$(b$, x4, 1) = wndot1(j) THEN 20
  192.                 NEXT j
  193.             END IF
  194.             IF x5 <> 0 THEN
  195.                 FOR j = 1 TO kndot1
  196.                     IF MID$(b$, x5, 1) = wndot1(j) THEN 20
  197.                 NEXT j
  198.             END IF
  199.  
  200.  
  201.  
  202.             'use exclusion list if loaded
  203.             IF lex1 > 0 THEN
  204.                 FOR ie = 1 TO lex1
  205.                     ex1 = MID$(ex$, ie, 1)
  206.                     IF INSTR(exq$, ex1) = 0 THEN 'lets not remove known letters
  207.                         IF INSTR(b$, ex1) > 0 THEN 20
  208.                     END IF
  209.                 NEXT ie
  210.             END IF
  211.             PRINT b$,
  212.         END IF
  213.    20 NEXT ii
  214.  
  215.     PRINT ""
  216. longform:
  217. p0 = 1: kk = 0
  218. r1$ = ""
  219. r2$ = ""
  220.     kk = kk + 1
  221.     p1 = INSTR(p0, a$, ",")
  222.     IF p1 = 0 THEN
  223.         r1$(kk) = MID$(f$, p0, LEN(f$) - p0 + 1)
  224.         EXIT DO
  225.     END IF
  226.     r1$(kk) = MID$(f$, p0, p1 - p0)
  227.     p0 = p1 + 1
  228. FOR nn = 1 TO kk
  229.     'PRINT r1$(nn); ASC(r1$(nn))
  230. NEXT nn
  231. u1 = 0
  232. FOR ii = 1 TO kk
  233.     IF r1$(ii) = "." THEN 100
  234.     IF LEN(r1$(ii)) = 3 THEN 100
  235.     IF ASC(r1$(ii)) < 58 THEN
  236.         FOR jj = ii + 1 TO kk
  237.             IF r1$(jj) = "." THEN 120
  238.             IF LEN(r1$(jj)) = 3 THEN 120
  239.             IF ASC(r1$(jj)) < 58 THEN
  240.                 'PRINT r1$(ii); r1$(jj), ii; jj; LEN(r1$(jj)): INPUT sa$
  241.                 IF r1$(ii) = r1$(jj) THEN r1$(jj) = CHR$(50 + u1) + CHR$(50 + u1) + CHR$(50 + u1): u2 = 99
  242.             END IF
  243.  
  244.         120 NEXT jj
  245.         IF u2 = 0 THEN r1$(ii) = "."
  246.         IF u2 = 99 THEN
  247.             u2 = 0
  248.             r1$(ii) = CHR$(50 + u1) + CHR$(50 + u1) + CHR$(50 + u1)
  249.             u1 = u1 + 1
  250.         END IF
  251.     END IF
  252. 100 NEXT ii
  253. f$ = ""
  254. FOR ii = 1 TO kk
  255.     IF LEN(r1$(ii)) = 3 THEN r1$(ii) = LEFT$(r1$(ii), 1)
  256.  
  257.     f$ = f$ + r1$(ii)
  258. NEXT ii
  259. a$ = f$
  260. 'PRINT a$, LEN(a$)
  261.  
  262.  
  263. 'why does this get slower after several searches???
  264. 'changing q1$ to string*1 seems to solve it!
« Last Edit: July 07, 2020, 12:39:38 pm by david_uwi »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Code word solver
« Reply #1 on: July 06, 2020, 11:19:30 am »
Hi @david_uwi

I tried your code and ran smack into problem of not having Dictionary file, you might include that with your code in a .zip package or recommend a file to download (that your code can work with) from Internet.


Offline david_uwi

  • Newbie
  • Posts: 71
    • View Profile
Re: Code word solver
« Reply #2 on: July 06, 2020, 11:31:12 am »
here's the word list I use (it is crap) I'm sure you can find a better one.
Change the number in the loading loop to the number of words in your word list of choice.
* dictionary_english.zip (Filesize: 942.01 KB, Downloads: 193)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Code word solver
« Reply #3 on: July 06, 2020, 11:40:43 am »
Yes, I have a couple lists but your code appears to be using one of a particular size.

Right now I just wanted to see what you're doing, thanks for your copy.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Code word solver
« Reply #4 on: July 06, 2020, 11:44:29 am »
David, you might be interested in my cipher crossword program

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

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Code word solver
« Reply #5 on: July 06, 2020, 11:45:02 am »
Well the file you passed is password protected. 😒

Offline david_uwi

  • Newbie
  • Posts: 71
    • View Profile
Re: Code word solver
« Reply #6 on: July 06, 2020, 12:09:10 pm »
Here it is unzipped. I downloaded it when I had very limited internet access. It has a lot of rubbish words and a few obvious missing word (particularly composite -see sweetpea and chequerboard).
I've just done an online search of codeword solvers and they use much the same notation as mine -maybe there is only so many way of doing it. Note my multiple letters start at 2 as 1 looked too much like a lower case L.
* dictionary_english.dic (Filesize: 3.45 MB, Downloads: 216)
« Last Edit: July 06, 2020, 12:14:07 pm by david_uwi »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Code word solver
« Reply #7 on: July 06, 2020, 01:29:11 pm »
Well how long does this word input need to go on?

I put in about 2 dozen words and the last was "end" and that was that! This is not fun so far, maybe some more instruction please.

BTW the new file did work when I removed the path.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Code word solver
« Reply #8 on: July 06, 2020, 01:46:01 pm »
Yep more instruction needed, like is there a special code when inputting words to stop?
Code: QB64: [Select]
  1. OPEN "dictionary_english.dic" FOR INPUT AS #1
  2. DIM word$(320000)
  3. DIM q1 AS STRING * 1, q2 AS STRING * 1 'there are problems if these are not dimensioned
  4. DIM wdot(25) AS STRING * 1, wndot(25) AS STRING * 1, wndot1(25) AS STRING * 1
  5. DIM w2(7) AS STRING * 1, w3(7) AS STRING * 1, w4(7) AS STRING * 1, w5(7) AS STRING * 1
  6. DIM ex1 AS STRING * 1
  7. DIM r1$(20)
  8. SCREEN _NEWIMAGE(1000, 500, 2)
  9.  
  10. 'font1& = _LOADFONT("c:\windows\fonts\courbd.ttf", 20, "bold")  'courier bold
  11. 'font1& = _LOADFONT("c:\windows\fonts\times.ttf", 20, "bold") 'times bold
  12. font1& = _LOADFONT("c:\windows\fonts\cour.ttf", 20, "bold") 'courier regular
  13. _FONT font1& 'lets have a monospaced font - lines up better
  14.  
  15. 'either put in the numbers in the puzzle separated by "," OR
  16. 'put in "." for unknowns and the numbers 2,3,4,5 for duplicates
  17. '.2334.4N52.54 will work as will 13,8,21,21,4,16,4,N,3,8,10,3,4 [the N was a given letter]
  18. 'both will give differentiate
  19.  
  20. 'when letters are given (or known) they can be excluded by loading an exclusion list
  21. 'input ! followed by the letters, this can be added to by ! [more letters] and reset by just putting in !
  22.  
  23. ' **************************all duplicates MUST be put in**********************
  24. 'for crosswords this will not work!!!
  25. PRINT "loading word list....please wait"
  26. FOR i = 1 TO 319378
  27.     INPUT #1, word$(i) 'load list into RAM it is much faster
  28.     '200 PRINT "input word  ";
  29.     'LINE INPUT a$
  30.  
  31.     ' avoid tedious task of making up how ever many words this thing wants
  32.    200 a$ = word$(INT(RND * 319378))
  33.  
  34.  
  35.  
  36.  
  37.     f$ = a$
  38.     IF INSTR(a$, ",") <> 0 THEN GOSUB longform
  39.     IF LEFT$(a$, 1) = "!" THEN
  40.         IF LEN(a$) = 1 THEN ex$ = ""
  41.         IF LEN(a$) > 1 THEN ex$ = RIGHT$(a$, LEN(a$) - 1) + ex$
  42.         lex1 = LEN(ex$)
  43.         IF lex1 > 0 THEN PRINT "exclusion list  "; ex$
  44.         IF lex1 = 0 THEN PRINT "exclusion list reset"
  45.         GOTO 200
  46.     END IF
  47.     x1 = LEN(a$)
  48.     z$ = a$
  49.     'z$ original input string
  50.     'a$ input string with 2,3,..replaced by dots
  51.     'b$ test string from word list
  52.     FOR i = 1 TO x1
  53.         IF ASC(MID$(a$, i, 1)) < 56 THEN MID$(a$, i, 1) = "."
  54.     NEXT i
  55.     exq$ = ""
  56.     FOR i = 1 TO x1
  57.         IF MID$(a$, i, 1) <> "." THEN exq$ = exq$ + MID$(a$, i, 1)
  58.     NEXT i
  59.     IF a$ = "end" THEN EXIT DO
  60.     FOR ii = 1 TO 319378
  61.         b$ = word$(ii)
  62.         IF LEN(b$) = x1 THEN
  63.             FOR i = 1 TO x1
  64.                 q1 = MID$(a$, i, 1)
  65.                 IF q1 <> "." THEN
  66.                     q2 = MID$(b$, i, 1)
  67.                     IF q1 <> q2 THEN 20
  68.                 END IF
  69.             NEXT i
  70.             k2 = 0
  71.             FOR i = 1 TO x1
  72.                 q1 = MID$(z$, i, 1)
  73.                 IF q1 = "2" THEN
  74.                     k2 = k2 + 1
  75.                     w2(k2) = MID$(b$, i, 1)
  76.                 END IF
  77.             NEXT i
  78.             k3 = 0
  79.             FOR i = 1 TO x1
  80.                 q1 = MID$(z$, i, 1)
  81.                 IF q1 = "3" THEN
  82.                     k3 = k3 + 1
  83.                     w3(k3) = MID$(b$, i, 1)
  84.                 END IF
  85.             NEXT i
  86.             k4 = 0
  87.             FOR i = 1 TO x1
  88.                 q1 = MID$(z$, i, 1)
  89.                 IF q1 = "4" THEN
  90.                     k4 = k4 + 1
  91.                     w4(k4) = MID$(b$, i, 1)
  92.                 END IF
  93.             NEXT i
  94.             k5 = 0
  95.             FOR i = 1 TO x1
  96.                 q1 = MID$(z$, i, 1)
  97.                 IF q1 = "5" THEN
  98.                     k5 = k5 + 1
  99.                     w5(k5) = MID$(b$, i, 1)
  100.                 END IF
  101.             NEXT i
  102.  
  103.             kdot = 0
  104.             FOR i = 1 TO x1
  105.                 q1 = MID$(z$, i, 1)
  106.                 IF q1 = "." THEN
  107.                     kdot = kdot + 1
  108.                     wdot(kdot) = MID$(b$, i, 1)
  109.                 END IF
  110.             NEXT i
  111.             kndot = 0
  112.             FOR i = 1 TO x1
  113.                 q1 = MID$(z$, i, 1)
  114.                 IF q1 <> "." THEN
  115.                     kndot = kndot + 1
  116.                     wndot(kndot) = MID$(b$, i, 1)
  117.                 END IF
  118.             NEXT i
  119.             kndot1 = 0
  120.             FOR i = 1 TO x1
  121.                 q1 = MID$(a$, i, 1)
  122.                 IF q1 <> "." THEN
  123.                     kndot1 = kndot1 + 1
  124.                     wndot1(kndot1) = MID$(a$, i, 1)
  125.                 END IF
  126.             NEXT i
  127.  
  128.             'PRINT k2; k3; w2$(1): INPUT sa$
  129.             'make sure all dots are different
  130.             IF k2 <> 0 THEN
  131.                 FOR i = 1 TO k2 - 1
  132.                     IF w2(i) <> w2(i + 1) THEN 20
  133.                 NEXT i
  134.             END IF
  135.  
  136.             IF k3 <> 0 THEN
  137.                 FOR i = 1 TO k3 - 1
  138.                     IF w3(i) <> w3(i + 1) THEN 20
  139.                 NEXT i
  140.             END IF
  141.             IF k4 <> 0 THEN
  142.                 FOR i = 1 TO k4 - 1
  143.                     IF w4(i) <> w4(i + 1) THEN 20
  144.                 NEXT i
  145.             END IF
  146.             IF k5 <> 0 THEN
  147.                 FOR i = 1 TO k5 - 1
  148.                     IF w5(i) <> w5(i + 1) THEN 20
  149.                 NEXT i
  150.             END IF
  151.  
  152.             'now checking if any of the dots are the same as inputted letters
  153.             IF kdot <> 0 THEN
  154.                 FOR i = 1 TO kdot - 1
  155.                     FOR j = i + 1 TO kdot
  156.  
  157.                         IF wdot(i) = wdot(j) THEN 20
  158.                     NEXT j
  159.                 NEXT i
  160.             END IF
  161.             FOR i = 1 TO kdot
  162.                 FOR j = 1 TO kndot
  163.  
  164.                     IF wdot(i) = wndot(j) THEN 20
  165.                 NEXT j
  166.             NEXT i
  167.             'now checking for duplicates in repeated letters
  168.             x2 = INSTR(z$, "2")
  169.             x3 = INSTR(z$, "3")
  170.             x4 = INSTR(z$, "4")
  171.             x5 = INSTR(z$, "5")
  172.             IF x3 <> 0 THEN
  173.                 IF MID$(b$, x2, 1) = MID$(b$, x3, 1) THEN 20
  174.             END IF
  175.             IF x4 <> 0 THEN
  176.                 IF MID$(b$, x2, 1) = MID$(b$, x4, 1) THEN 20
  177.                 IF MID$(b$, x3, 1) = MID$(b$, x4, 1) THEN 20
  178.             END IF
  179.             IF k5 <> 0 THEN
  180.                 IF MID$(b$, x2, 1) = MID$(b$, x5, 1) THEN 20
  181.                 IF MID$(b$, x3, 1) = MID$(b$, x5, 1) THEN 20
  182.                 IF MID$(b$, x4, 1) = MID$(b$, x5, 1) THEN 20
  183.  
  184.             END IF
  185.             'now check if any of the given letters are the same as multiples
  186.             IF x2 <> 0 THEN
  187.                 FOR j = 1 TO kndot1
  188.                     IF MID$(b$, x2, 1) = wndot1(j) THEN 20
  189.                 NEXT j
  190.             END IF
  191.             IF x3 <> 0 THEN
  192.                 FOR j = 1 TO kndot1
  193.                     IF MID$(b$, x3, 1) = wndot1(j) THEN 20
  194.                 NEXT j
  195.             END IF
  196.             IF x4 <> 0 THEN
  197.                 FOR j = 1 TO kndot1
  198.                     IF MID$(b$, x4, 1) = wndot1(j) THEN 20
  199.                 NEXT j
  200.             END IF
  201.             IF x5 <> 0 THEN
  202.                 FOR j = 1 TO kndot1
  203.                     IF MID$(b$, x5, 1) = wndot1(j) THEN 20
  204.                 NEXT j
  205.             END IF
  206.  
  207.  
  208.  
  209.             'use exclusion list if loaded
  210.             IF lex1 > 0 THEN
  211.                 FOR ie = 1 TO lex1
  212.                     ex1 = MID$(ex$, ie, 1)
  213.                     IF INSTR(exq$, ex1) = 0 THEN 'lets not remove known letters
  214.                         IF INSTR(b$, ex1) > 0 THEN 20
  215.                     END IF
  216.                 NEXT ie
  217.             END IF
  218.             PRINT b$,
  219.         END IF
  220.    20 NEXT ii
  221.  
  222.     PRINT ""
  223.  
  224.  
  225. longform:
  226. p0 = 1: kk = 0
  227. r1$ = ""
  228. r2$ = ""
  229.     kk = kk + 1
  230.     p1 = INSTR(p0, a$, ",")
  231.     IF p1 = 0 THEN
  232.         r1$(kk) = MID$(f$, p0, LEN(f$) - p0 + 1)
  233.         EXIT DO
  234.     END IF
  235.     r1$(kk) = MID$(f$, p0, p1 - p0)
  236.     p0 = p1 + 1
  237. FOR nn = 1 TO kk
  238.     'PRINT r1$(nn); ASC(r1$(nn))
  239. NEXT nn
  240. u1 = 0
  241. FOR ii = 1 TO kk
  242.     IF r1$(ii) = "." THEN 100
  243.     IF LEN(r1$(ii)) = 3 THEN 100
  244.     IF ASC(r1$(ii)) < 58 THEN
  245.         FOR jj = ii + 1 TO kk
  246.             IF r1$(jj) = "." THEN 120
  247.             IF LEN(r1$(jj)) = 3 THEN 120
  248.             IF ASC(r1$(jj)) < 58 THEN
  249.                 'PRINT r1$(ii); r1$(jj), ii; jj; LEN(r1$(jj)): INPUT sa$
  250.                 IF r1$(ii) = r1$(jj) THEN r1$(jj) = CHR$(50 + u1) + CHR$(50 + u1) + CHR$(50 + u1): u2 = 99
  251.             END IF
  252.  
  253.         120 NEXT jj
  254.         IF u2 = 0 THEN r1$(ii) = "."
  255.         IF u2 = 99 THEN
  256.             u2 = 0
  257.             r1$(ii) = CHR$(50 + u1) + CHR$(50 + u1) + CHR$(50 + u1)
  258.             u1 = u1 + 1
  259.         END IF
  260.     END IF
  261. 100 NEXT ii
  262. f$ = ""
  263. FOR ii = 1 TO kk
  264.     IF LEN(r1$(ii)) = 3 THEN r1$(ii) = LEFT$(r1$(ii), 1)
  265.  
  266.     f$ = f$ + r1$(ii)
  267. NEXT ii
  268. a$ = f$
  269. 'PRINT a$, LEN(a$)
  270.  
  271.  
  272. 'why does this get slower after several searches???
  273. 'changing q1$ to string*1 seems to solve it!
  274.  
  275.  
  276.  

This thing seems stuck in endless word input loop.
« Last Edit: July 06, 2020, 01:53:40 pm by bplus »

Offline david_uwi

  • Newbie
  • Posts: 71
    • View Profile
Re: Code word solver
« Reply #9 on: July 06, 2020, 02:56:40 pm »
Yes it does take a while for all the words to load (I've got a SSD).
The searching is much quicker when loaded in RAM rather than on the hard drive so that is the reason for this.
Don't put in end as that is the word that I used to stop execution.
At the prompt put in .2334.4n52.54 (this was an actual example from a "sunday telegraph" puzzle)
the string indicates that there is a "N" in the middle (a known letter)
positions 2 and 9 are the same letter, positions 3 and 4 likewise 5,7 and 13 are the same 9 and 12 are also the same.
The dots represent single unknown letters.
In the actual codeword the numbers were  13,8,21,21,4,16,4,n,3,8,10,3,4 and this is also accepted as input.
Both will give just one word differentiate, which may be enough to solve (with a bit of thought) the whole puzzle.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Code word solver
« Reply #10 on: July 06, 2020, 03:29:36 pm »
Oh so this helps you solve puzzles you are working on from the paper! Sorry I thought you had some word game going.

Now I get it.  Cool! 

I did something similar for a Word Puzzle called the Scrambler, you unscramble the words and then used circled letters to solve a question from cartoon and caption that usually involves a clever pun.