jahboater
Posts: 5035
Joined: Wed Feb 04, 2015 6:38 pm

Re: Liberation through Computer Literacy

Mon Nov 11, 2019 10:08 pm

Heater wrote:
Mon Nov 11, 2019 9:16 pm
John_Spikowski,
Strictly speaking there are no associative arrays in ScriptBasic...
Who are you quoting there?

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?
Didn't someone say earlier that they are linked lists :(

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Liberation through Computer Literacy

Mon Nov 11, 2019 10:09 pm

Who are you quoting there?
ScriptBasic User Guide.

Heater
Posts: 14443
Joined: Tue Jul 17, 2012 3:02 pm

Re: Liberation through Computer Literacy

Mon Nov 11, 2019 10:25 pm

So what is it?

Scanning a linked list to find the value that has a key "idx" where "idx" is what we might normally think is an array index: someArray[idx].

Or some kind of hash table, where "idx" is used to create a hash which quickly finds the element we want? Which I doubt as it is so slow.

Or something else?

Whatever it is, linked list, hash table, binary tree, etc, it can be seen as an associative key-value store rather than a regular array.

Hmm actually, thinking about that "associative array" thing. Literally it means ScriptBasic doe not have arrays as the linearly addresses areas of memory we know and love. That associate an index directly to a memory address. Rather it has some other data structure as an associative, key - value, store. That just looks like an array syntactically.

Which is what Javascript does as it happens. Except JS will optimize things like someArray[idx] to actual fast linear arrays when "idx" is always an integer.
Memory in C++ is a leaky abstraction .

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Liberation through Computer Literacy

Mon Nov 11, 2019 10:26 pm

If I can get the HASH extension module to work, I wonder if I can use it instead of ScriptBasic Arrays? Would it be faster than the TA extension module I wrote?

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Liberation through Computer Literacy

Mon Nov 11, 2019 11:06 pm

I added do_v to the TA extension module to handle the inner FOR/NEXT that updated the v array.

interface.c

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   
tatamix.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"
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))
Output (Laptop)

Code: Select all

[email protected]:~/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
[email protected]:~/sbrt/examples$ 

ejolson
Posts: 4260
Joined: Tue Mar 18, 2014 11:47 am

Re: Liberation through Computer Literacy

Mon Nov 11, 2019 11:59 pm

John_Spikowski wrote:
Mon Nov 11, 2019 11:06 pm
I added do_v to the TA extension module to handle the inner FOR/NEXT that updated the v array.

interface.c

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   
tatamix.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"
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))
Output (Laptop)

Code: Select all

[email protected]:~/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
[email protected]:~/sbrt/examples$ 
Am I right that your code now runs more than twice as fast?

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Liberation through Computer Literacy

Tue Nov 12, 2019 12:05 am

I added find_s to the TA extension module which is the find s FOR/NEXT in the v array.

interface.c

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   
tatamix.sb

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))
Output (laptop)

Code: Select all

[email protected]:~/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
[email protected]:~/sbrt/examples$ 
Output (RPi 4B 4GB)

Code: Select all

[email protected]:~/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
[email protected]:~/sbrt/examples $ 
:D

ejolson
Posts: 4260
Joined: Tue Mar 18, 2014 11:47 am

Re: Liberation through Computer Literacy

Tue Nov 12, 2019 3:38 am

Heater wrote:
Mon Nov 11, 2019 9:07 pm
We can pin point the start of the Digital Dark Ages to February 3rd, 1976.
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!

I'm not sure Bill Gates was the one who convinced the judges of the US justice system that computer software was a literary art which could be copyrighted as opposed to a mathematical algorithm which couldn't. At the time there were many of either persuasion. Given how the division of government powers among three branches is supposed to work, as I see it, the difficulty was the legislators did not perform a proper game-theoretic analysis to determine whether the resulting Nash equilibrium would lead to computer literacy and economic growth or the opposite.

Since the laws which define intellectual property are made up by people in the first place, then it only makes sense for those laws to be made up in a way that benefits people.

As I typed the above sentence, the dog developer--looking a bit sick from eating so many dog treats--suddenly barked, don't forget IBM. The friends of those same judges had just won an antitrust lawsuit which declared it was an unfair practice to develop and provide free software with IBM computers. My friend Bill was a lucky businessman who likes dogs, not an evil force that caused the collapse of the golden age. Before I could ask how Fido became friends with the billionaire, the dog developer turned over and went to sleep snoring loudly.
Last edited by ejolson on Tue Nov 12, 2019 6:14 am, edited 2 times in total.

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Liberation through Computer Literacy

