Oxygen Basic
Programming => Example Code => General => Topic started by: Charles Pegge on March 28, 2011, 04:06:51 AM
-
This is a simple piece of experimental maths, which I anticipate will be useful in various construction projects. The program identifies rational diagonals - I am looking for only those diagonals that are a simple proportion to the lengths of the sides.
' the integer diagonal problem
'=============================
'
'looking for diagonals which have a simple ratio to the lengths of the sides.
' diagonal=sqrt x*x + y*y + z*z
' examples:
'----------
'
' 2D 3 4 --> diagonal 5
' 3D 2 3 6 --> diagonal 7
def e 100
sys c,i,j,k,l,d[e]
string pr,cr,se
cr=chr(13)+chr(10)
se=chr(9) 'tab
pr="TABLE OF CUBOID DIAGONAL INTEGERS" cr cr
pr+="x" se "y" se "z" se "diagonal" cr
for i=1 to e
d[i]=i*i
next
do
for i=2 to e
for j= i to e
for k=j to e
for l=i to e
if d[i]+d[j]+d[k]=d[l] then
pr+="" i se j se k se l cr
c+=1
if c>40 then exit do 'PROCESS FIRST 40 VALUES ONLY
end if
next
next
next
next
exit
end do
print pr
Charles
-
Hi Charles
if d+d[j]+d[k]=d[l] then '<-- is this now necessary? ???
-
No Peter, 'then' is a luxury item. My fingers are responsible. I do not instruct them to type it in :)
Charles
-
Why stop with eliminating the THEN and drop the IF as well.
d+d[j]+d[k]=d[l]
If an expression exists on the left side of an equation, assume IF.
-
Hi John,
I think we are always going to need the 'IF' because of clarity and because Oxygen often puts expressions on the left side.
For instance the classic basic string patching procedure:
mid(s,4)="abc"
would be confused with
if mid(s,4)="abc" ..
But the idea is an interesting one and worth exploring:
if a=b {print "yes"}else{print "no"}
a==b {print "yes"}{print "no"}
Charles
-
Yes, We need this 'IF'! The standard must be preserved.
C has also 'IF'. Without 'IF' is it C--. :D
-
For instance the classic basic string patching procedure:
mid(s,4)="abc"
would be confused with
if mid(s,4)="abc" ..
Of course i agree with Cherles IF must exist but THEN not if is not
inline expression like IF a=b THEN c=d
and much logical to me is :
IF a=b ' without THEN
....
...
ELSE
....
END IF
-
s = string(10," ")
mid(s,4)="abc"
print s,"\n"
This produces a syntax error in ScriptBasic. Assignments to functions aren't allowed.
How many other Basic languages allow these types of assignments?
-
As far as I can remember, all the basics I have used regularly, going back to BBC basic and Mbasic, have had this MID$()=
But let me share a secret with you: No assignment is involved! The compiler takes both sides of the expression and treats the whole thing as a procedure. MID$ can be expressed in at least 3 ways:
string s="1234567890"
mid s,1,"A"
mid(s,2,"B")
mid(s,3)="C" 'pseudovariable
print s
You can also deploy your own pseudovariables if it makes sense to do so
sub insert(s as string,i as long,t as string)
s=left(s,i-1)+t+mid(s,i)
end sub
s="1234567890"
insert(s,4)="ABC"
print s
Charles
-
Charles im not sure about MID or MID$ function as standard shape like this
a$ = MID$(b$,StartPosInString,Len)
'Len is number of characters or count
For example in VB:
Public Shared Function Mid( ByVal str As String, ByVal Start As Integer, Optional ByVal Length As Integer ) As String
-
Aurel, Does VB use Mid$(s,i)=... or does it use another command name?
Due to its widespread use, I've chosen to offer the flexible syntax.
To distinguish the two different kinds of MID The compiler has to work a liitle harder but MID is not unique in this. STRING presents a similar problem:
Here string has two completely separate meanings:
string s="ABC"
s=string(3,"A")
Charles
-
Visual basic pur!
' Creates text string.
Dim TestString As String = "Mid Function Demo"
' Returns "Mid".
Dim FirstWord As String = Mid(TestString, 1, 3)
' Returns "Demo".
Dim LastWord As String = Mid(TestString, 14, 4)
' Returns "Function Demo".
Dim MidWords As String = Mid(TestString, 5)
-
ScriptBasic has a REPLACE() (http://www.scriptbasic.org/docs/ug/ug_25.144.html) function/statement that may be somewhat equivalent to a left sided MID.
REPLACE(base_string,search_string,replace_string [,number_of_replaces] [,position])
-
string s="ABC"
s=string(3,"A")
agree it's two different things.
and we all know that in first
STRING mean variable type
in second:
string variable s is filled with AAA
So becose of this and many similiar situation is good to have sufix like STRING$
-
As far as I can remember, all the basics I have used regularly, going back to BBC basic and Mbasic, have had this MID$()=
If I remember correctly, some Basic dialects support both a MID function and MID statement. What you are showing is the use of a MID statement. I happen to like the SB REPLACE statement to manipulate an existing string. The old LEFT/RIGHT/MID functions work great if your assembling a string from scratch.