Author Topic: Diagonals  (Read 5863 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Diagonals
« 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.

Code: [Select]

  ' 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

Peter

  • Guest
Re: Diagonals
« Reply #1 on: March 28, 2011, 05:42:49 AM »
Hi Charles

if d+d[j]+d[k]=d[l] then  '<-- is this now necessary?   ???

Charles Pegge

  • Guest
Re: Diagonals
« Reply #2 on: March 28, 2011, 06:56:02 AM »
No Peter, 'then' is a luxury item. My fingers are responsible. I do not instruct them to type it in :)

Charles

JRS

  • Guest
Re: Diagonals
« Reply #3 on: March 28, 2011, 11:29:34 PM »
Why stop with eliminating the THEN and drop the IF as well.

Code: [Select]
d+d[j]+d[k]=d[l]

If an expression exists on the left side of an equation, assume IF.


Charles Pegge

  • Guest
Re: Diagonals
« Reply #4 on: March 29, 2011, 01:11:16 AM »

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

Peter

  • Guest
Re: Diagonals
« Reply #5 on: March 29, 2011, 02:21:32 AM »
Yes, We need this 'IF'!   The standard must be  preserved.
C has also 'IF'. Without  'IF' is it C--.   :D

Aurel

  • Guest
Re: Diagonals
« Reply #6 on: March 29, 2011, 08:45:31 AM »
Quote
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

JRS

  • Guest
Re: Diagonals
« Reply #7 on: March 29, 2011, 10:44:50 AM »
Code: [Select]
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?



« Last Edit: March 29, 2011, 10:48:35 AM by JRS »

Charles Pegge

  • Guest
Re: Diagonals
« Reply #8 on: March 29, 2011, 11:32:26 AM »

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:

Code: [Select]
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

Code: [Select]
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

Aurel

  • Guest
Re: Diagonals
« Reply #9 on: March 29, 2011, 12:01:08 PM »
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
« Last Edit: March 29, 2011, 12:06:00 PM by Aurel »

Charles Pegge

  • Guest
Re: Diagonals
« Reply #10 on: March 29, 2011, 12:20:26 PM »
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

Peter

  • Guest
Re: Diagonals
« Reply #11 on: March 29, 2011, 12:59:14 PM »
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)

JRS

  • Guest
Re: Diagonals
« Reply #12 on: March 29, 2011, 01:35:47 PM »
ScriptBasic has a REPLACE() function/statement that may be somewhat equivalent to a left sided MID.

REPLACE(base_string,search_string,replace_string [,number_of_replaces] [,position])

Aurel

  • Guest
Re: Diagonals
« Reply #13 on: March 29, 2011, 02:09:29 PM »
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$

JRS

  • Guest
Re: Diagonals
« Reply #14 on: March 31, 2011, 06:57:45 PM »
Quote
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.