1
$\begingroup$
     Table[g = 
     Map[Sort, 
     Solve[a + b + c == L && a^2 + b^2 == c^2 && a > 0 && b > 0 && 
     c > 0, Integers] // Values] // DeleteDuplicates, {L, 12, 
     3000}]
     Count[g]

this is the question, its suppose to be written in mathematica but this one doesnt work..

L is the length for the wire and I want to know the number of values of L that is less than 3000 that exactly one integer sided right angle triangle can be formed.

$\endgroup$

2 Answers 2

2
$\begingroup$
Clear["Global`*"]

Avoid redundant solutions by requiring that a, b, and c be ordered

eqns = a + b + c == L && a^2 + b^2 == c^2 && 0 < a <= b < c && 0 < L < 3000;

solAll = Solve[eqns, {a, b, c, L}, Integers];

Verifying the solutions

And @@ (eqns /. solAll)

(* True *)

Eliminating values of L with more than one solution

solSingles = Cases[GatherBy[solAll, Last], x_?(Length[#] == 1 &) :> x[[1]]];

The number of solutions before and after filtering

Length /@ {solAll, solSingles}

(* {1201, 332} *)

Looking at solutions for the 20 largest values of L

SortBy[solSingles, Last][[-20 ;;]]

(* {{a -> 708, b -> 944, c -> 1180, L -> 2832}, {a -> 660, b -> 989, c -> 1189, 
  L -> 2838}, {a -> 568, b -> 1065, c -> 1207, L -> 2840}, {a -> 441, 
  b -> 1160, c -> 1241, L -> 2842}, {a -> 711, b -> 948, c -> 1185, 
  L -> 2844}, {a -> 736, b -> 930, c -> 1186, L -> 2852}, {a -> 53, b -> 1404,
   c -> 1405, L -> 2862}, {a -> 717, b -> 956, c -> 1195, 
  L -> 2868}, {a -> 148, b -> 1365, c -> 1373, L -> 2886}, {a -> 723, 
  b -> 964, c -> 1205, L -> 2892}, {a -> 400, b -> 1218, c -> 1282, 
  L -> 2900}, {a -> 485, b -> 1164, c -> 1261, L -> 2910}, {a -> 705, 
  b -> 992, c -> 1217, L -> 2914}, {a -> 729, b -> 972, c -> 1215, 
  L -> 2916}, {a -> 584, b -> 1095, c -> 1241, L -> 2920}, {a -> 612, 
  b -> 1075, c -> 1237, L -> 2924}, {a -> 732, b -> 976, c -> 1220, 
  L -> 2928}, {a -> 828, b -> 896, c -> 1220, L -> 2944}, {a -> 747, b -> 996,
   c -> 1245, L -> 2988}, {a -> 345, b -> 1300, c -> 1345, L -> 2990}} *)
$\endgroup$
1
$\begingroup$

I think you mean to do this?

g = Table[
  Map[Sort, 
    Solve[a + b + c == L && a^2 + b^2 == c^2 && a > 0 && b > 0 && 
       c > 0, Integers] // Values] // DeleteDuplicates, {L, 12, 1500}];

DeleteCases[g, {}] // Length
$\endgroup$
2
  • $\begingroup$ thanks! how do I count how many elements there are? i think the output should be around 16100 $\endgroup$
    – Aran
    Commented Oct 18, 2020 at 19:53
  • $\begingroup$ The DeleteCases[g, {}] // Length should it. I know 1500 will take sometime, so try like 100, it returns 14, which I think is correct? $\endgroup$
    – James Khan
    Commented Oct 19, 2020 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.