Tue Nov 12, 2019 4:55 am

Maybe a good group project would be to expand on C BASIC to fill out the syntax?

Here is the interface.c TA extension module in native C.

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;}
Last edited by John_Spikowski on Tue Nov 12, 2019 7:30 am, edited 4 times in total.

jalih
Posts: 97
Joined: Mon Apr 15, 2019 3:54 pm

Re: Liberation through Computer Literacy

Tue Nov 12, 2019 5:55 am

John_Spikowski wrote:
Tue Nov 12, 2019 12:05 am
I added find_s to the TA extension module...
You should update your tatami code to jcyr's fixed version. Your current version got buffer overrun by one when writing to array...

Change all:

Code: Select all

k4 = INT(nMAX/i)
To:

Code: Select all

k4 = INT((nMAX-1)/i)

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Liberation through Computer Literacy

Tue Nov 12, 2019 6:05 am

Nice catch.

Thanks!

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Liberation through Computer Literacy

Tue Nov 12, 2019 6:26 am

ScriptBasic Tatami Update

interface.c

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  
tatamix.sb

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))
Output (Lenovo Laptop)

Code: Select all

[email protected]:~/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
[email protected]:~/sbrt/examples$ 
Output (RPi 3B 4GB)

Code: Select all

[email protected]:~/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
[email protected]:~/sbrt/examples $ 

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Liberation through Computer Literacy

Tue Nov 12, 2019 6:50 am

@jcyr's latest C code with his best optimization flags on my RPI 4B 4GB.

Code: Select all

[email protected]:~/sbrt/examples $ gcc -O3 -march=native -mtune=cortex-a53 -o tatami tatami.c
[email protected]:~/sbrt/examples $ time ./tatami 200
T(85765680) = 200

real	0m10.455s
user	0m10.110s
sys	0m0.340s
[email protected]:~/sbrt/examples $ 

ejolson
Posts: 4260
Joined: Tue Mar 18, 2014 11:47 am

Re: Liberation through Computer Literacy

Tue Nov 12, 2019 4:33 pm

Heater wrote:
Mon Nov 11, 2019 9:07 pm
They do all they need with appliances that use services in the "cloud".
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.

With a modern decrease in the reliability of the electrical grid along with the greater role played by outward facing network resources for non-IT-related businesses, using someone else's computer could be a good idea. An alternative would be to locate your own machines in someone else's datacenter with guarantees on power, AC and network availability. For a technology-based company with significant inward-facing computational needs and expertise, colocation and cloud are less likely good ideas. For a person, canine or feline who values individual liberty and freedom, the only sensible choice is a fully-owned personal computer. These days such a computer can be obtained at the price of a dinner for two, if not for free attached to a magazine cover.

There are notable computer literacy projects such as Scratch3, NCLab and others that leverage the cloud. I'm not affiliated with any such project but can see the potential. Unfortunately, cloud resources are not available to all schools and individuals. Moreover, there are always terms and conditions when sharing time on someone else's computer that deny a person the freedom to run any algorithm that person is able to think up. For example, if computing T(s) for large values of s really were cryptographic research, then it would not be possible to solve the tatami challenge using cloud resources hosted in certain countries.

Whether hive-mind efficiency is more important than liberation through computer literacy is a topic that may be interesting to discuss, or not.
Last edited by ejolson on Tue Nov 12, 2019 5:05 pm, edited 2 times in total.

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Liberation through Computer Literacy

Tue Nov 12, 2019 4:43 pm

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.
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.

Heater
Posts: 14443
Joined: Tue Jul 17, 2012 3:02 pm

Re: Liberation through Computer Literacy

Tue Nov 12, 2019 5:37 pm

ejolson,
In my opinion the cloud is nothing new.
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.

What I was getting at with my comment is that the overwhelming majority of computer users don't use their devices as computers. They use them as appliances to watch video, listen to music, chat to each other, play ganes, etc, etc. There is no computer literacy going on there.
With a modern decrease in the reliability of the electrical grid...
Only in third world countries that can't afford or can't organize themselves well enough to keep their infrastructure in good shape.

But yes, it's neat to be able to have your data and services spread over different data centers, with different companies, in different countries. The ultimate back up! Where would I be without github, bitbucket and the like?

On the down side, every week we read of some major data leak from some major service. Millions of records or personal data just hanging out on the net for anyone to grab. Be it some government service, medical records, genetic data, etc, etc. We can assume that once the data hits the cloud they might as well have posted it a public github repo for all the security there is. I find it horrifying.

