This brutal program looks at a different issue but reminds me of what's going on here. It turns out that every odd number can be produced by a formula
a = (x * 2^y - 1) / 3
... for some pair x, y (as long as x is indivisible by 3). This particular relation is used to help say things about the Collatz conjecture if anyone wants to reverse engineer it. For some reason, this code runs slower in later versions of QB64, faster in the SDL version, and fastest in QBjs. Not even close to ready when tried in the BAM.
a = (x * 2^y - 1) / 3
... for some pair x, y (as long as x is indivisible by 3). This particular relation is used to help say things about the Collatz conjecture if anyone wants to reverse engineer it. For some reason, this code runs slower in later versions of QB64, faster in the SDL version, and fastest in QBjs. Not even close to ready when tried in the BAM.
Code: (Select All)
'DefInt A-Z
Dim i, x, y, a, f, xlim, ylim
xlim = 1500
ylim = 1500
For i = 1 To 1001 Step 2
f = 0
x = 0
Do While (f = 0) And (x < xlim)
y = 0
If (x Mod 3) <> 0 Then
Do While (f = 0) And (y < ylim)
a = (x * (2 ^ y) - 1) / 3
If (a = i) Then
Print a; "= ("; _Trim$(Str$(x)); " * 2^"; _Trim$(Str$(y)); ") - 1) / 3"
f = 1
End If
If (f = 1) Then Exit Do
y = y + 1
Loop
If (f = 1) Then Exit Do
End If
x = x + 1
Loop
If (f = 0) Then
Print i; "Increase xlim or ylim."
Beep
End If
Next