### Cosmetics

parent 2f56ab23
 ... ... @@ -5625,14 +5625,14 @@ try (final Scanner scan = new Scanner(System.in)) { ) which could be ruled out beforehand easily rather then creating and filtering them. Do we really need three nested loops? which could be easily ruled out beforehand rather then creating and filtering them. Do we really need three nested loops? Also triples having identical values but in a different order like (40, 399, 401) and (40, 401, 399) are equivalent. For this reason we may consider only triples being ordered by size. Also triples having identical values in different order like (40, 399, 401) and (40, 401, 399) are equivalent. For this reason we may consider only triples being ordered by value. So the problem can be stated to find the set of all triples ... ... @@ -5862,7 +5862,8 @@ for (int a = 1; a <= sum / 3; a++) { } } This leaves us with eight triples: We've reduced the original code from three to just two nested loops. Running this code reveals eight triples: (40, 399, 401) (56, 390, 394) ... ... @@ -5874,10 +5875,10 @@ for (int a = 1; a <= sum / 3; a++) { (240, 252, 348) The above code can be simplified even further. We introduce the variable s being shorthand for sum in our code. The inner for loop so far starts with a value of introduce a variable s being shorthand for sum. The inner for loop so far starts with a value of b ... ... @@ -5914,9 +5915,9 @@ for (int a = 1; a <= sum / 3; a++) { language="java">c will be decremented by the same amount. Regarding the n-th step of the inner for loop we thus look for a value of n so that the following equation becomes true: Regarding the n-th step of the inner loop we thus look for a value of n so that the following equation becomes true: ... ... @@ -6089,8 +6090,8 @@ for (int a = 1; a <= sum / 3; a++) { So for each given value of a there is either no or exactly one possible solution (since n is of integer type). Our inner nested loop becomes obsolete. language="java">n is of integer type). This way the inner loop becomes obsolete. The above equation must hold for integer arithmetic leaving no fractional remainder. We introduce two variables ... ...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!