r/QBprograms • • Apr 06 '22
QBASIC QBASIC 3n+1 problem
The 3n+1 problem: Start with any positive integer. If even divide by 2, if odd multiply by 3 and add 1. repeat, No matter what you start with you will end up at one.
https://en.wikipedia.org/wiki/Collatz_conjecture
DO
INPUT "Starting value", n
IF n > 0 THEN
m = n
e = 0
o = 0
DO
IF (n MOD 2) = 0 THEN
e = e + 1
n = n / 2
ELSE
o = o + 1
n = 3 * n + 1
END IF
IF n > m THEN m = n
PRINT "Step:"; e + o; " Max:"; m; " Current:"; n
LOOP WHILE n > 1
END IF
LOOP WHILE n > 0
2
Upvotes
View all comments
Show parent comment
1
u/SupremoZanne Apr 07 '22
Well, a few tricks I did were...
used the view source feature in the browser, and got rid of some <p> marks from the HTML code so it could be QB64 complaint.
but what I did, was that I typed DO at the top line in QB64, and the code got shifted into "code mode" for old Reddit, and then I removed the DO from that line since that one was simply there to shift the text.
yup, it took me a few tries to master the proper typing of code into a Reddit post.