On the other down side, pretty much any data about you that any organization gathers is traded among all kind of shadowy figures we know nothing about. Even more horrifying.

We never had such a dangerous cloud before...

My hope is that with the computer literacy that could become wide spread thanks to efforts like the Pi the next generation will have some faint idea about what is going on and how to fight back.
Memory in C++ is a leaky abstraction .

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Liberation through Computer Literacy

Tue Nov 12, 2019 6:04 pm

The cloud is a tornado that spins buzz words and fantasies.

Heater
Posts: 14443
Joined: Tue Jul 17, 2012 3:02 pm

Re: Liberation through Computer Literacy

Tue Nov 12, 2019 6:26 pm

When new technologies come along they are always surrounded by hype, buzz words and fantasies. As spun my those who want to make money out of it.

The dangers of every shady organization from governments to law enforcement to every other commercial/financial entity having access to every detail of everything you think, say and do are real enough.
Memory in C++ is a leaky abstraction .

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Liberation through Computer Literacy

Tue Nov 12, 2019 6:49 pm

The cloud works because there is no commitment. You can be anything you want to be as long as your CC doesn't decline.

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Liberation through Computer Literacy

Tue Nov 12, 2019 7:50 pm

True.bits of the story which is are a byte in the ass.

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Liberation through Computer Literacy

Tue Nov 12, 2019 8:54 pm

Back on topic:

Am I correct by saying the following languages have Tatami 200 submissions?

C
Perl
ScriptBasic
8th
Last edited by John_Spikowski on Tue Nov 12, 2019 9:19 pm, edited 1 time in total.

ejolson
Posts: 4260
Joined: Tue Mar 18, 2014 11:47 am

Re: Liberation through Computer Literacy

Tue Nov 12, 2019 8:58 pm

John_Spikowski wrote:
Tue Nov 12, 2019 8:54 pm
Back on topic:

Am I correct by saying the following languages have Tatami submissions?

C
Perl
ScriptBasic
8th
I also wrote a solution in Visual Basic some time ago and later one in Commodore Basic. There were also Fortran and PL/I solutions posted.

Heater
Posts: 14443
Joined: Tue Jul 17, 2012 3:02 pm

Re: Liberation through Computer Literacy

Tue Nov 12, 2019 9:08 pm

Rust.
Memory in C++ is a leaky abstraction .

jalih
Posts: 97
Joined: Mon Apr 15, 2019 3:54 pm

Re: Liberation through Computer Literacy

Tue Nov 12, 2019 9:30 pm

Here are updated Tatami codes for PL/1, Fortran and 8th. I use ancient PL/1 compiler for Windows but it still produces the fastest code of the bunch. PL/1 code takes about 3 seconds to run, Fortran code doubles that time and runs in about 6.5 seconds. Execution time for 8th in this task is poor and takes about 9 minutes!

8th:

Code: Select all

\ Based on Tatami.c written by jcyr on Raspberrypi.org forums

100000000 constant N-MAX
N-MAX n:sqrt n:int constant N-MAX-SQRT

N-MAX b:new true b:writable constant v

: swap+-  \ a b c f -- a (a+b+1) (a+c-1)
  drop
  swap 2 pick n:+ n:1+
  swap 2 pick n:+ n:1- ;

: l4  \ i k2 k3 k4 -- i k2 k3 k4
  \ i k2 k3 k4 j
  4 pick over n:*
  v over b:@ n:1+ rot swap b:! 2drop ;

: l3
  \ i
  dup 3 n:+             \ i k2=i+3
  over dup n:+ 4 n:-    \ i k2 k3=i+i-4
  repeat  \ i k2 k3
    2dup n:> not 2over n:* N-MAX n:< and if
      N-MAX n:1- 3 pick n:/ n:int     \  i k2 k3 k4
      2dup n:< if
        drop dup
      then
      ' l4 3 pick 2 pick loop   \ i k2 k3 k4
      swap+-
    else
      break
    then
  again
  2drop drop
  2 step ;

: l2  \ i k2 k3 k4 -- i k2 k3 k4
  \ i k2 k3 k4 j
  4 pick over n:*
  v over b:@ n:1+ rot swap b:! 2drop
  2 step ;

: l1
  \ i
  dup 3 n:+             \ i k2=i+3
  over dup n:+ 4 n:-    \ i k2 k3=i+i-4
  repeat  \ i k2 k3
    2dup n:> not 2over n:* N-MAX n:< and if
      N-MAX n:1- 3 pick n:/ n:int     \  i k2 k3 k4
      2dup n:< if
        drop dup
      then
      ' l2 3 pick 2 pick loop   \ i k2 k3 k4
      swap+-
    else
      break
    then
  again
  2drop drop
  2 step ;

