User avatar
jcyr
Posts: 427
Joined: Sun Apr 23, 2017 1:31 pm
Location: Atlanta

Re: Liberation through Computer Literacy

Thu Nov 07, 2019 8:31 pm

ejolson wrote:
Thu Nov 07, 2019 8:18 pm
For 32-bit divisions the correct march and mtune options are all that's needed.
And to optimize for the BCM2711 those would be?
It's um...uh...well it's kinda like...and it's got a bit of...

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

Re: Liberation through Computer Literacy

Thu Nov 07, 2019 8:40 pm

John_Spikowski,
We should have a challenge on how to avoid ScriptBasic at any cost.
I don't know about "how" but "why" does not seem to be much of a challenge.

Joking, only joking, honest :)
Memory in C++ is a leaky abstraction .

User avatar
jcyr
Posts: 427
Joined: Sun Apr 23, 2017 1:31 pm
Location: Atlanta

Re: Liberation through Computer Literacy

Thu Nov 07, 2019 8:53 pm

ejolson wrote:
Thu Nov 07, 2019 8:18 pm
For 32-bit divisions the correct march and mtune options are all that's needed.
Ah! -march=native uses UDIV, but does make a great deal difference.

Code: Select all

[email protected]:~/tatami $ gcc -O3 tatami.c
[email protected]:~/tatami $ time ./a.out 
The smallest room size s for which T(s) = 200 is 85765680

real    0m9.972s
user    0m9.638s
sys     0m0.331s
[email protected]:~/tatami $ gcc -O3 -march=native tatami.c
[email protected]:~/tatami $ time ./a.out                  
The smallest room size s for which T(s) = 200 is 85765680

real    0m9.938s
user    0m9.587s
sys     0m0.351s
[email protected]:~/tatami $
It's um...uh...well it's kinda like...and it's got a bit of...

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

Re: Liberation through Computer Literacy

Thu Nov 07, 2019 9:27 pm

Heater wrote:
Thu Nov 07, 2019 8:40 pm
Joking, only joking, honest :)
Speaking of avoiding things, is it possible to solve the Tatami challenge in Rust while avoiding the use of mut variables? The vice-president of testing and code review, who claims an official pedigree, wants to know.

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

Re: Liberation through Computer Literacy

Thu Nov 07, 2019 10:03 pm

I'm not the right person to ask. I'm a Rust newbie and I have no idea what that tatami code is doing or why anyway!

However I'm told that whatever can be computed can be computed with Church's Lambda Calculus and hence Function Programming with no mutables or side effects.

Also there is library support for such Functional Programming in Rust which presumably removes the need for any mutables.

So tentatively my answer is "yes".

Personally I like to have as many mutts, sorry mut's, in my code as possible. As Turing intended.
Memory in C++ is a leaky abstraction .

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

Re: Liberation through Computer Literacy

Thu Nov 07, 2019 10:07 pm

Heater wrote:
Thu Nov 07, 2019 8:40 pm
John_Spikowski,
We should have a challenge on how to avoid ScriptBasic at any cost.
I don't know about "how" but "why" does not seem to be much of a challenge.

Joking, only joking, honest :)
You're lucky you're talking to me and not Peter. He would have had your scalp hanging from his belt by now.

Just kidding.

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

Re: Liberation through Computer Literacy

Thu Nov 07, 2019 10:20 pm

I'm all for a discussion with Peter, or anyone about any programming language. I'm sure they all have perfectly sound reasons for being as they are.

Not so keen on the scalp hunters though :o
Memory in C++ is a leaky abstraction .

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

Re: Liberation through Computer Literacy

Fri Nov 08, 2019 1:46 am

jalih wrote:
Thu Nov 07, 2019 12:22 pm
Heater wrote:
Thu Nov 07, 2019 8:33 am
From everything I ever heard about it I got the impression it was some mythic beast of software development that was slain before it could get off the ground.
It truly is a mythic beast with a lot of interesting ideas. I personally applaud the choice of PL/I as the system programming language.

