Created
December 4, 2019 18:44
-
-
Save groob/839944a64e03541fd323f3fcf0278995 to your computer and use it in GitHub Desktop.
Revisions
-
groob created this gist
Dec 4, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ extension Int { func digits() -> [Int] { var newN = self var result: [Int] = [] while newN > 0 { let r = newN % 10 newN = newN / 10 result.append(r) } result.reverse() return result } } func isValid(_ digits: [Int]) -> Bool { return digits == digits.sorted() && digits.contains { d in digits.filter { $0 == d }.count == 2 } } let result = (136760...595730) .map { $0.digits() } .filter { isValid($0) } .count print(result)