Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,86 @@
|
|||
include "ConsoleWindow"
|
||||
|
||||
// Set width of tabs
|
||||
def tab 10
|
||||
|
||||
local fn gcd( a as long, b as long )
|
||||
dim as long result
|
||||
|
||||
if ( b != 0 )
|
||||
result = fn gcd( b, a mod b)
|
||||
else
|
||||
result = abs(a)
|
||||
end if
|
||||
end fn = result
|
||||
|
||||
begin globals
|
||||
dim as long triangleInfo( 600, 4 )
|
||||
end globals
|
||||
|
||||
local fn CalculateHeronianTriangles( numberToCheck as long ) as long
|
||||
dim as long c, b, a, result, count : count = 0
|
||||
dim as double s, area
|
||||
|
||||
for c = 1 to numberToCheck
|
||||
for b = 1 to c
|
||||
for a = 1 to b
|
||||
s = ( a + b + c ) / 2
|
||||
area = s * ( s - a ) * ( s - b ) * ( s - c )
|
||||
if area > 0
|
||||
area = sqr( area )
|
||||
if area = int( area )
|
||||
result = fn gcd( b, c )
|
||||
result = fn gcd( a, result )
|
||||
if result == 1
|
||||
count++
|
||||
triangleInfo( count, 0 ) = a
|
||||
triangleInfo( count, 1 ) = b
|
||||
triangleInfo( count, 2 ) = c
|
||||
triangleInfo( count, 3 ) = 2 * s
|
||||
triangleInfo( count, 4 ) = area
|
||||
end if
|
||||
end if
|
||||
end if
|
||||
next
|
||||
next
|
||||
next
|
||||
end fn = count
|
||||
|
||||
dim as long i, k, count
|
||||
|
||||
count = fn CalculateHeronianTriangles( 200 )
|
||||
|
||||
print
|
||||
print "Number of triangles:"; count
|
||||
print
|
||||
print "---------------------------------------------"
|
||||
print "Side A", "Side B", "Side C", "Perimeter", "Area"
|
||||
print "---------------------------------------------"
|
||||
|
||||
// Sort array
|
||||
dim as Boolean flips : flips = _true
|
||||
while ( flips = _true )
|
||||
flips = _false
|
||||
for i = 1 to count - 1
|
||||
if triangleInfo( i, 4 ) > triangleInfo( i + 1, 4 )
|
||||
for k = 0 to 4
|
||||
swap triangleInfo( i, k ), triangleInfo( i + 1, k )
|
||||
next
|
||||
flips = _true
|
||||
end if
|
||||
next
|
||||
wend
|
||||
|
||||
// Find first 10 heronian triangles
|
||||
for i = 1 to 10
|
||||
print triangleInfo( i, 0 ), triangleInfo( i, 1 ), triangleInfo( i, 2 ), triangleInfo( i, 3 ), triangleInfo( i, 4 )
|
||||
next
|
||||
print
|
||||
print "Triangles with an area of 210:"
|
||||
print
|
||||
// Search for triangle with area of 210
|
||||
for i = 1 to count
|
||||
if triangleInfo( i, 4 ) == 210
|
||||
print triangleInfo( i, 0 ), triangleInfo( i, 1 ), triangleInfo( i, 2 ), triangleInfo( i, 3 ), triangleInfo( i, 4 )
|
||||
end if
|
||||
next
|
||||
Loading…
Add table
Add a link
Reference in a new issue