You can run the most current release using simulator and try it yourself!
In addition to PL/I it would appear that Multics includes Basic and C.
  • Thanks to two good programmers and one mathematician, everyone in the golden age had a copy of the language used by the Dartmouth timesharing system to run on their personal computers.
  • Thanks to another good programmer assisted by the multitude, everyone in the second age has a copy of the Unix operating system originally designed for minicomputers to run on their personal computers.
  • Thanks to yet one more visionary and many others, everyone on this forum has a personal computer so inexpensive that it can be included for free with a magazine.
What I find amazing is that, in addition to most modern software, through hardware emulation that inexpensive single-board computer can run almost all software ever written. This lucky circumstance is due, in part, to the efforts of the many unnamed software engineers and hobbyists who carefully curated that historical software as well as the generosity of the authors. Thanks!

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

Re: Liberation through Computer Literacy

Fri Nov 08, 2019 3:02 am

ejolson wrote:
Fri Nov 08, 2019 1:46 am
jalih wrote:
Thu Nov 07, 2019 12:22 pm
Heater wrote:
Thu Nov 07, 2019 8:33 am
From everything I ever heard about it I got the impression it was some mythic beast of software development that was slain before it could get off the ground.
It truly is a mythic beast with a lot of interesting ideas. I personally applaud the choice of PL/I as the system programming language.

You can run the most current release using simulator and try it yourself!
In addition to PL/I it would appear that Multics includes Basic and C.
And BCPL !!
And a GCOS simulator.
Cool ...

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

Re: Liberation through Computer Literacy

Fri Nov 08, 2019 4:52 am

I tried to convert @jcyr's C tatami.c to ScriptBasic but I'm getting a zero returned for tatami(s). It seems to taking about the right time if it was working correctly. Another set of eyes would be great.

Code: Select all

' Tatami.sb

nMax = 6700000
nMaxSqrt = SQR(nMax)

SPLITA STRING(nMax, "0") BY "" TO v

FUNCTION Tatami(s)
  FOR i = 7 TO nMaxSqrt STEP 2
    k2 = i + 3
    IF (i * k2) < nMax THEN
      k3 = i + i - 4
      k = 1
      WHILE k2 <= k3
        k4 = nMax / i
        IF k3 < k4 THEN
          k4 = k3
        END IF
        FOR j = k2 TO k4 STEP 2
          v[i * j] += v[i * j]
        NEXT
        k2 += i + 1
        k3 += i - 1
        k += 1
      WEND
    END IF
  NEXT
  FOR i = 8 TO nMaxSqrt STEP 2
    k2 = 1 + 3
    IF (i * k2) < nMax THEN
      k3 = i + i - 4
      k = 1
      WHILE k2 <= k3
        k4 = nMax / i
        IF k3 < k4 THEN
          k4 = k3
        END IF
        FOR j = k2 TO k4
          v[i * j] += v[i * j]
        NEXT
        k2 += i + 1
        k3 += i - 1
        k += 1
      WEND
    END IF
  NEXT
  FOR i = 0 TO nMax
    IF v[i] = s THEN
      Tatami = i
      EXIT FUNCTION
    END IF
  NEXT
END FUNCTION

s = 100
PRINT FORMAT("The smallest room size s for which T(s) = %d is %d\n", s, Tatami(s))
[email protected]:~/sb/tatami$ scriba Tatami.sb
The smallest room size s for which T(s) = 100 is 0
[email protected]:~/sb/tatami$

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

Re: Liberation through Computer Literacy

Fri Nov 08, 2019 5:34 am

I changed the code to v[i * j] += 1 but I'm still not getting the correct answer.

Code: Select all

' Tatami.sb

nMax = 6700000
nMaxSqrt = SQR(nMax)

SPLITA STRING(nMax, "0") BY "" TO v

