-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathjim.swift
executable file
·104 lines (80 loc) · 1.89 KB
/
jim.swift
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/swift
import Foundation
class NestA {
class NestB {
class NestC {
init(_ a: String) {
self.ABC = [""]
}
let ABC:[String]
}
}
}
class State {
init(_ affairs:[String:AnyObject]) {
self.💩 = affairs
}
func mutate(_ like:(([String:AnyObject]) -> [String:AnyObject])) -> State {
return State(like(self.💩))
}
var description:String {
return 💩.description
}
private
let 💩:[String:AnyObject]
}
protocol Aggitatable {
var state:State { get set }
}
class Aggitator {
static let attributes:[String] = ["FartCapacitance", "ElectrostaticReactance", "ElectrostaticResistance", "HealthPoints"]
var aggitatees:[Aggitatable]
init(_ aggitatee: Aggitatable) {
self.aggitatees = [aggitatee]
}
init(_ aggitatees: [Aggitatable]) {
self.aggitatees = aggitatees
}
func aggitate(_ like:((Aggitatable) -> Aggitatable)) -> [Aggitatable] {
for (index, _) in aggitatees.enumerated() {
aggitatees[index] = like(aggitatees[index])
}
return aggitatees
}
}
class Max : Aggitatable, CustomStringConvertible {
var state:State
var description:String {
return self.state.description
}
required init(_ state:State = State([:])) {
self.state = state
}
}
func main() {
var max = Max()
let agg = Aggitator(max)
let 😂 = { (aggitatee: Aggitatable) -> Aggitatable in
if let max = aggitatee as? Max {
return type(of:max).init(max.state.mutate() { (before) in
var after = before
let random = Int(arc4random_uniform(UInt32(Aggitator.attributes.count)))
if random >= before.count {
after[Aggitator.attributes[random]] = arc4random_uniform(100) as AnyObject
} else if random < before.count {
after[Aggitator.attributes[random]] = nil
}
return after
})
} else {
return aggitatee
}
}
print(max)
let 🐸s = agg.aggitate(😂)
if let 🐸 = 🐸s[0] as? Max {
max = 🐸
}
print(max)
}
main()