Skip to content

Commit ea6c74c

Browse files
committed
fixed game №4 Progression
1 parent 4080321 commit ea6c74c

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

app/src/main/java/hexlet/code/Games.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.util.Random;
44
import java.util.Arrays; // for game №3 calc
55
import java.util.List; // for game №3 calc
6-
import java.math.BigInteger; // for game №4 gcd
6+
import java.math.BigInteger;// for game №4 gcd
77

88
public class Games {
99

@@ -102,23 +102,31 @@ public static int progression() {
102102

103103
for (var i = 0; i < Engine.rounds; i++) {
104104

105-
int[] array = new int[10];
105+
int arrayLength = random.nextInt(5) + 5;
106+
int[] array = new int[arrayLength];
106107

107108
int step = random.nextInt(9) + 1;
108109
int start = random.nextInt(14) + 1;
109110

110-
for (int j = 0; j < 10; j++) {
111+
for (int j = 0; j < arrayLength; j++) {
111112
array[j] = start + j * step;
112113
}
113114

114-
int indexFromArray = random.nextInt(9);
115+
int indexFromArray = random.nextInt(arrayLength - 1);
116+
115117
String arrayToString = Arrays.toString(array);
116-
String hideNumber = arrayToString.replaceAll(String.valueOf(array[indexFromArray]), "..");
117-
question[i] = hideNumber;
118+
String elementToHide = String.valueOf(array[indexFromArray]);
119+
String oneElement = "\\b" + elementToHide + "\\b";
120+
String arrayHideNumber = arrayToString.replaceFirst(oneElement, "..");
121+
arrayHideNumber = arrayHideNumber.replace("[", "").replace("]", "")
122+
.replace(",", "");
123+
124+
question[i] = arrayHideNumber;
118125
correctAnswer[i] = String.valueOf(array[indexFromArray]);
119126

120127
}
121128
Engine.skeletonOfGames(mainGameQuestion, question, correctAnswer);
122129
return 0;
123130
}
124131
}
132+

0 commit comments

Comments
 (0)