Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Arcade/Intro/isLucky.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// https://codefights.com/arcade/intro/level-3/3AdBC97QNuhF6RwsQ

func isLucky(n: Int) -> Bool {
var a = String(n).characters.map { Int("\($0)")! }, h = a.count / 2
var h1 = a[0..<h].reduce(0, combine: +)
var h2 = a[h..<2*h].reduce(0, combine: +)

let a = String(n).map { Int("\($0)")! }, h = a.count / 2
let h1 = a[0..<h].reduce(0) {
$0 + $1
}
let h2 = a[h..<2*h].reduce(0) {$0 + $1}
print(a)
return h1 == h2
}