FUNCTION Tatami(s)
  FOR i = 7 TO nMaxSqrt STEP 2
    k2 = i + 3
    IF (i * k2) < nMax THEN
      k3 = i + i - 4
      k = 1
      WHILE k2 <= k3
        k4 = nMax / i
        IF k3 < k4 THEN
          k4 = k3
        END IF
        FOR j = k2 TO k4 STEP 2
          v[i * j] += 1
        NEXT
        k2 += i + 1
        k3 += i - 1
        k += 1
      WEND
    END IF
  NEXT
  FOR i = 8 TO nMaxSqrt STEP 2
    k2 = 1 + 3
    IF (i * k2) < nMax THEN
      k3 = i + i - 4
      k = 1
      WHILE k2 <= k3
        k4 = nMax / i
        IF k3 < k4 THEN
          k4 = k3
        END IF
        FOR j = k2 TO k4
          v[i * j] += 1
        NEXT
        k2 += i + 1
        k3 += i - 1
        k += 1
      WEND
    END IF
  NEXT
  FOR i = 0 TO nMax
    IF v[i] = s THEN
      Tatami = i
      EXIT FUNCTION
    END IF
  NEXT
END FUNCTION

s = 100
PRINT FORMAT("The smallest room size s for which T(s) = %d is %d\n", s, Tatami(s))
Output

Code: Select all

[email protected]:~/sb/tatami$ scriba Tatami.sb
The smallest room size s for which T(s) = 100 is 240240
[email protected]:~/sb/tatami$ 

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

Re: Liberation through Computer Literacy

Fri Nov 08, 2019 11:14 am

John_Spikowski wrote:
Fri Nov 08, 2019 5:34 am

Code: Select all

[email protected]:~/sb/tatami$ scriba Tatami.sb
The smallest room size s for which T(s) = 100 is 240240
[email protected]:~/sb/tatami$ 
Is the correct answer for T(s)=100 produced by the original C code?

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

Re: Liberation through Computer Literacy

Fri Nov 08, 2019 1:45 pm

ejolson wrote:
Fri Nov 08, 2019 11:14 am
John_Spikowski wrote:
Fri Nov 08, 2019 5:34 am

Code: Select all

[email protected]:~/sb/tatami$ scriba Tatami.sb
The smallest room size s for which T(s) = 100 is 240240
[email protected]:~/sb/tatami$ 
Is the correct answer for T(s)=100 produced by the original C code?
The original C code says:

Code: Select all

The smallest room size s for which T(s) = 100 is 6683040

User avatar
jcyr
Posts: 427
Joined: Sun Apr 23, 2017 1:31 pm
Location: Atlanta

Re: Liberation through Computer Literacy

Fri Nov 08, 2019 1:55 pm

John_Spikowski wrote:
Fri Nov 08, 2019 5:34 am
I changed the code to v[i * j] += 1 but I'm still not getting the correct answer.

Code: Select all

' Tatami.sb

nMax = 6700000
nMaxSqrt = SQR(nMax)

SPLITA STRING(nMax, "0") BY "" TO v

FUNCTION Tatami(s)
  FOR i = 7 TO nMaxSqrt STEP 2
    k2 = i + 3
    IF (i * k2) < nMax THEN
      k3 = i + i - 4
      k = 1
      WHILE k2 <= k3
        k4 = nMax / i
        IF k3 < k4 THEN
          k4 = k3
        END IF
        FOR j = k2 TO k4 STEP 2
          v[i * j] += 1
        NEXT
        k2 += i + 1
        k3 += i - 1
        k += 1
      WEND
    END IF
  NEXT
  FOR i = 8 TO nMaxSqrt STEP 2
    k2 = 1 + 3
    IF (i * k2) < nMax THEN
      k3 = i + i - 4
      k = 1
      WHILE k2 <= k3
        k4 = nMax / i
        IF k3 < k4 THEN
          k4 = k3
        END IF
        FOR j = k2 TO k4
          v[i * j] += 1
        NEXT
        k2 += i + 1
        k3 += i - 1
        k += 1
      WEND
    END IF
  NEXT
  FOR i = 0 TO nMax
    IF v[i] = s THEN
      Tatami = i
      EXIT FUNCTION
    END IF
  NEXT
END FUNCTION

s = 100
PRINT FORMAT("The smallest room size s for which T(s) = %d is %d\n", s, Tatami(s))
Output

Code: Select all