: tatami  \ n -- s
  ' l1 7 N-MAX-SQRT n:1- loop
  ' l3 8 N-MAX-SQRT n:1- loop
  v swap 1 a:close b:new b:search nip ;

: app:main
  200 tatami null? not if
    "The smallest room size s for which T(s) = 200 is %d.\n" s:strfmt .
  else
    drop "Not found\n" .
  then
  bye ;
  
PL/1:

Code: Select all


*PROCESS MARGINS(1,180) LIBS(SINGLE,STATIC);
*PROCESS OPTIMIZE(3) DFT(REORDER);
*PROCESS PP(MACRO);


/* Based on Tatami.c written by jcyr on Raspberrypi.org forums */
 tatami: proc options(main);
   dcl N_MAX fixed bin(31) value(100000000);
   dcl N_MAX_SQRT fixed bin(31) value(sqrt(N_MAX));

   dcl v(0:N_MAX-1) fixed bin(8) unsigned ctl;

   dcl (i, j, k2, k3, k4) fixed bin(31);

   allocate v(0:N_MAX-1);

   do i = 7 to N_MAX_SQRT - 1 by 2;
     k2 = i + 3;
     k3 = i + i - 4;
     do while((k2 <= k3) & ((i * k2) < N_MAX));
       k4 = (N_MAX - 1) / i;
       if k3 < k4 then k4 = k3;
       do j = k2 to k4 by 2;
         v(i*j)+=1;
       end;
       k2 += i + 1;
       k3 += i - 1;
     end;
   end;

   do i = 8 to N_MAX_SQRT - 1 by 2;
     k2 = i + 3;
     k3 = i + i - 4;
     do while((k2 <= k3) & ((i * k2) < N_MAX));
       k4 = (N_MAX - 1) / i;
       if k3 < k4 then k4 = k3;
       do j = k2 to k4;
         v(i*j)+=1;
       end;
       k2 += i + 1;
       k3 += i - 1;
     end;
   end;

   do i = 0 upthru N_MAX - 1;
     if v(i) = 200 then leave;
   end;

   put skip list('The smallest room size s for which T(s) = 200 is:', i);

   free v;
 end tatami;
Fortran:

Code: Select all

! Based on Tatami.c written by jcyr on Raspberrypi.org forums
program tatami
  implicit none

  integer, parameter :: N_MAX = 100000000
  integer, parameter :: N_MAX_SQRT = sqrt(real(N_MAX))

  integer :: ierror
  integer, dimension(:), allocatable :: v 

  integer :: i, j, k2, k3, k4

  allocate(v(0:N_MAX-1), stat=ierror)
  if (ierror /= 0) then
    print *, 'Could not allocate vector'
    stop
  end if
  
  do i = 7, N_MAX_SQRT - 1, 2
    k2 = i + 3
    k3 = i + i - 4
    do while((k2 <= k3) .and. ((i * k2) < N_MAX))
      k4 = (N_MAX - 1) / i
      if (k3 < k4) k4 = k3
      do j = k2, k4, 2
        v(i*j) = v(i*j) + 1
      end do
      k2 = k2 + i + 1
      k3 = k3 + i - 1
    end do    
  end do

  do i = 8, N_MAX_SQRT - 1, 2
    k2 = i + 3
    k3 = i + i - 4
    do while((k2 <= k3) .and. ((i * k2) < N_MAX))
      k4 = (N_MAX - 1) / i
      if (k3 < k4) k4 = k3
      do j = k2, k4, 1
        v(i*j) = v(i*j) + 1
      end do
      k2 = k2 + i + 1
      k3 = k3 + i - 1
    end do    
  end do
  
  do i = 0, N_MAX - 1, 1
    if (v(i) == 200) exit
  end do
    
  print *, 'The smallest room size s for which T(s) = 200 is:', i
  
  deallocate(v)  
end program tatami
Last edited by jalih on Wed Nov 13, 2019 4:56 pm, edited 1 time in total.

User avatar
John_Spikowski
Posts: 1614
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Liberation through Computer Literacy

Tue Nov 12, 2019 9:51 pm

I forgot about your VB6 version. I even converted it to ScriptBasic no less.

Is a Tatami 200 chart in the making?

A nice change ScriptBasic not being the retard language in the group.

Array Class
The future evolution of the TA extension module.

Return to “General programming discussion”