Skip to content

Commit f35172d

Browse files
committed
🟢 Solve problem 3110
1 parent becb74e commit f35172d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

‎swift/3110.swift‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
func scoreOfString(_ s: String) -> Int {
2+
var score = 0
3+
4+
let characters = Array(s)
5+
for i in 0..<characters.count - 1 {
6+
let current = characters[i].asciiValue
7+
let next = characters[i + 1].asciiValue
8+
let diff = abs(Int(current!) - Int(next!))
9+
score += diff
10+
}
11+
12+
return score
13+
}
14+
15+
let bateryOfTests: [Bool] = [
16+
scoreOfString("zaz") == 50,
17+
scoreOfString("hello") == 13
18+
]
19+
20+
if bateryOfTests.allSatisfy({ $0 == true }) {
21+
print("All tests passed")
22+
} else {
23+
print("Some tests failed")
24+
}

0 commit comments

Comments
 (0)