-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprobability.dart
86 lines (70 loc) · 2.27 KB
/
probability.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import 'dart:math';
import 'dart:async';
void main() {
var questions = [];
var repeated = 0;
var roundRepeated = 0;
var previousQuestion = "";
var roundNumber = 1000000000;
List<int> occurrence = [];
for (var x = 0; x < roundNumber; x++){
var question = createQuestion();
if(question.toString() == previousQuestion.toString()){
repeated++;
roundRepeated++;
}
previousQuestion = question;
questions.add(question);
if(x % 10 == 0){
occurrence.add(roundRepeated);
roundRepeated = 0;
questions.clear();
}
}
var maxRepeated = occurrence.reduce(max);
print("Maximum number of repeated questions: " + maxRepeated.toString());
var occurrenceCount = 0;
for (var y = 0; y < occurrence.length; y++){
if(occurrence[y] == maxRepeated){
occurrenceCount++;
}
}
print("Number of times max number was encountered: "
+ occurrenceCount.toString());
print("Percentage of rounds with a lot of repeated questions: "
+ ((occurrenceCount/(roundNumber/10))*100).toString() + "%");
print("Total number of repeated questions: "
+ repeated.toString());
}
createQuestion() {
Random random = new Random();
String question = "";
int firstNumber = 1 + random.nextInt(12 - 1);
int questionOperator = random.nextInt(3);
int secondNumber = 1 + random.nextInt(12 - 1);
if (questionOperator == 2) {
if (firstNumber == 1) {
secondNumber = 1;
} else {
secondNumber = 1 + random.nextInt(firstNumber - 1);
}
} else if (questionOperator == 1) {
var numberList = [];
for (var i = 1; i <= 12; i++) {
if (firstNumber % i == 0) {
numberList.add(i);
}
}
secondNumber = numberList[random.nextInt(numberList.length)];
}
if (questionOperator == 0) {
question = firstNumber.toString() + " x " + secondNumber.toString();
} else if (questionOperator == 1) {
question = firstNumber.toString() + " ÷ " + secondNumber.toString();
} else if (questionOperator == 2) {
question = firstNumber.toString() + " - " + secondNumber.toString();
} else {
question = firstNumber.toString() + " + " + secondNumber.toString();
}
return question;
}