[email protected]:~/sb/tatami$ scriba Tatami.sb
The smallest room size s for which T(s) = 100 is 240240
[email protected]:~/sb/tatami$ 
Variable k serves no purpose... I may have published a bad one along the way. Here's what I've settled on

Code: Select all

// Tatami.c

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define nMax 100000000
#define nMaxSqrt sqrt(nMax)

unsigned char v[nMax];

int Tatami(int s)
{
    for (int i = 7; i < nMaxSqrt; i += 2)
    {
        int k2 = i + 3;
        int k3 = i + i - 4;
        while ((k2 <= k3) && ((i * k2) < nMax))
        {
            int k4 = nMax / i;
            if (k3 < k4)
                k4 = k3;
            for (int j = k2; j <= k4; j += 2)
                ++v[i * j];
            k2 += i + 1;
            k3 += i - 1;
        }
    }
    for (int i = 8; i < nMaxSqrt; i += 2)
    {
        int k2 = i + 3;
        int k3 = i + i - 4;
        while ((k2 <= k3) && ((i * k2) < nMax))
        {
            int k4 = nMax / i;
            if (k3 < k4)
                k4 = k3;
            for (int j = k2; j <= k4; ++j)
                ++v[i * j];
            k2 += i + 1;
            k3 += i - 1;
        }
    }

    for (int i = 0; i < nMax; ++i)
        if (v[i] == s)
            return i;
}

int main(int ac, char *av[])
{
    int s = atoi(av[1]);
    printf(
        "The smallest room size s for which T(s) = %d is %d\n", s, Tatami(s));
}

Code: Select all

[email protected]:~/tatami $ ./tatami 100
The smallest room size s for which T(s) = 100 is 6683040
It's um...uh...well it's kinda like...and it's got a bit of...

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

Re: Liberation through Computer Literacy

Fri Nov 08, 2019 4:11 pm

Heater wrote:
Thu Nov 07, 2019 10:03 pm
I'm a Rust newbie and I have no idea what that tatami code is doing or why anyway!
It is likely I dismissed the idea of literate programming too quickly.
ejolson wrote:
Sun Nov 03, 2019 5:14 pm
As to the mystery surrounding what the program does and how it works, that's the topic of literate programming

https://en.m.wikipedia.org/wiki/Literate_programming

which, in my opinion, may not generally be as useful as yoga.
Although I've tried to avoid the tangle Professor Knuth created with his vision of literate programming, it's true that mathematical formulas and graphs are often useful in explaining how an algorithm works. For unifying the documentation with the source code, there are two obvious choices:
  • Including a machine understandable version of the source code scattered throughout the documentation, as practiced by Knuth.
  • Including a human understandable version of the documentation scattered throughout the source code, as practiced by others.
When I asked the vice-president of code review which is preferable, the former developer of FidoBasic said, neither is needed nor possible since the current curriculum is fully based on Scratch. I replied, because Scratch is a graphical programming language, it must be possible to include graphs as comments in the code. After that Fido looked at me with head turned sideways, then pawed at one ear. I suspect the dog developer is having trouble hearing after using the turbo encabulator to shred paper.

With Basic the line numbers can be used for cross reference while keeping the documentation and the source code separate. Could true liberation come from Basic or literate programming?
Last edited by ejolson on Fri Nov 08, 2019 4:50 pm, edited 1 time in total.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23878
Joined: Sat Jul 30, 2011 7:41 pm

Re: Liberation through Computer Literacy

Fri Nov 08, 2019 4:48 pm

John_Spikowski wrote:
Thu Nov 07, 2019 4:10 am
Gavinmc42 wrote:
Thu Nov 07, 2019 2:03 am
Is that farm simulator running on Pi's?
It's running on Windows 10. It's really taking advantage of what my new laptop has to offer.

AllBASIC Forum Thread
So, really, shouldn't be on this forum at all?

Please try to keep on topic. And since my commute home is currently taking twice as long due to tractors, spud and beet lifters, and filthy roads, less farm talk.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I think it’s wrong that only one company makes the game Monopoly.” – Steven Wright

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

Re: Liberation through Computer Literacy

