Puzzling question.Does tiling the floors of rectangular rooms with tatami carpets help in any way?
Puzzling question.Does tiling the floors of rectangular rooms with tatami carpets help in any way?
We can pin point the start of the Digital Dark Ages to February 3rd, 1976.Before placing blame for the ensuing digital dark ages on Basic itself...
Yeah, that.Maybe the desire of many to strike it rich by selling proprietary software was the real reason behind the end of the golden age. Linus could not have written an operating system before the last hacker at MIT created gcc.
I'm not so optimistic:Although the foundations for the second age of personal computing appear quite solid...
Who are you quoting there?Strictly speaking there are no associative arrays in ScriptBasic...
Didn't someone say earlier that they are linked listsHeater wrote: ↑Mon Nov 11, 2019 9:16 pmJohn_Spikowski,Who are you quoting there?Strictly speaking there are no associative arrays in ScriptBasic...
Now you have to explain something because the message I always got before is that ScriptBasic arrays are not any kind of normal array in linearly addressable memory. But rather associative arrays and hence the appalling performance when used for regular array operations.
What actually is a ScriptBasic array?
ScriptBasic User Guide.Who are you quoting there?
Code: Select all
besFUNCTION(do_v)
DIM AS long start;
DIM AS long end;
DIM AS long value;
DIM AS long idx;
besARGUMENTS("iii")
AT start, AT end, AT value
besARGEND
DEF_FOR (idx = start TO idx <= end STEP INCR idx + 2)
BEGIN_FOR
v[value * idx] += 1;
NEXT
besRETURNVALUE = NULL;
besEND
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"
DECLARE SUB do_v ALIAS "do_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
do_v(k2, k4, i)
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
do_v(k2, k4, i)
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))
Code: Select all
ubuntu@ubuntu:~/sbrt/examples$ time scriba tatamix.sb 200
The smallest room size s for which T(s) = 200 is 85765680
real 1m50.241s
user 1m50.176s
sys 0m0.060s
ubuntu@ubuntu:~/sbrt/examples$
Am I right that your code now runs more than twice as fast?John_Spikowski wrote: ↑Mon Nov 11, 2019 11:06 pmI added do_v to the TA extension module to handle the inner FOR/NEXT that updated the v array.
interface.ctatamix.sbCode: Select all
besFUNCTION(do_v) DIM AS long start; DIM AS long end; DIM AS long value; DIM AS long idx; besARGUMENTS("iii") AT start, AT end, AT value besARGEND DEF_FOR (idx = start TO idx <= end STEP INCR idx + 2) BEGIN_FOR v[value * idx] += 1; NEXT besRETURNVALUE = NULL; besEND
Output (Laptop)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" DECLARE SUB do_v ALIAS "do_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 do_v(k2, k4, i) 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 do_v(k2, k4, i) 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))
Code: Select all
ubuntu@ubuntu:~/sbrt/examples$ time scriba tatamix.sb 200 The smallest room size s for which T(s) = 200 is 85765680 real 1m50.241s user 1m50.176s sys 0m0.060s ubuntu@ubuntu:~/sbrt/examples$
Code: Select all
besFUNCTION(find_s)
DIM AS long s;
DIM AS long idx;
besARGUMENTS("i")
AT s
besARGEND
DEF_FOR (idx = 0 TO idx <= 99999999 STEP INCR idx)
BEGIN_FOR
IF (v[idx] == s) THEN_DO besRETURN_LONG(idx);
NEXT
besEND
besFUNCTION(do_v)
DIM AS long start;
DIM AS long end;
DIM AS long value;
DIM AS long idx;
besARGUMENTS("iii")
AT start, AT end, AT value
besARGEND
DEF_FOR (idx = start TO idx <= end STEP INCR idx + 2)
BEGIN_FOR
v[value * idx] += 1;
NEXT
besRETURNVALUE = NULL;
besEND
Code: Select all
' Tatamix.sb
DECLARE SUB do_v ALIAS "do_v" LIB "ta"
DECLARE SUB find_s ALIAS "find_s" 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
do_v(k2, k4, i)
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
do_v(k2, k4, i)
k2 += i + 1
k3 += i - 1
WEND
NEXT
Tatami = find_s(s)
END FUNCTION
s = VAL(COMMAND())
PRINT FORMAT("The smallest room size s for which T(s) = %d is %d\n", s, Tatami(s))
Code: Select all
ubuntu@ubuntu:~/sbrt/examples$ time scriba tatamix.sb 200
The smallest room size s for which T(s) = 200 is 85765680
real 0m5.894s
user 0m5.838s
sys 0m0.056s
ubuntu@ubuntu:~/sbrt/examples$
Code: Select all
pi@RPi4B:~/sbrt/examples $ time scriba tatamix.sb 200
The smallest room size s for which T(s) = 200 is 85765680
real 0m26.649s
user 0m26.327s
sys 0m0.311s
pi@RPi4B:~/sbrt/examples $
Just think how the history of personal computing would have been changed if Microsoft had really delivered a version of APL for those early 8-bit processors!
Code: Select all
unsigned char v[100000000];
int versmodu(int Version, char *pszVariation, void **ppModuleInternal){
return((int)11);
return 0;}
int bootmodu(pSupportTable pSt, void **ppModuleInternal, pFixSizeMemoryObject pParameters, pFixSizeMemoryObject *pReturnValue){ pExecuteObject pEo=
((void *)0);
long * p;
(*ppModuleInternal) = (pSt->Alloc((sizeof(long)),pSt->pEo->pMemorySegment));
if ((*ppModuleInternal) == ((void *)0)
) return(0);
p = (long *)(*ppModuleInternal);
return(0);
return 0;}
int finimodu(pSupportTable pSt, void **ppModuleInternal, pFixSizeMemoryObject pParameters, pFixSizeMemoryObject *pReturnValue){ pExecuteObject pEo=
((void *)0);
long * p;
p = (long *)(*ppModuleInternal);
if (p == ((void *)0)
) return(0);
return(0);
return 0;}
int do_v(pSupportTable pSt, void **ppModuleInternal, pFixSizeMemoryObject pParameters, pFixSizeMemoryObject *pReturnValue){ pExecuteObject pEo=
((void *)0);
long start;
long end;
long value;
long idx;
int iError; iError = pSt->basext_GetArgsF(pSt,pParameters,("iii"),
& start, & end, & value
); if( iError )return iError;
for (idx = start ; idx <= end ; ++ idx + 2)
{
v[value * idx] += 1;
}
(*pReturnValue) = ((void *)0);
return 0;}
int find_s(pSupportTable pSt, void **ppModuleInternal, pFixSizeMemoryObject pParameters, pFixSizeMemoryObject *pReturnValue){ pExecuteObject pEo=
((void *)0);
long s;
long idx;
int iError; iError = pSt->basext_GetArgsF(pSt,pParameters,("i"),
& s
); if( iError )return iError;
for (idx = 0 ; idx <= 99999999 ; ++ idx)
{
if (v[idx] == s) {
do{(*pReturnValue) = (pSt->NewMortalLong(pSt->pEo->pMo,pSt->pEo->pGlobalMortalList)); if( (*pReturnValue) ==
((void *)0))return 1; (((*pReturnValue))->Value.lValue) = (idx); return 0; }while(0);;
break;
}
}
return 0;}
You should update your tatami code to jcyr's fixed version. Your current version got buffer overrun by one when writing to array...
Code: Select all
k4 = INT(nMAX/i)
Code: Select all
k4 = INT((nMAX-1)/i)
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(do_v)
DIM AS long start;
DIM AS long end;
DIM AS long value;
DIM AS long idx;
besARGUMENTS("iii")
AT start, AT end, AT value
besARGEND
DEF_FOR (idx = start TO idx <= end STEP INCR idx + 2)
BEGIN_FOR
v[value * idx] += 1;
NEXT
besRETURNVALUE = NULL;
besEND
besFUNCTION(find_s)
DIM AS long s;
DIM AS long idx;
besARGUMENTS("i")
AT s
besARGEND
DEF_FOR (idx = 0 TO idx <= 99999999 STEP INCR idx)
BEGIN_FOR
IF (v[idx] == s) THEN
besRETURN_LONG(idx);
EXIT_FOR
END_IF
NEXT
besEND
Code: Select all
' Tatamix.sb
DECLARE SUB do_v ALIAS "do_v" LIB "ta"
DECLARE SUB find_s ALIAS "find_s" 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 -1) / i)
IF k3 < k4 THEN
k4 = k3
END IF
do_v(k2, k4, i)
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 -1) / i)
IF k3 < k4 THEN
k4 = k3
END IF
do_v(k2, k4, i)
k2 += i + 1
k3 += i - 1
WEND
NEXT
Tatami = find_s(s)
END FUNCTION
s = VAL(COMMAND())
PRINT FORMAT("The smallest room size s for which T(s) = %d is %d\n", s, Tatami(s))
Code: Select all
ubuntu@ubuntu:~/sbrt/examples$ time scriba tatamix.sb 200
The smallest room size s for which T(s) = 200 is 85765680
real 0m5.931s
user 0m5.894s
sys 0m0.037s
ubuntu@ubuntu:~/sbrt/examples$
Code: Select all
pi@RPi4B:~/sbrt/examples $ time scriba tatamix.sb 200
The smallest room size s for which T(s) = 200 is 85765680
real 0m26.700s
user 0m26.373s
sys 0m0.321s
pi@RPi4B:~/sbrt/examples $
Code: Select all
pi@RPi4B:~/sbrt/examples $ gcc -O3 -march=native -mtune=cortex-a53 -o tatami tatami.c
pi@RPi4B:~/sbrt/examples $ time ./tatami 200
T(85765680) = 200
real 0m10.455s
user 0m10.110s
sys 0m0.340s
pi@RPi4B:~/sbrt/examples $
In my opinion the cloud is nothing new. Cloud services such as CompuServe were very popular at the dawn of the golden age of personal computing and widely deployed by businesses outsourcing their data centers. As with present timesharing services--Amazon, Azure and the IBM Cloud--using someone else's computer has advantages as well as drawbacks.
My online life started with Compuserve using a 1200 baud modem and a Osborne 'portable' computer. My bad eyesight began on that 4 inch screen.Cloud services such as CompuServe were very popular at the dawn of the golden age of personal computing and widely deployed by businesses outsourcing their data centers.
There is nothing new under the sun. Looked at that way I can claim to have used "cloud" computing in 1972. At our tech college where we communed with some mainframe in a different city using a teletype connected via acoustic coupler and modem. The glorious old times when we were introduced to programming with BASIC. Still, we had local storage on paper tape and luckily they insisted we become fluent in assembler as well.In my opinion the cloud is nothing new.
Only in third world countries that can't afford or can't organize themselves well enough to keep their infrastructure in good shape.With a modern decrease in the reliability of the electrical grid...
And yet I find very few that are mathematically liberated!