/** static factory constructor */ public static NumberRange fromStartStop(long start, long stop) { return new NumberRange(start, stop); }
Examples: start=10 stop=12 then size=3 The size is 3 because the range includes: 10, 11 and 12 start=20 stop=20 then size=1 The size is 1 because the range includes: 20
public String toString() { return String.format("[%d, %d]", this.getStart(), this.getStop()); }
//Example Usage NumberRange range = new NumberRange(10, 20); println('Start: ' + range.getStart()); //Start: 10
//Example Usage NumberRange range = new NumberRange(10, 20); println('Stop ' + range.getStop()); //Stop: 10
//Example Usage NumberRange range = new NumberRange(10, 20); println('Start: ' + range.getStart()); //Start: 10 range.setStart(1000); println('Start: ' + range.getStart()); //Start: 1000
//Example Usage NumberRange range = new NumberRange(10, 20); println('Stop: ' + range.getStop()); //Stop: 10 range.setStop(5000); println('Stop: ' + range.getStop()); //Stop: 5000
Examples: start=10 stop=12 then size=3 The size is 3 because the range includes: 10, 11 and 12 start=20 stop=20 then size=1 The size is 1 because the range includes: 20
Math.max(a, b); //returns max of a and b Math.min(a, b); //returns min of a and b
Examples: | ||
---|---|---|
Start | Stop | Primes Count |
1 | 10 | 4 |
1 | 100 | 25 |
1 | 1000 | 168 |
mustBeBoth | Description |
---|---|
true | Return count of nums in our range that are divisible by both factor1 AND factor2 |
false | Return count of nums in our range that are divisible by both factor1 OR factor2 |
Range Start | Range Stop | factor1 | factor2 | mustBeBoth | countDivisibleBy (Resulting Count) |
---|---|---|---|---|---|
1 | 10 | 2 | 5 | true | 1 |
1 | 10 | 2 | 5 | false | 6 |
1 | 1000 | 2 | 5 | true | 100 |
1 | 1000 | 2 | 5 | false | 600 |
Range Start | Range Stop | Primes Sum |
---|---|---|
1 | 10 | 17 |
1 | 100 | 1,060 |
1 | 1000 | 76,127 |
4 (count = 1)
14, 15, 16 (count = 3)
Start | Stop | Largest Prime Gap |
---|---|---|
3 | 3 | 0 |
4 | 4 | 0 |
1 | 10 | 1 |
10 | 20 | 3 |
1 | 1000 | 19 |
10,000 | 11,000 | 31 |
100,000 | 101,000 | 53 |
prime1 + "-" + prime2
13-17
Start | Stop | Largest Prime Gap Pair |
---|---|---|
1 | 10 | 3-5 |
1 | 20 | 7-11 |
10 | 20 | 13-17 |
public String getSummary() { String summary = ""; String sep = System.lineSeparator(); summary += "Start: " + this.getStart() + sep; summary += "Stop: " + this.getStop() + sep; summary += "Prime Count: " + this.countPrimes() + sep; summary += "Odd Count: " + this.oddCount() + sep; //TODO return summary; }