_TITLE "Cryptarithm Program Writer #2 ASMD" 'b+ 2020-09-01 ' for rebus challenge by danilin ref: https://www.qb64.org/forum/index.php?topic=2961.msg122153#msg122153
' Takes input for words to add and solve and writes a program to do that.
' 2020-08-31 Let's "add" more than 2 words - Cryptarithm Program Writer +.bas
' write 1 solution because we don't want to run through all 10 digits of 10 letter permutations
' We probably want the letter of the last word to go first (be the last to change). Done that was easy!
' No not done we need to make the last word first!
' 2020-08-31 PM Let's do more than just add - Cryptarithm Program Writer ASMD.bas
' Had to add "_DEFINE A-Z AS _INTEGER64" to programs being written, as one test returned answer
' with e notation.
' 2020-09-01 Got a huge hint from tsh73 from years ago at JB Forum how to make the input to the
' Program Writer a one line, simply enter the whole equation. We will use spaces to separate
' the words from the operators or = sign. Simply smart!
SCREEN _NEWIMAGE(1200, 400, 32) 'need a wider screen taller screen for lot's of solutions restart:
PRINT " For our word equation use the following operator symbols:" PRINT " + add, - subtract, * multiply, \ integer divide and = sign with final word" PRINT " Make sure there is a space between each word and operator or = sign." PRINT " Example > hip * hip = hurray" PRINT " No more than 10 different letters total."
' debug with this old one from JB
'eq$ = "noon + moon + soon = june"
Split eq$, " ", word()
' collect and count letters
FOR w
= nWords
TO 0 STEP -2 'make sure first letter of = word is at top of list 10 permutations take while IF i
= 1 THEN start$
= L$
+ start$: wordCnt
= wordCnt
+ 1 ' make sure the first letter of the last word is listed first, never used wordCnt addit = -1
INPUT " Enter anything to quit, just enter to continue..."; quit$
'OK here we start writing the file
p
= INSTR(eq$
, "\") 'cant open file with "\" in title eqq$
= MID$(eq$
, 1, p
- 1) + "idvd" + MID$(eq$
, p
+ 1) eqq$ = eq$
p
= INSTR(eqq$
, "*") 'cant open file with "*" in title eqq$
= MID$(eqq$
, 1, p
- 1) + "mult" + MID$(eqq$
, p
+ 1)
S1$ = " ' written by Cryptarithm Program Writer #2 ASMD.bas b+ 2020-09-01"
PRINT #1, "_TITLE " + CHR$(34) + "Solve (" + eq$
+ ").bas" + CHR$(34) + S1$
PRINT #1, "SCREEN _NEWIMAGE(1200, 720, 32) 'need a wider screen taller screen for lot's of solutions" PRINT #1, "_SCREENMOVE _MIDDLE" PRINT #1, "_DEFINE A-Z AS _INTEGER64"
S$ = "" ' Header for solution columns, aint we full of hope!
FOR i
= 0 TO nWords
STEP 2 ' setup a header actually should do this at start reguardless of solutions or not S$
= S$
+ CHR$(34) + " " + word
(i
) + CHR$(34) S$
= S$
+ CHR$(34) + word
(i
- 1) + word
(i
) + CHR$(34) IF i
<> nWords
THEN S$
= S$
+ ", " Header$ = S$ ' if there are allot of multiple solutions the we could pause, then cls and fill another with header
PRINT #1, "IF a(xx) = a(yy) THEN GOTO skip"
'ten = 100 * t + 10 * e + n
S$ = word(w) + " = "
S$
= S$
+ "10 ^ " + _TRIM$(STR$(LW
- i
)) + " * " + MID$(word
(w
), i
, 1) IF i
<> LW
THEN S$
= S$
+ " + "
'IF ten + two = four THEN
PRINT #1, "IF " + eq$
+ " THEN" ' here we have a solution
'PRINT count, ten, two, four
S$ = ""
S$ = S$ + word(i)
IF i
<> nWords
THEN S$
= S$
+ ", " 'PRINT #1, "PRINT: PRINT " + CHR$(34) + " Press any to end..." + CHR$(34)
'PRINT #1, "SLEEP"
'PRINT #1, "END"
PRINT #1, "PRINT " + CHR$(34) + " Run is done, goodbye!" + CHR$(34)
curpos
= 1: arrpos
= LBOUND(loadMeArray
): LD
= LEN(delim
) dpos
= INSTR(curpos
, SplitMeString
, delim
) loadMeArray
(arrpos
) = MID$(SplitMeString
, curpos
, dpos
- curpos
) arrpos = arrpos + 1
curpos = dpos + LD
dpos
= INSTR(curpos
, SplitMeString
, delim
) loadMeArray
(arrpos
) = MID$(SplitMeString
, curpos
)