-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandomness.swift
More file actions
82 lines (67 loc) · 2.93 KB
/
Copy pathrandomness.swift
File metadata and controls
82 lines (67 loc) · 2.93 KB
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
var winCountInt = 0
var winCountString = 0
var tieCount = 0
for _ in 1...100 {
let stringList = ["This is a long string","This is a verrrrrryyy long string","This is a verrrrrryyy longgggggggggggg string This is a verrrrrryyy longgggggggggggg string This is a verrrrrryyy longgggggggggggg string This is a verrrrrryyy longgggggggggggg string"]
var stringData: [String] = []
for _ in 1...10000 {
stringData.append(stringList.randomElement()!)
}
var longestConsecutiveChain = 0
var longestConsecutiveChainString = "string"
var lastElement = "string"
var currentChain = 0
for item in stringData {
if item == lastElement {
currentChain += 1
} else {
currentChain = 0
}
if currentChain > longestConsecutiveChain{
longestConsecutiveChain = currentChain
longestConsecutiveChainString = item
}
lastElement = item
}
print("Strings")
print("Data Set Length: \(stringData.count)")
print("Longest chain string: \(longestConsecutiveChainString)")
print("Longest chain count: \(longestConsecutiveChain)")
var intData: [Int] = []
for _ in 1...10000 {
intData.append(Int.random(in: 1...3))
}
var longestConsecutiveIntChain = 0
var longestConsecutiveIntChainInt = 0
var lastIntElement = 0
var currentIntChain = 0
for item in intData {
if item == lastIntElement {
currentIntChain += 1
} else {
currentIntChain = 0
}
if currentIntChain > longestConsecutiveIntChain{
longestConsecutiveIntChain = currentIntChain
longestConsecutiveIntChainInt = item
}
lastIntElement = item
}
print("\nIntegers")
print("Data Set Length: \(intData.count)")
print("Longest chain int: \(longestConsecutiveIntChainInt)")
print("Longest chain count: \(longestConsecutiveIntChain)")
if longestConsecutiveIntChain > longestConsecutiveChain {
print("Int longer")
winCountInt += 1
} else if longestConsecutiveIntChain < longestConsecutiveChain {
print("String longer")
winCountString += 1
} else {
print("TIE")
tieCount += 1
}
}
print("Win count strings \(winCountString)")
print("Win count ints \(winCountInt)")
print("Ties \(tieCount)")