Fri Nov 08, 2019 5:15 pm

I may have published a bad one along the way.
Are you saying the final C code never produced the correct answer nor was it tested?

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

Re: Liberation through Computer Literacy

Fri Nov 08, 2019 6:07 pm

Please try to keep on topic. And since my commute home is currently taking twice as long due to tractors, spud and beet lifters, and filthy roads, less farm talk.
Those tractors are what keeps the world fed. Do you complain when standing in line at McDonald's?

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

Re: Liberation through Computer Literacy

Fri Nov 08, 2019 6:12 pm

John_Spikowski wrote:
Fri Nov 08, 2019 5:15 pm
I may have published a bad one along the way.
Are you saying the final C code never produced the correct answer nor was it tested?
Thanks for checking.

Is it possible the post was edited after you downloaded the code?

I'll admit my factor.c program originally gave wrong answers--it's correct now. I suspect others make similar mistakes. Fortunately, it's possible to go back and fix things, even without a time machine. If you do so before anyone notices, then all is well. On the other hand, if the bug becomes the focus of further forum discussion, then it is likely better to leave the original post alone and create a new post with the updated code. In either case, to be safe when updating posted code, I think it's a good idea to add a comment of the form

Edit: Updated the code to fix bug.

I didn't follow my own advice for my factor.c program, but have now added a note to this post to inform anyone who might have previously downloaded the code that it has changed.

As before, one of the tasks is to verify all posted code. As this is a challenge rather than a contest, everyone who submits a working program wins. At the same time, all winners must be content with fame only, because there is no fortune due to lack of prizes. However, if any benefactor wishes to supply prizes to all people who submit working code (for example an 8GB version of the Pi 4B), it may be possible to arrange something.

My personal experience suggests that things learned without financial reward are often more liberating anyway than always focusing on the money.
Last edited by ejolson on Fri Nov 08, 2019 6:28 pm, edited 1 time in total.

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

Re: Liberation through Computer Literacy

Fri Nov 08, 2019 6:22 pm

I'm giving a free copy of ScriptBasic away to anyone coming up with the correct answer.
Last edited by John_Spikowski on Fri Nov 08, 2019 6:39 pm, edited 1 time in total.

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

Re: Liberation through Computer Literacy

Fri Nov 08, 2019 6:32 pm

John_Spikowski wrote:
Fri Nov 08, 2019 6:22 pm
I'm giving a free copy of ScriptBasic away to anyone coming up with correct answer.
Are you sure you don't have any 8GB Pi 4B computers you would like to donate?

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

Re: Liberation through Computer Literacy

Fri Nov 08, 2019 6:38 pm

ejolson wrote:
Fri Nov 08, 2019 6:32 pm
John_Spikowski wrote:
Fri Nov 08, 2019 6:22 pm
I'm giving a free copy of ScriptBasic away to anyone coming up with correct answer.
Are you sure you don't have any 8GB Pi 4B computers you would like to donate?
🤑

User avatar
jcyr
Posts: 427
Joined: Sun Apr 23, 2017 1:31 pm
Location: Atlanta

Re: Liberation through Computer Literacy

Fri Nov 08, 2019 7:16 pm

John_Spikowski wrote:
Fri Nov 08, 2019 6:22 pm
I'm giving a free copy of ScriptBasic away to anyone coming up with the correct answer.
Tried downloading it. Got bad link....
It's um...uh...well it's kinda like...and it's got a bit of...

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

Re: Liberation through Computer Literacy

Fri Nov 08, 2019 7:34 pm

Try following the instructions HERE.

Happy to help you get going with ScriptBasic if you need a hand.

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

Re: Liberation through Computer Literacy

Fri Nov 08, 2019 9:37 pm

ejolson wrote:
Fri Nov 08, 2019 6:32 pm
John_Spikowski wrote:
Fri Nov 08, 2019 6:22 pm
I'm giving a free copy of ScriptBasic away to anyone coming up with correct answer.
Are you sure you don't have any 8GB Pi 4B computers you would like to donate?
A good question for the Raspberry Pi Foundation.

Return to “General programming discussion”