Here is the converted ScriptBasic script I used with BaCon if anyone wishing to comment on this to help solve the issue of hanging and not returning a result the help would be appreciated. I haven't used BaCon in a while.
Update: I noticed that my find s code overshot the end of the array. I added a couple things I thought that would help. Still no results and hangs.
Code: Select all
GLOBAL nMax, s, i, j, k2, k3, k4 TYPE long
nMax = 100000000
nMaxSqrt = INT(SQR(nMax))
DECLARE v[50000000] TYPE NUMBER
FUNCTION Tatami(s)
FOR i = 7 TO nMaxSqrt - 1 STEP 2
k2 = i + 3
k3 = i + i - 4
WHILE (k2 <= k3) AND ((i * k2) < nMax)
k4 = INT(nMax / i)
IF k3 < k4 THEN
k4 = k3
END IF
FOR j = k2 TO k4 STEP 2
v[(i * j) / 2] += 1;
NEXT
k2 = k2 + (i + 1)
k3 = k3 + (i - 1)
WEND
NEXT
FOR i = 8 TO nMaxSqrt - 1 STEP 2
k2 = i + 3
k3 = i + i - 4
WHILE (k2 <= k3) AND ((i * k2) < nMax)
k4 = INT(nMax / i)
IF k3 < k4 THEN
k4 = k3
END IF
FOR j = k2 TO k4
v[(i * j) / 2] += 1;
NEXT
k2 = k2 + (i + 1)
k3 = k3 + (i - 1)
WEND
NEXT
FOR i = 0 TO 49999999
IF v[i] = s THEN
RETURN i
EXIT FUNCTION
END IF
NEXT
END FUNCTION
s = 200
PRINT "The smallest room size s for which T(s) = ", s, " is ", Tatami(s)
Compile Output
Code: Select all
[email protected]:~/bacon-dev/examples $ bacon tatami.bac
Converting 'tatami.bac'... done, 55 lines were processed in 0.083 seconds.
Compiling 'tatami.bac'... cc -c tatami.bac.c
cc -o tatami tatami.bac.o -lbacon -L. -lm
Done, program 'tatami' ready.
[email protected]:~/bacon-dev/examples $