# Help for a beginner

As a beginner I need help in writing what I hope is a simple program to generate the following type of expressions. The example here is for a string of 6 characters, but the program should begin with a request for the string length.

AAAAAA = BAAAAA
AAAAAA = ABAAAA
AAAAAA = AABAAA
etc

Then

BAAAAA = BBAAAA
BAAAAA = BABAAA
BAAAAA = BAABAA
etc

Then

BBAAAA =BBBAAA
BBAAAA = BBABAA
etc.

The last expression would be

BBBBBBA = BBBBBB

In summary: Start with a string of As n elements long and after a = change the A to B in the first, then second, then third, etc positions. Next, begin with a string that begins with a B and change the following sequence of As as above, sequentially starting the string with increasing numbers of Bs.

Any help will be very much appreciated.

Thanks,
Dave

• Is something like this what you're looking for.

LINE INPUT "Enter String", strng\$
DIM strng1(LEN(strng\$)) AS STRING

FOR x% = 1 TO LEN(strng\$)
strng1(x%) = strng\$
MID\$(strng1(x%), x%, 1) = "B"
PRINT strng1(x%)
NEXT

• : Thanks for your reply. Your suggestion does not work, unfortunately. It simply returns a single "B".

Dave

: Is something like this what you're looking for.
:
:
: LINE INPUT "Enter String", strng\$
: DIM strng1(LEN(strng\$)) AS STRING
:
: FOR x% = 1 TO LEN(strng\$)
: strng1(x%) = strng\$
: MID\$(strng1(x%), x%, 1) = "B"
: PRINT strng1(x%)
: NEXT
:
:

• Hi Dave,
I was trying to find something for my son to learn programming on this site and found your post. Interesting. I did try to put something together. Hope it works for you.

I was amazed that I still remember BASIC though I learnt it 35 years ago and havn't touched it ever since...

DECLARE SUB OutputStr (PosA AS INTEGER, Length AS INTEGER)
DIM i AS INTEGER
DIM l AS INTEGER
CLS

PRINT "Enter the length of your string - "
INPUT l
PRINT
PRINT " ================"
PRINT " || ||"
PRINT " || RESULT ||"
PRINT " || ||"
PRINT " ================"
PRINT

FOR i = 1 TO l
'PRINT i
CALL OutputStr(i - 1, l)
NEXT i

PRINT
PRINT " ================"
PRINT " || ||"
PRINT " || END ! ||"
PRINT " || ||"
PRINT " ================"

END

SUB OutputStr (PosA AS INTEGER, Length AS INTEGER)
DIM a AS INTEGER
DIM i AS INTEGER
DIM l AS INTEGER
DIM s AS INTEGER
DIM outputstring1 AS STRING
DIM outputstring2 AS STRING

s = PosA + 1
outputstring1 = ""
outputstring2 = ""

'build outputstring1

FOR a = 1 TO Length
IF a <= PosA THEN
outputstring1 = outputstring1 + "B"
ELSE
outputstring1 = outputstring1 + "A"
END IF
NEXT a

'build outputstring2

FOR l = 1 TO Length - PosA
outputstring2 = ""
FOR i = 1 TO Length
IF i <= PosA OR i = s THEN
outputstring2 = outputstring2 + "B"
ELSE
outputstring2 = outputstring2 + "A"
END IF
NEXT i
PRINT outputstring1 + " = " + outputstring2
s = s + 1
NEXT l

END SUB

: As a beginner I need help in writing what I hope is a simple program to generate the following type of expressions. The example here is for a string of 6 characters, but the program should begin with a request for the string length.
:
: AAAAAA = BAAAAA
: AAAAAA = ABAAAA
: AAAAAA = AABAAA
: etc
:
: Then
:
: BAAAAA = BBAAAA
: BAAAAA = BABAAA
: BAAAAA = BAABAA
: etc
:
: Then
:
: BBAAAA =BBBAAA
: BBAAAA = BBABAA
: etc.
:
: The last expression would be
:
: BBBBBBA = BBBBBB
:
: In summary: Start with a string of As n elements long and after a = change the A to B in the first, then second, then third, etc positions. Next, begin with a string that begins with a B and change the following sequence of As as above, sequentially starting the string with increasing numbers of Bs.
:
: Any help will be very much appreciated.
:
: Thanks,
: Dave
:
:
:

• Hi and thanks for the reply. You're far better at recalling basic than I am. I am not really a beginner, but like you had not used it for ... well, about the same 35 yrs now that I count back. And it seems whatever skill I had then has vanished. I expect to apply what you provided to some chemistry modeling I am involved in.

Again thanks for the input.

Regards,

Dave

: Hi Dave,
: I was trying to find something for my son to learn programming on this site and found your post. Interesting. I did try to put something together. Hope it works for you.
:
: I was amazed that I still remember BASIC though I learnt it 35 years ago and havn't touched it ever since...
:
: DECLARE SUB OutputStr (PosA AS INTEGER, Length AS INTEGER)
: DIM i AS INTEGER
: DIM l AS INTEGER
: CLS
:
: PRINT "Enter the length of your string - "
: INPUT l
: PRINT
: PRINT " ================"
: PRINT " || ||"
: PRINT " || RESULT ||"
: PRINT " || ||"
: PRINT " ================"
: PRINT
:
: FOR i = 1 TO l
: 'PRINT i
: CALL OutputStr(i - 1, l)
: NEXT i
:
: PRINT
: PRINT " ================"
: PRINT " || ||"
: PRINT " || END ! ||"
: PRINT " || ||"
: PRINT " ================"
:
:
: END
:
: SUB OutputStr (PosA AS INTEGER, Length AS INTEGER)
: DIM a AS INTEGER
: DIM i AS INTEGER
: DIM l AS INTEGER
: DIM s AS INTEGER
: DIM outputstring1 AS STRING
: DIM outputstring2 AS STRING
:
: s = PosA + 1
: outputstring1 = ""
: outputstring2 = ""
:
: 'build outputstring1
:
: FOR a = 1 TO Length
: IF a <= PosA THEN
: outputstring1 = outputstring1 + "B"
: ELSE
: outputstring1 = outputstring1 + "A"
: END IF
: NEXT a
:
:
: 'build outputstring2
:
:
: FOR l = 1 TO Length - PosA
: outputstring2 = ""
: FOR i = 1 TO Length
: IF i <= PosA OR i = s THEN
: outputstring2 = outputstring2 + "B"
: ELSE
: outputstring2 = outputstring2 + "A"
: END IF
: NEXT i
: PRINT outputstring1 + " = " + outputstring2
: s = s + 1
: NEXT l
:
:
: END SUB
:
:
:
: : As a beginner I need help in writing what I hope is a simple program to generate the following type of expressions. The example here is for a string of 6 characters, but the program should begin with a request for the string length.
: :
: : AAAAAA = BAAAAA
: : AAAAAA = ABAAAA
: : AAAAAA = AABAAA
: : etc
: :
: : Then
: :
: : BAAAAA = BBAAAA
: : BAAAAA = BABAAA
: : BAAAAA = BAABAA
: : etc
: :
: : Then
: :
: : BBAAAA =BBBAAA
: : BBAAAA = BBABAA
: : etc.
: :
: : The last expression would be
: :
: : BBBBBBA = BBBBBB
: :
: : In summary: Start with a string of As n elements long and after a = change the A to B in the first, then second, then third, etc positions. Next, begin with a string that begins with a B and change the following sequence of As as above, sequentially starting the string with increasing numbers of Bs.
: :
: : Any help will be very much appreciated.
: :
: : Thanks,
: : Dave
: :
: :
: :
:
: