Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
47
Task/Heronian-triangles/PowerShell/heronian-triangles-1.psh
Normal file
47
Task/Heronian-triangles/PowerShell/heronian-triangles-1.psh
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
function Get-Gcd($a, $b){
|
||||
if($a -ge $b){
|
||||
$dividend = $a
|
||||
$divisor = $b
|
||||
}
|
||||
else{
|
||||
$dividend = $b
|
||||
$divisor = $a
|
||||
}
|
||||
$leftover = 1
|
||||
while($leftover -ne 0){
|
||||
$leftover = $dividend % $divisor
|
||||
if($leftover -ne 0){
|
||||
$dividend = $divisor
|
||||
$divisor = $leftover
|
||||
}
|
||||
}
|
||||
$divisor
|
||||
}
|
||||
function Is-Heron($heronArea){
|
||||
$heronArea -gt 0 -and $heronArea % 1 -eq 0
|
||||
}
|
||||
function Get-HeronArea($a, $b, $c){
|
||||
$s = ($a + $b + $c) / 2
|
||||
[math]::Sqrt($s * ($s - $a) * ($s - $b) * ($s - $c))
|
||||
}
|
||||
$result = @()
|
||||
foreach ($c in 1..200){
|
||||
for($b = 1; $b -le $c; $b++){
|
||||
for($a = 1; $a -le $b; $a++){
|
||||
if((Get-Gcd $c (Get-Gcd $b $a)) -eq 1 -and (Is-Heron(Get-HeronArea $a $b $c))){
|
||||
$result += @(,@($a, $b, $c,($a + $b + $c), (Get-HeronArea $a $b $c)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$result = $result | sort-object @{Expression={$_[4]}}, @{Expression={$_[3]}}, @{Expression={$_[2]}}
|
||||
"Primitive Heronian triangles with sides up to 200: $($result.length)`nFirst ten when ordered by increasing area, then perimeter,then maximum sides:`nSides`t`t`t`tPerimeter`tArea"
|
||||
for($i = 0; $i -lt 10; $i++){
|
||||
"$($result[$i][0])`t$($result[$i][1])`t$($result[$i][2])`t`t`t$($result[$i][3])`t`t`t$($result[$i][4])"
|
||||
}
|
||||
"`nArea = 210`nSides`t`t`t`tPerimeter`tArea"
|
||||
foreach($i in $result){
|
||||
if($i[4] -eq 210){
|
||||
"$($i[0])`t$($i[1])`t$($i[2])`t`t`t$($i[3])`t`t`t$($i[4])"
|
||||
}
|
||||
}
|
||||
23
Task/Heronian-triangles/PowerShell/heronian-triangles-2.psh
Normal file
23
Task/Heronian-triangles/PowerShell/heronian-triangles-2.psh
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
Primitive Heronian triangles with sides up to 200: 517
|
||||
|
||||
First ten when ordered by increasing area, then perimeter,then maximum sides:
|
||||
Sides Perimeter Area
|
||||
3 4 5 12 6
|
||||
5 5 6 16 12
|
||||
5 5 8 18 12
|
||||
4 13 15 32 24
|
||||
5 12 13 30 30
|
||||
9 10 17 36 36
|
||||
3 25 26 54 36
|
||||
7 15 20 42 42
|
||||
10 13 13 36 60
|
||||
8 15 17 40 60
|
||||
|
||||
Area = 210
|
||||
Sides Perimeter Area
|
||||
17 25 28 70 210
|
||||
20 21 29 70 210
|
||||
12 35 37 84 210
|
||||
17 28 39 84 210
|
||||
7 65 68 140 210
|
||||
3 148 149 300 210
|
||||
Loading…
Add table
Add a link
Reference in a new issue