I added a new function to the extension module called

**add_v** which reduces the

**v** bumps to one call instead of two.

Here is 100. The only silver lining is I will be able to do 200 but no prizes expected.

Code: Select all

```
pi@RPi4B:~/sbrt/examples $ time scriba Tatami_ext.sb 100
The smallest room size s for which T(s) = 100 is 6683040
real 12m10.151s
user 12m9.426s
sys 0m0.432s
pi@RPi4B:~/sbrt/examples $
```

I'll post the 200 results when they come in.

**Tatami_ext.sb**
Code: Select all

```
' Tatami.sb
DECLARE SUB get_v ALIAS "get_v" LIB "ta"
DECLARE SUB set_v ALIAS "set_v" LIB "ta"
DECLARE SUB add_v ALIAS "add_v" LIB "ta"
nMax = 100000000
nMaxSqrt = INT(SQR(nMax))
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
add_v(i * j, 1)
NEXT
k2 += i + 1
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
add_v(i * j, 1)
NEXT
k2 += i + 1
k3 += i - 1
WEND
NEXT
FOR i = 0 TO nMax - 1
IF get_v(i) = s THEN
Tatami = i
EXIT FUNCTION
END IF
NEXT
END FUNCTION
s = VAL(COMMAND())
PRINT FORMAT("The smallest room size s for which T(s) = %d is %d\n", s, Tatami(s))
```

**interface.c** (TA extension module using my

**C BASIC** preprocessor include)

Code: Select all

```
/* Tatami Array Get / Set / Add
UXLIBS: -lm
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../../basext.h"
#include "cbasic.h"
DIM AS unsigned char v[100000000];
/****************************
Extension Module Functions
****************************/
besVERSION_NEGOTIATE
RETURN_FUNCTION((int)INTERFACE_VERSION);
besEND
besSUB_START
DIM AS long PTR p;
besMODULEPOINTER = besALLOC(sizeof(long));
IF (besMODULEPOINTER EQ NULL) THEN_DO RETURN_FUNCTION(0);
p = (long PTR)besMODULEPOINTER;
RETURN_FUNCTION(0);
besEND
besSUB_FINISH
DIM AS long PTR p;
p = (long PTR)besMODULEPOINTER;
IF (p EQ NULL) THEN_DO RETURN_FUNCTION(0);
RETURN_FUNCTION(0);
besEND
/************************
Tatami array functions
************************/
besFUNCTION(get_v)
DIM AS long idx;
DIM AS long value;
besARGUMENTS("i")
AT idx
besARGEND
value = v[idx];
besRETURN_LONG(value);
besEND
besFUNCTION(set_v)
DIM AS long idx;
DIM AS long value;
besARGUMENTS("ii")
AT idx, AT value
besARGEND
v[idx] = value;
besRETURNVALUE = NULL;
besEND
besFUNCTION(add_v)
DIM AS long idx;
DIM AS long value;
besARGUMENTS("ii")
AT idx, AT value
besARGEND
v[idx] += value;
besRETURNVALUE = NULL;
besEND
```

Wow!

I was expecting it to take much longer at 200.

Code: Select all

```
pi@RPi4B:~/sbrt/examples $ time scriba Tatami_ext.sb 200
The smallest room size s for which T(s) = 200 is 85765680
real 17m7.563s
user 17m6.692s
sys 0m0.432s
pi@RPi4B:~/sbrt/examples $
```

Just a reminder that ScriptBasic completed 100 in

**53 seconds** using its native array feature.