June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,13 +1,13 @@
|
|||
use framework "Foundation"
|
||||
|
||||
property ca : current application
|
||||
-- HERONIAN TRIANGLES --------------------------------------------------------
|
||||
|
||||
-- heroniansOfSideUpTo :: Int -> [(Int, Int, Int)]
|
||||
on heroniansOfSideUpTo(n)
|
||||
script sideA
|
||||
on lambda(a)
|
||||
on |λ|(a)
|
||||
script sideB
|
||||
on lambda(b)
|
||||
on |λ|(b)
|
||||
script sideC
|
||||
-- primitiveHeronian :: Int -> Int -> Int -> Bool
|
||||
on primitiveHeronian(x, y, z)
|
||||
|
|
@ -16,55 +16,51 @@ on heroniansOfSideUpTo(n)
|
|||
isIntegerValue(hArea(x, y, z))
|
||||
end primitiveHeronian
|
||||
|
||||
on lambda(c)
|
||||
on |λ|(c)
|
||||
if primitiveHeronian(a, b, c) then
|
||||
[[a, b, c]]
|
||||
{{a, b, c}}
|
||||
else
|
||||
[]
|
||||
{}
|
||||
end if
|
||||
end lambda
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
concatMap(sideC, range(b, n))
|
||||
end lambda
|
||||
concatMap(sideC, enumFromTo(b, n))
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
concatMap(sideB, range(a, n))
|
||||
end lambda
|
||||
concatMap(sideB, enumFromTo(a, n))
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
concatMap(sideA, range(1, n))
|
||||
concatMap(sideA, enumFromTo(1, n))
|
||||
end heroniansOfSideUpTo
|
||||
|
||||
|
||||
|
||||
-- TEST
|
||||
|
||||
-- TEST ----------------------------------------------------------------------
|
||||
on run
|
||||
set n to 200
|
||||
|
||||
set lstHeron to sortByKeys(map(triangleDimensions, ¬
|
||||
heroniansOfSideUpTo(n)), ¬
|
||||
{"area", "perimeter", "maxSide"})
|
||||
set lstHeron to ¬
|
||||
sortByComparing({{"area", true}, {"perimeter", true}, {"maxSide", true}}, ¬
|
||||
map(triangleDimensions, heroniansOfSideUpTo(n)))
|
||||
|
||||
set lstCols to {"sides", "perimeter", "area"}
|
||||
set lstColWidths to [20, 15, 0]
|
||||
set lstColWidths to {20, 15, 0}
|
||||
set area to 210
|
||||
|
||||
script areaFilter
|
||||
-- Record -> [Record]
|
||||
on lambda(recTriangle)
|
||||
on |λ|(recTriangle)
|
||||
if area of recTriangle = area then
|
||||
[recTriangle]
|
||||
{recTriangle}
|
||||
else
|
||||
[]
|
||||
{}
|
||||
end if
|
||||
end lambda
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
intercalate("
|
||||
|
||||
", {("Number of triangles found (with sides <= 200): " & ¬
|
||||
intercalate("\n \n", {("Number of triangles found (with sides <= 200): " & ¬
|
||||
length of lstHeron as string), ¬
|
||||
¬
|
||||
tabulation("First 10, ordered by area, perimeter, longest side", ¬
|
||||
|
|
@ -74,8 +70,6 @@ on run
|
|||
concatMap(areaFilter, lstHeron), lstCols, lstColWidths)})
|
||||
end run
|
||||
|
||||
|
||||
|
||||
-- triangleDimensions :: (Int, Int, Int) ->
|
||||
-- {sides: (Int, Int, Int), area: Int, perimeter: Int, maxSize: Int}
|
||||
on triangleDimensions(lstSides)
|
||||
|
|
@ -105,23 +99,23 @@ on gcd(m, n)
|
|||
end gcd
|
||||
|
||||
|
||||
-- TABLE FORMATTING
|
||||
-- TABULATION ----------------------------------------------------------------
|
||||
|
||||
-- tabulation :: [Record] -> [String] -> String -> [Integer] -> String
|
||||
on tabulation(strLegend, lstRecords, lstKeys, lstWidths)
|
||||
script heading
|
||||
on lambda(strTitle, iCol)
|
||||
set str to toCapitalized(strTitle)
|
||||
str & nreps(space, (item iCol of lstWidths) - (length of str))
|
||||
end lambda
|
||||
on |λ|(strTitle, iCol)
|
||||
set str to toTitle(strTitle)
|
||||
str & replicate((item iCol of lstWidths) - (length of str), space)
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
script lineString
|
||||
on lambda(rec)
|
||||
on |λ|(rec)
|
||||
script fieldString
|
||||
-- fieldString :: String -> Int -> String
|
||||
on lambda(strKey, i)
|
||||
set v to keyValue(rec, strKey)
|
||||
on |λ|(strKey, i)
|
||||
set v to keyValue(strKey, rec)
|
||||
|
||||
if class of v is list then
|
||||
set strData to ("(" & intercalate(", ", v) & ")")
|
||||
|
|
@ -129,12 +123,12 @@ on tabulation(strLegend, lstRecords, lstKeys, lstWidths)
|
|||
set strData to v as string
|
||||
end if
|
||||
|
||||
strData & nreps(space, (item i of (lstWidths)) - (length of strData))
|
||||
end lambda
|
||||
strData & replicate(space, (item i of (lstWidths)) - (length of strData))
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
tab & intercalate(tab, map(fieldString, lstKeys))
|
||||
end lambda
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
strLegend & ":" & linefeed & linefeed & ¬
|
||||
|
|
@ -143,81 +137,52 @@ on tabulation(strLegend, lstRecords, lstKeys, lstWidths)
|
|||
intercalate(linefeed, map(lineString, lstRecords))
|
||||
end tabulation
|
||||
|
||||
-- isIntegerValue :: Num -> Bool
|
||||
on isIntegerValue(n)
|
||||
{real, integer} contains class of n and (n = (n as integer))
|
||||
end isIntegerValue
|
||||
-- GENERIC FUNCTIONS ---------------------------------------------------------
|
||||
|
||||
|
||||
-- sortByKeys :: [Record] -> [String] -> [Record]
|
||||
on sortByKeys(lstRecords, lstKeys)
|
||||
script keyDescriptor
|
||||
on lambda(strKey)
|
||||
ca's NSSortDescriptor's ¬
|
||||
sortDescriptorWithKey:(strKey) ascending:true
|
||||
end lambda
|
||||
end script
|
||||
|
||||
((ca's NSArray's arrayWithArray:lstRecords)'s ¬
|
||||
sortedArrayUsingDescriptors:(map(keyDescriptor, lstKeys))) as list
|
||||
end sortByKeys
|
||||
|
||||
|
||||
-- keyValue :: Record -> String -> a
|
||||
on keyValue(rec, strKey)
|
||||
item 1 of ((ca's NSArray's ¬
|
||||
arrayWithObject:((ca's NSDictionary's dictionaryWithDictionary:rec)'s ¬
|
||||
objectForKey:strKey)) as list)
|
||||
end keyValue
|
||||
|
||||
-- GENERIC FUNCTIONS
|
||||
-- concat :: [[a]] -> [a] | [String] -> String
|
||||
on concat(xs)
|
||||
if length of xs > 0 and class of (item 1 of xs) is string then
|
||||
set acc to ""
|
||||
else
|
||||
set acc to {}
|
||||
end if
|
||||
repeat with i from 1 to length of xs
|
||||
set acc to acc & item i of xs
|
||||
end repeat
|
||||
acc
|
||||
end concat
|
||||
|
||||
-- concatMap :: (a -> [b]) -> [a] -> [b]
|
||||
on concatMap(f, xs)
|
||||
script append
|
||||
on lambda(a, b)
|
||||
a & b
|
||||
end lambda
|
||||
end script
|
||||
foldl(append, {}, map(f, xs))
|
||||
concat(map(f, xs))
|
||||
end concatMap
|
||||
|
||||
-- enumFromTo :: Int -> Int -> [Int]
|
||||
on enumFromTo(m, n)
|
||||
if m > n then
|
||||
set d to -1
|
||||
else
|
||||
set d to 1
|
||||
end if
|
||||
set lst to {}
|
||||
repeat with i from m to n by d
|
||||
set end of lst to i
|
||||
end repeat
|
||||
return lst
|
||||
end enumFromTo
|
||||
|
||||
-- foldl :: (a -> b -> a) -> a -> [b] -> a
|
||||
on foldl(f, startValue, xs)
|
||||
tell mReturn(f)
|
||||
set v to startValue
|
||||
set lng to length of xs
|
||||
repeat with i from 1 to lng
|
||||
set v to lambda(v, item i of xs, i, xs)
|
||||
set v to |λ|(v, item i of xs, i, xs)
|
||||
end repeat
|
||||
return v
|
||||
end tell
|
||||
end foldl
|
||||
|
||||
-- map :: (a -> b) -> [a] -> [b]
|
||||
on map(f, xs)
|
||||
tell mReturn(f)
|
||||
set lng to length of xs
|
||||
set lst to {}
|
||||
repeat with i from 1 to lng
|
||||
set end of lst to lambda(item i of xs, i, xs)
|
||||
end repeat
|
||||
return lst
|
||||
end tell
|
||||
end map
|
||||
|
||||
-- range :: Int -> Int -> [Int]
|
||||
on range(m, n)
|
||||
set d to 1
|
||||
if n < m then set d to -1
|
||||
set lst to {}
|
||||
repeat with i from m to n by d
|
||||
set end of lst to i
|
||||
end repeat
|
||||
return lst
|
||||
end range
|
||||
|
||||
|
||||
-- intercalate :: Text -> [Text] -> Text
|
||||
on intercalate(strText, lstText)
|
||||
set {dlm, my text item delimiters} to {my text item delimiters, strText}
|
||||
|
|
@ -226,24 +191,33 @@ on intercalate(strText, lstText)
|
|||
return strJoined
|
||||
end intercalate
|
||||
|
||||
-- Text -> Text
|
||||
on toCapitalized(str)
|
||||
((ca's NSString's stringWithString:(str))'s ¬
|
||||
capitalizedStringWithLocale:(ca's NSLocale's currentLocale())) as text
|
||||
end toCapitalized
|
||||
-- isIntegerValue :: Num -> Bool
|
||||
on isIntegerValue(n)
|
||||
{real, integer} contains class of n and (n = (n as integer))
|
||||
end isIntegerValue
|
||||
|
||||
-- String -> Int -> String
|
||||
on nreps(s, n)
|
||||
set o to ""
|
||||
if n < 1 then return o
|
||||
-- keyValue :: String -> Record -> Maybe String
|
||||
on keyValue(strKey, rec)
|
||||
set ca to current application
|
||||
set v to (ca's NSDictionary's dictionaryWithDictionary:rec)'s objectForKey:strKey
|
||||
if v is not missing value then
|
||||
item 1 of ((ca's NSArray's arrayWithObject:v) as list)
|
||||
else
|
||||
missing value
|
||||
end if
|
||||
end keyValue
|
||||
|
||||
repeat while (n > 1)
|
||||
if (n mod 2) > 0 then set o to o & s
|
||||
set n to (n div 2)
|
||||
set s to (s & s)
|
||||
end repeat
|
||||
return o & s
|
||||
end nreps
|
||||
-- map :: (a -> b) -> [a] -> [b]
|
||||
on map(f, xs)
|
||||
tell mReturn(f)
|
||||
set lng to length of xs
|
||||
set lst to {}
|
||||
repeat with i from 1 to lng
|
||||
set end of lst to |λ|(item i of xs, i, xs)
|
||||
end repeat
|
||||
return lst
|
||||
end tell
|
||||
end map
|
||||
|
||||
-- Lift 2nd class handler function into 1st class script wrapper
|
||||
-- mReturn :: Handler -> Script
|
||||
|
|
@ -252,7 +226,52 @@ on mReturn(f)
|
|||
f
|
||||
else
|
||||
script
|
||||
property lambda : f
|
||||
property |λ| : f
|
||||
end script
|
||||
end if
|
||||
end mReturn
|
||||
|
||||
-- replicate :: Int -> String -> String
|
||||
on replicate(n, s)
|
||||
set out to ""
|
||||
if n < 1 then return out
|
||||
set dbl to s
|
||||
|
||||
repeat while (n > 1)
|
||||
if (n mod 2) > 0 then set out to out & dbl
|
||||
set n to (n div 2)
|
||||
set dbl to (dbl & dbl)
|
||||
end repeat
|
||||
return out & dbl
|
||||
end replicate
|
||||
|
||||
-- List of {strKey, blnAscending} pairs -> list of records -> sorted list of records
|
||||
|
||||
-- sortByComparing :: [(String, Bool)] -> [Records] -> [Records]
|
||||
on sortByComparing(keyDirections, xs)
|
||||
set ca to current application
|
||||
|
||||
script recDict
|
||||
on |λ|(x)
|
||||
ca's NSDictionary's dictionaryWithDictionary:x
|
||||
end |λ|
|
||||
end script
|
||||
set dcts to map(recDict, xs)
|
||||
|
||||
script asDescriptor
|
||||
on |λ|(kd)
|
||||
set {k, d} to kd
|
||||
ca's NSSortDescriptor's sortDescriptorWithKey:k ascending:d selector:dcts
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
((ca's NSArray's arrayWithArray:dcts)'s ¬
|
||||
sortedArrayUsingDescriptors:map(asDescriptor, keyDirections)) as list
|
||||
end sortByComparing
|
||||
|
||||
-- toTitle :: String -> String
|
||||
on toTitle(str)
|
||||
set ca to current application
|
||||
((ca's NSString's stringWithString:(str))'s ¬
|
||||
capitalizedStringWithLocale:(ca's NSLocale's currentLocale())) as text
|
||||
end toTitle
|
||||
|
|
|
|||
122
Task/Heronian-triangles/C/heronian-triangles.c
Normal file
122
Task/Heronian-triangles/C/heronian-triangles.c
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
/*Abhishek Ghosh, 6th October 2017*/
|
||||
|
||||
#include<stdlib.h>
|
||||
#include<stdio.h>
|
||||
#include<math.h>
|
||||
|
||||
typedef struct{
|
||||
int a,b,c;
|
||||
int perimeter;
|
||||
double area;
|
||||
}triangle;
|
||||
|
||||
typedef struct elem{
|
||||
triangle t;
|
||||
struct elem* next;
|
||||
}cell;
|
||||
|
||||
typedef cell* list;
|
||||
|
||||
void addAndOrderList(list *a,triangle t){
|
||||
list iter,temp;
|
||||
int flag = 0;
|
||||
|
||||
if(*a==NULL){
|
||||
*a = (list)malloc(sizeof(cell));
|
||||
(*a)->t = t;
|
||||
(*a)->next = NULL;
|
||||
}
|
||||
|
||||
else{
|
||||
temp = (list)malloc(sizeof(cell));
|
||||
|
||||
iter = *a;
|
||||
while(iter->next!=NULL){
|
||||
if(((iter->t.area<t.area)||(iter->t.area==t.area && iter->t.perimeter<t.perimeter)||(iter->t.area==t.area && iter->t.perimeter==t.perimeter && iter->t.a<=t.a))
|
||||
&&
|
||||
(iter->next==NULL||(t.area<iter->next->t.area || t.perimeter<iter->next->t.perimeter || t.a<iter->next->t.a))){
|
||||
temp->t = t;
|
||||
temp->next = iter->next;
|
||||
iter->next = temp;
|
||||
flag = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
iter = iter->next;
|
||||
}
|
||||
|
||||
if(flag!=1){
|
||||
temp->t = t;
|
||||
temp->next = NULL;
|
||||
iter->next = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int gcd(int a,int b){
|
||||
if(b!=0)
|
||||
return gcd(b,a%b);
|
||||
return a;
|
||||
}
|
||||
|
||||
void calculateArea(triangle *t){
|
||||
(*t).perimeter = (*t).a + (*t).b + (*t).c;
|
||||
(*t).area = sqrt(0.5*(*t).perimeter*(0.5*(*t).perimeter - (*t).a)*(0.5*(*t).perimeter - (*t).b)*(0.5*(*t).perimeter - (*t).c));
|
||||
}
|
||||
|
||||
list generateTriangleList(int maxSide,int *count){
|
||||
int a,b,c;
|
||||
triangle t;
|
||||
list herons = NULL;
|
||||
|
||||
*count = 0;
|
||||
|
||||
for(a=1;a<=maxSide;a++){
|
||||
for(b=1;b<=a;b++){
|
||||
for(c=1;c<=b;c++){
|
||||
if(c+b > a && gcd(gcd(a,b),c)==1){
|
||||
t = (triangle){a,b,c};
|
||||
calculateArea(&t);
|
||||
if(t.area/(int)t.area == 1){
|
||||
addAndOrderList(&herons,t);
|
||||
(*count)++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return herons;
|
||||
}
|
||||
|
||||
void printList(list a,int limit,int area){
|
||||
list iter = a;
|
||||
int count = 1;
|
||||
|
||||
printf("\nDimensions\tPerimeter\tArea");
|
||||
|
||||
while(iter!=NULL && count!=limit+1){
|
||||
if(area==-1 ||(area==iter->t.area)){
|
||||
printf("\n%d x %d x %d\t%d\t\t%d",iter->t.a,iter->t.b,iter->t.c,iter->t.perimeter,(int)iter->t.area);
|
||||
count++;
|
||||
}
|
||||
iter = iter->next;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argC,char* argV[])
|
||||
{
|
||||
int count;
|
||||
list herons = NULL;
|
||||
|
||||
if(argC!=4)
|
||||
printf("Usage : %s <Max side, max triangles to print and area, -1 for area to ignore>",argV[0]);
|
||||
else{
|
||||
herons = generateTriangleList(atoi(argV[1]),&count);
|
||||
printf("Triangles found : %d",count);
|
||||
(atoi(argV[3])==-1)?printf("\nPrinting first %s triangles.",argV[2]):printf("\nPrinting triangles with area %s square units.",argV[3]);
|
||||
printList(herons,atoi(argV[2]),atoi(argV[3]));
|
||||
free(herons);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
/*REXX program generates & displays primitive Heronian triangles by side length and area*/
|
||||
parse arg N first area . /*obtain optional arguments from the CL*/
|
||||
if N=='' | N==',' then N=200 /*Not specified? Then use the default.*/
|
||||
if first=='' | first==',' then first= 10 /* " " " " " " */
|
||||
if area=='' | area==',' then area=210 /* " " " " " " */
|
||||
if N=='' | N=="," then N=200 /*Not specified? Then use the default.*/
|
||||
if first=='' | first=="," then first= 10 /* " " " " " " */
|
||||
if area=='' | area=="," then area=210 /* " " " " " " */
|
||||
numeric digits 99; numeric digits max(9, 1+length(N**5)) /*ensure 'nuff decimal digits.*/
|
||||
call Heron; HT= 'Heronian triangles' /*invoke the Heron subroutine. */
|
||||
say # ' primitive' HT "found with sides up to " N ' (inclusive).'
|
||||
|
|
|
|||
|
|
@ -1,32 +1,32 @@
|
|||
/*REXX program generates & displays primitive Heronian triangles by side length and area*/
|
||||
parse arg N first area . /*obtain optional arguments from the CL*/
|
||||
if N=='' | N==',' then N=200 /*Not specified? Then use the default.*/
|
||||
if first=='' | first==',' then first= 10 /* " " " " " " */
|
||||
if area=='' | area==',' then area=210 /* " " " " " " */
|
||||
if N=='' | N=="," then N=200 /*Not specified? Then use the default.*/
|
||||
if first=='' | first=="," then first= 10 /* " " " " " " */
|
||||
if area=='' | area=="," then area=210 /* " " " " " " */
|
||||
numeric digits 99; numeric digits max(9, 1+length(N**5)) /*ensure 'nuff decimal digits.*/
|
||||
call Heron; HT= 'Heronian triangles' /*invoke the Heron subroutine. */
|
||||
say # ' primitive' HT "found with sides up to " N ' (inclusive).'
|
||||
call show , 'Listing of the first ' first ' primitive' HT":"
|
||||
say # ' primitive' HT "found with sides up to " N ' (inclusive).'
|
||||
call show , 'Listing of the first ' first ' primitive' HT":"
|
||||
call show area, 'Listing of the (above) found primitive' HT "with an area of " area
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
Heron: @.=0; #=0; !.=.; minP=9e9; maxA=0; maxP=0; minA=9e9; Ln=length(N) /* __ */
|
||||
do i=5 to N**2%2; _=i*i; !._=i; end /*pre-calculate a fast √ */
|
||||
do i=5 to N**2%2; _=i*i; !._=i; end /*pre-calculate a fast √ */
|
||||
do a=3 to N /*start at a minimum side length of 3. */
|
||||
even= a//2==0 /*if A is even, B and C must be odd.*/
|
||||
do b=a+even to N by 1+even; ab=a+b /*AB: is a shortcut sum. */
|
||||
even= (a//2==0) /*if A is even, B and C must be odd.*/
|
||||
do b=a+even to N by 1+even; ab=a + b /*AB: is a shortcut sum. */
|
||||
if b//2==0 then bump=1 /*B is even? Then C is odd. */
|
||||
else if even then bump=0 /*A is even? " " " " */
|
||||
else bump=1 /*A & B odd, biz as usual. */
|
||||
do c=b+bump to N by 2; s=(ab+c)%2 /*calculate perimeter: S. */
|
||||
do c=b+bump to N by 2; s=(ab + c) % 2 /*calculate perimeter: S. */
|
||||
_=s*(s-a)*(s-b)*(s-c); if !._==. then iterate /*Is _ not a square? Skip.*/
|
||||
ar=!._; if ar*ar\==_ then iterate /*Area not an integer? Skip.*/
|
||||
if hGCD(a,b,c)\==1 then iterate /*GCD of sides not 1? Skip.*/
|
||||
#=#+1; p=ab+c /*primitive Heronian triangle*/
|
||||
minP=min( p,minP); maxP=max( p,maxP); Lp=length(maxP)
|
||||
minA=min(ar,minA); maxA=max(ar,maxA); La=length(maxA); @.ar=
|
||||
_=@.ar.p.0+1 /*bump the triangle counter.*/
|
||||
@.ar.p.0=_; @.ar.p._=right(a,Ln) right(b,Ln) right(c,Ln) /*unique.*/
|
||||
if hGCD(a,b,c) \== 1 then iterate /*GCD of sides not 1? Skip.*/
|
||||
#=# + 1; p=ab + c /*primitive Heronian triangle*/
|
||||
minP=min( p, minP); maxP=max( p, maxP); Lp=length(maxP)
|
||||
minA=min(ar, minA); maxA=max(ar, maxA); La=length(maxA); @.ar=
|
||||
_=@.ar.p.0 + 1 /*bump the triangle counter. */
|
||||
@.ar.p.0=_; @.ar.p._=right(a, Ln) right(b, Ln) right(c, Ln) /*unique.*/
|
||||
end /*c*/ /* [↑] keep each unique perimeter #. */
|
||||
end /*b*/
|
||||
end /*a*/
|
||||
|
|
@ -43,3 +43,4 @@ show: m=0; say; say; parse arg ae; say arg(2); if ae\=='' then
|
|||
end /*k*/
|
||||
end /*j*/ /* [↑] use the known perimeters. */
|
||||
end /*i*/ /* [↑] show any found triangles. */
|
||||
return
|
||||
|
|
|
|||
43
Task/Heronian-triangles/Ring/heronian-triangles.ring
Normal file
43
Task/Heronian-triangles/Ring/heronian-triangles.ring
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# Project : Heronian triangles
|
||||
# Date : 2017/11/04
|
||||
# Author : Gal Zsolt (~ CalmoSoft ~)
|
||||
# Email : <calmosoft@gmail.com>
|
||||
|
||||
see "Heronian triangles with sides up to 200" + nl
|
||||
see "Sides Perimeter Area" + nl
|
||||
for n = 1 to 200
|
||||
for m = n to 200
|
||||
for p = m to 200
|
||||
s = (n + m + p) / 2
|
||||
w = sqrt(s * (s - n) * (s - m) * (s - p))
|
||||
bool = (gcd(n, m) = 1 or gcd(n, m) = n) and (gcd(n, p) = 1 or gcd(n, p) = n) and (gcd(m, p) = 1 or gcd(m, p) = m)
|
||||
if w = floor(w) and w > 0 and bool
|
||||
see "{" + n + ", " + m + ", " + p + "}" + " " + s*2 + " " + w + nl
|
||||
ok
|
||||
next
|
||||
next
|
||||
next
|
||||
see nl
|
||||
|
||||
see "Heronian triangles with area 210:" + nl
|
||||
see "Sides Perimeter Area" + nl
|
||||
for n = 1 to 150
|
||||
for m = n to 150
|
||||
for p = m to 150
|
||||
s = (n + m + p) / 2
|
||||
w = sqrt(s * (s - n) * (s - m) * (s - p))
|
||||
bool = (gcd(n, m) = 1 or gcd(n, m) = n) and (gcd(n, p) = 1 or gcd(n, p) = n) and (gcd(m, p) = 1 or gcd(m, p) = m)
|
||||
if w = 210 and bool
|
||||
see "{" + n + ", " + m + ", " + p + "}" + " " + s*2 + " " + w + nl
|
||||
ok
|
||||
next
|
||||
next
|
||||
next
|
||||
|
||||
func gcd(gcd, b)
|
||||
while b
|
||||
c = gcd
|
||||
gcd = b
|
||||
b = c % b
|
||||
end
|
||||
return gcd
|
||||
Loading…
Add table
Add a link
Reference in a new issue