Τετάρτη 11 Ιουνίου 2025

Factorial up to 1000!

 We use biginteger, a type for real big numbers.





Font "Verdana"
form 80, 48
Cls , 0 ' 0 for non split display, eg 3 means we preserve the 3 top lines from scrolling/cla
Report {
Factorial Task
Definitions
               • The factorial of   0   (zero)   is defined as being   1   (unity).
               • The   Factorial Function   of a positive integer,   n,   is defined as the product of the sequence:
                                                                      n,   n-1,   n-2,   ...   1
                                                                      
}
Cls, row ' now we preserve some lines (as row number return here)
Module CheckIt {
m=1u ' 1u is biginteger
k=width-tab
For i=1 to 1000
if pos>tab then print
m*=i
Print @(0), format$("{0::-4} :", i);
Report ltrim$(str$(m)), k
' Report accumulate lines and stop at 3/4 of the screen (but not on printer)
' so we can break this using this line:
while inkey$<>"": wait 1:end while: keyboard "         "
Next i
}
Checkit
while inkey$<>"": wait 1:end while
push key$
drop

Κυριακή 8 Ιουνίου 2025

Export help entries to a doc file (simple text file)

 Loading the INFO file we find the EXPORTHELP module

Although this module written to be used with the application of m2000.exe and m2000.dll as source code, we can use it  downloading the file and we need two lines, at top in EXPORTHELP:

DB.PROVIDER "Microsoft.Jet.OLEDB.4.0"
appdir$=dir$

and a file help2000.mdb at User directory (although the appdir$ is the application directory, we just change it for the module level, to dir$ using appdir$=dir$ which make a local variable appdir$ which shadow the read only variable (which we can use at this level using @appdir$).

The DB.PROVIDER need to be 4 because by default it is 12, so we can use DB.PROVIDER as the last statement without arguments to restore to 12.

To download the help2000.mdb we have to get it from 

https://github.com/M2000Interpreter/Environment/blob/main/help2000.mdb

using your browser.

to open explorer at dir$ use this from M2000:

Win Dir$ 

To copy to clipboard the path:

Clipboard Dir$

So if all is ok you can execute EXPORTHELP and choose E for the English help or G for the Greek help.

The General.doc has 265 (Writer)/299 (Word) A4 pages and the Γενικά.doc has 225 (Writer)/255 (Word) A4 pages. The format of these files are UTF8 text.

If you don't want to make the latest, you can read these (although from M2000 we can use HELP word , or HELP ALL and then click on any word to go further):

June 8, 2025: 

Greek - Γενικά.doc

English - General.doc

Παρασκευή 6 Ιουνίου 2025

Talmudic bankruptcy problem

 I found an interesting problem from here Mathologer - YouTube 

So I decide to write a program to calculate the values based on the graphic solution provided by Mathologer. There was no algorithm in the video, so I have to invent one. After thtee fault solution I find how to "fill" like water the vessels of "claims", or pools (as objects)

I found that the objects has to be in ascending order, from smaller to higher claim, so the  "water" split can be done faultless.




cls
Print "Talmudic bankruptcy problem"
report {
The Problem:
A man dies, leaving three creditors with claims of 100, 200, and 300. The estate's value is not specified, but the Talmud provides solutions for when the estate is worth 100, 200, and 300.
The Talmudic Solutions:
Estate Value of 100: The estate is divided equally, giving each creditor 33 1/3.
Estate Value of 200: The creditors receive 50, 75, and 75.
Estate Value of 300: The creditors receive 50, 100, and 150, proportional to their claims.
}
class pool {
claim as double
lim1 as value, total as value
function level(per_cent as double) {
if per_cent<.lim1 then
w=per_cent*.total
if w>=.claim/2 then
=.claim/2
else
=w
end if
else.if per_cent>1-.lim1 then
=.claim-per_cent*.total
else
=.claim
end if
}
module fix (t) {
.total<=t
.lim1<=.claim*2/t
}
class:
module pool (.claim) {
}
}
function total {
var tot as double
while not empty
read t as *pool
tot+=t=>claim
end while
=tot
}
function process(tot, estate) {
m=array([])
many=len(m)
k=each(m)
p=estate>tot/2
if p then estate=tot-estate
while k
t=array(k)
t=>fix tot
per_cent=estate/tot/many
z=t=>level(per_cent)
estate-=z
many--
if p then
data -round(z,2)+t=>claim
else
data round(z,2)
end if
end while
=array([])
}
a->pool(100)
b->pool(200)
c->pool(300)
total=total(a,b,c)
flush
data 50, 100, 200, 250, 275, 300, 400, 450, 500, 600
Pen 15 {Print "", "       A", "      B", "      C", "    SUM"}
while not empty
read that
rep=process(total, that, a, b, c)
Pen 15 {Print "estate = ";that,}
Print rep,
Pen 15 {Print round(rep#sum(),0)}
end while
total=total(a,b)
flush
data 50, 100, 200, 250, 275, 300
Pen 15{Print "", "       A", "      B","", "    SUM"}
while not empty
read that
rep=process(total, that, a, b)
Pen 15 {Print "estate = ";that,}
Print rep,"      ....",
Pen 15 {Print round(rep#sum(),0)}
end while


Κυριακή 1 Ιουνίου 2025

Polyspiral

 





module polyspiral {
smooth off
form 60, 25
cls #220055, 0
var inc = 0, x=scale.x / 2, y=scale.y / 2
var length, angle
refresh 1000
gradient 0, #330066
pen 15 {
italic 1
pen 14 {report "M2000 Interpreter"}
italic 0
report "POLYSPIRAL ANIMATION"
}
hold
every 1000/30 {
release
inc+=0.00248
move x, y
length = TWIPSx*20
angle = inc
for ν=1 to 150
pen #FF0055
width 2 {draw angle angle, length}
length+=TWIPSx*5
angle+=inc
next
if keyPress(32) then exit
refresh 1000
}
refresh 25
}
polyspiral
pen 14