Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
57
Task/Heronian-triangles/Java/heronian-triangles-1.java
Normal file
57
Task/Heronian-triangles/Java/heronian-triangles-1.java
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import java.util.ArrayList;
|
||||
public class Heron {
|
||||
public static void main(String[] args) {
|
||||
ArrayList<int[]> list = new ArrayList<int[]>();
|
||||
for(int c = 1; c <= 200; c++){
|
||||
for(int b = 1; b <= c; b++){
|
||||
for(int a = 1; a <= b; a++){
|
||||
if(gcd(gcd(a, b), c) == 1 && isHeron(heronArea(a, b, c)
|
||||
list.add(new int[]{a, b, c, a + b + c, (int)heronArea(a, b, c)});
|
||||
}
|
||||
}
|
||||
}
|
||||
sort(list);
|
||||
System.out.printf("Number of primitive Heronian triangles with sides up to 200: %d\n\nFirst ten when ordered by increasing area, then perimeter:\nSides Perimeter Area", list.size());
|
||||
for(int i = 0; i < 10; i++){
|
||||
System.out.printf("\n%d x %d x %d %d %d",list.get(i)[0], list.get(i)[1], list.get(i)[2], list.get(i)[3], list.get(i)[4]);
|
||||
}
|
||||
System.out.printf("\n\nArea = 210\nSides Perimeter Area");
|
||||
for(int i = 0; i < list.size(); i++){
|
||||
if(list.get(i)[4] == 210)
|
||||
System.out.printf("\n%d x %d x %d %d %d",list.get(i)[0], list.get(i)[1], list.get(i)[2], list.get(i)[3], list.get(i)[4]);
|
||||
}
|
||||
}
|
||||
public static double heronArea(int a, int b, int c){
|
||||
double s = (a + b + c)/ 2f;
|
||||
return Math.sqrt(s *(s -a)*(s - b)*(s - c));
|
||||
}
|
||||
public static boolean isHeron(double h){
|
||||
return h % 1 == 0 && h > 0;
|
||||
}
|
||||
public static int gcd(int a, int b){
|
||||
int leftover = 1, dividend = a > b ? a : b, divisor = a > b ? b : a;
|
||||
while(leftover != 0){
|
||||
leftover = dividend % divisor;
|
||||
if(leftover > 0){
|
||||
dividend = divisor;
|
||||
divisor = leftover;
|
||||
}
|
||||
}
|
||||
return divisor;
|
||||
}
|
||||
public static void sort(ArrayList<int[]> list){
|
||||
boolean swapped = true;
|
||||
int[] temp;
|
||||
while(swapped){
|
||||
swapped = false;
|
||||
for(int i = 1; i < list.size(); i++){
|
||||
if(list.get(i)[4] < list.get(i - 1)[4] || list.get(i)[4] == list.get(i - 1)[4] && list.get(i)[3] < list.get(i - 1)[3]){
|
||||
temp = list.get(i);
|
||||
list.set(i, list.get(i - 1));
|
||||
list.set(i - 1, temp);
|
||||
swapped = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
23
Task/Heronian-triangles/Java/heronian-triangles-2.java
Normal file
23
Task/Heronian-triangles/Java/heronian-triangles-2.java
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
Number of primitive Heronian triangles with sides up to 200: 517
|
||||
|
||||
First ten when ordered by increasing area, then perimeter:
|
||||
Sides Perimeter Area
|
||||
3 x 4 x 5 12 6
|
||||
5 x 5 x 6 16 12
|
||||
5 x 5 x 8 18 12
|
||||
4 x 13 x 15 32 24
|
||||
5 x 12 x 13 30 30
|
||||
9 x 10 x 17 36 36
|
||||
3 x 25 x 26 54 36
|
||||
7 x 15 x 20 42 42
|
||||
10 x 13 x 13 36 60
|
||||
8 x 15 x 17 40 60
|
||||
|
||||
Area = 210
|
||||
Sides Perimeter Area
|
||||
17 x 25 x 28 70 210
|
||||
20 x 21 x 29 70 210
|
||||
12 x 35 x 37 84 210
|
||||
17 x 28 x 39 84 210
|
||||
7 x 65 x 68 140 210
|
||||
3 x 148 x 149 300 210
|
||||
Loading…
Add table
Add a link
Reference in a new issue