let count = 3
for (i, answer) in answers.enumerated() {
if _answers.isEmpty || i % count == 0 {
_answers.append([answer])
} else {
_answers[i / count].append(answer)
}
}
// 6.5.1 < 7.0
let flag = "6.5.1".compare("7.0", options: .numeric) == .orderedAscending
/// true
// 6.5.1 > 7.0
let flag = "6.5.1".compare("7.0", options: .numeric) == .orderedDescending
// false
(a + b - 1) / b
func value(from str: String) -> Int {
var result = 0
let zeroAscii = Character("0").asciiValue ?? 0
let aAscii = Character("a").asciiValue ?? 0
for char in str {
result = result * 16 % 100
if "0"..."9" ~= char {
result += Int(char.asciiValue.flatMap { $0 - zeroAscii } ?? 0)
} else if "a"..."f" ~= char {
result += Int(char.asciiValue.flatMap { $0 - aAscii + 10 } ?? 0)
}
}
return result
}
func hexMod(with str: String) -> Int {
let target = [
76,
16,
56,
96,
36
]
var result = 0
for (i, char) in str.reversed().enumerated() {
let number = Int("\(char)", radix: 16)!
if i == 0 {
result = number
continue
}
let idx = i % 5
let n = target[idx]
result += (number * n % 100)
}
result %= 100
return result
}
- (int)calculateHexMod:(NSString *)hexString {
static NSArray <NSNumber *>*targets;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
targets = @[
@76,
@16,
@56,
@96,
@36
];
});
int result = 0;
NSInteger strLength = hexString.length;
for (int i = 0; i < strLength; i++) {
NSString *subStr = [hexString substringWithRange:NSMakeRange(strLength - 1 - i, 1)];
int number = (int)strtoull([subStr UTF8String], NULL, 16);
if (i == 0) {
result = number;
continue;
}
int idx = i % 5;
int n = targets[idx].intValue;
result += (number * n);
}
result %= 100;
return result;
}
let a = [1, 2, 3, 4]
var b = [1, 2, 3, 4]
print(address(o: a))
a.withUnsafeBufferPointer {
print($0)
}
b.withUnsafeBufferPointer {
print($0)
}
b.append(5)
b.withUnsafeBufferPointer {
print($0)
}
func address(o: UnsafeRawPointer) -> String {
return String(format: "%018p", Int(bitPattern: o))
}
_bindStatusButton.transform = CGAffineTransformMakeScale(-1.0, 1.0);
_bindStatusButton.titleLabel.transform = CGAffineTransformMakeScale(-1.0, 1.0);
_bindStatusButton.imageView.transform = CGAffineTransformMakeScale(-1.0, 1.0);