Metadata
Key | Value |
---|---|
engine | mlx |
prompt | completion |
temp | 0.2 |
top_p | 0.95 |
max_new_tokens | 1024 |
n_completions | 10 |
Solutions
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
if abs(numbers[i] - numbers[j]) < threshold {
return true
}
}
}
return false
}
```swift
// Check if in given array of numbers, are any two numbers closer to each other than
// given threshold.
// hasCloseElements(numbers: [1.0, 2.0, 3.0], threshold: 0.5) == false
// hasCloseElements(numbers: [1.0, 2.8, 3.0, 4.0, 5.0, 2.0], threshold: 0.3) == true
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
if abs(numbers[i] - numbers[j]) < threshold {
return true
}
}
}
return false
}
```
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
var minDistance = Double.infinity
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
let distance = abs(numbers[i] - numbers[j])
if distance < minDistance {
minDistance = distance
}
}
}
return minDistance < threshold
}
```swift
// Check if in given array of numbers, are any two numbers closer to each other than
// given threshold.
// hasCloseElements(numbers: [1.0, 2.0, 3.0], threshold: 0.5) == false
// hasCloseElements(numbers: [1.0, 2.8, 3.0, 4.0, 5.0, 2.0], threshold: 0.3) == true
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
var minDistance = Double.infinity
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
let distance = abs(numbers[i] - numbers[j])
if distance < minDistance {
minDistance = distance
}
}
}
return minDistance < threshold
}
```
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
var sortedNumbers = numbers.sorted()
var i = 0
var j = 1
while i < sortedNumbers.count - 1 {
if sortedNumbers[j] - sortedNumbers[i] < threshold {
return true
}
i += 1
j += 1
}
return false
}
```swift
// Check if in given array of numbers, are any two numbers closer to each other than
// given threshold.
// hasCloseElements(numbers: [1.0, 2.0, 3.0], threshold: 0.5) == false
// hasCloseElements(numbers: [1.0, 2.8, 3.0, 4.0, 5.0, 2.0], threshold: 0.3) == true
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
var sortedNumbers = numbers.sorted()
var i = 0
var j = 1
while i < sortedNumbers.count - 1 {
if sortedNumbers[j] - sortedNumbers[i] < threshold {
return true
}
i += 1
j += 1
}
return false
}
```
var sortedNumbers = numbers.sorted() // variable 'sortedNumbers' was never mutated; consider changing to 'let' constant
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
var minDistance = Double.infinity
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
let distance = abs(numbers[i] - numbers[j])
if distance < minDistance {
minDistance = distance
}
}
}
return minDistance < threshold
}
```swift
// Check if in given array of numbers, are any two numbers closer to each other than
// given threshold.
// hasCloseElements(numbers: [1.0, 2.0, 3.0], threshold: 0.5) == false
// hasCloseElements(numbers: [1.0, 2.8, 3.0, 4.0, 5.0, 2.0], threshold: 0.3) == true
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
var minDistance = Double.infinity
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
let distance = abs(numbers[i] - numbers[j])
if distance < minDistance {
minDistance = distance
}
}
}
return minDistance < threshold
}
```
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
if abs(numbers[i] - numbers[j]) < threshold {
return true
}
}
}
return false
}
```swift
// Check if in given array of numbers, are any two numbers closer to each other than
// given threshold.
// hasCloseElements(numbers: [1.0, 2.0, 3.0], threshold: 0.5) == false
// hasCloseElements(numbers: [1.0, 2.8, 3.0, 4.0, 5.0, 2.0], threshold: 0.3) == true
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
if abs(numbers[i] - numbers[j]) < threshold {
return true
}
}
}
return false
}
```
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
if abs(numbers[i] - numbers[j]) < threshold {
return true
}
}
}
return false
}
```swift
// Check if in given array of numbers, are any two numbers closer to each other than
// given threshold.
// hasCloseElements(numbers: [1.0, 2.0, 3.0], threshold: 0.5) == false
// hasCloseElements(numbers: [1.0, 2.8, 3.0, 4.0, 5.0, 2.0], threshold: 0.3) == true
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
if abs(numbers[i] - numbers[j]) < threshold {
return true
}
}
}
return false
}
```
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
var sortedNumbers = numbers.sorted()
for i in 0..<sortedNumbers.count - 1 {
if abs(sortedNumbers[i] - sortedNumbers[i + 1]) < threshold {
return true
}
}
return false
}
```swift
// Check if in given array of numbers, are any two numbers closer to each other than
// given threshold.
// hasCloseElements(numbers: [1.0, 2.0, 3.0], threshold: 0.5) == false
// hasCloseElements(numbers: [1.0, 2.8, 3.0, 4.0, 5.0, 2.0], threshold: 0.3) == true
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
var sortedNumbers = numbers.sorted()
for i in 0..<sortedNumbers.count - 1 {
if abs(sortedNumbers[i] - sortedNumbers[i + 1]) < threshold {
return true
}
}
return false
}
```
var sortedNumbers = numbers.sorted() // variable 'sortedNumbers' was never mutated; consider changing to 'let' constant
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
if abs(numbers[i] - numbers[j]) < threshold {
return true
}
}
}
return false
}
```swift
// Check if in given array of numbers, are any two numbers closer to each other than
// given threshold.
// hasCloseElements(numbers: [1.0, 2.0, 3.0], threshold: 0.5) == false
// hasCloseElements(numbers: [1.0, 2.8, 3.0, 4.0, 5.0, 2.0], threshold: 0.3) == true
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
if abs(numbers[i] - numbers[j]) < threshold {
return true
}
}
}
return false
}
```
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
if abs(numbers[i] - numbers[j]) < threshold {
return true
}
}
}
return false
}
```swift
// Check if in given array of numbers, are any two numbers closer to each other than
// given threshold.
// hasCloseElements(numbers: [1.0, 2.0, 3.0], threshold: 0.5) == false
// hasCloseElements(numbers: [1.0, 2.8, 3.0, 4.0, 5.0, 2.0], threshold: 0.3) == true
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
if abs(numbers[i] - numbers[j]) < threshold {
return true
}
}
}
return false
}
```
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
if abs(numbers[i] - numbers[j]) < threshold {
return true
}
}
}
return false
}
```swift
// Check if in given array of numbers, are any two numbers closer to each other than
// given threshold.
// hasCloseElements(numbers: [1.0, 2.0, 3.0], threshold: 0.5) == false
// hasCloseElements(numbers: [1.0, 2.8, 3.0, 4.0, 5.0, 2.0], threshold: 0.3) == true
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
if abs(numbers[i] - numbers[j]) < threshold {
return true
}
}
}
return false
}
```
func separateParenGroups(parenString: String) -> [String] {
// TODO: Implement this function
}
```swift
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// separateParenGroups(parenString: "( ) (( )) (( )( ))") == ["()", "(())", "(()())"]
func separateParenGroups(parenString: String) -> [String] {
// TODO: Implement this function
}
```
} // missing return in global function expected to return '[String]'
func separateParenGroups(parenString: String) -> [String] {
// TODO: Implement this function
}
```swift
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// separateParenGroups(parenString: "( ) (( )) (( )( ))") == ["()", "(())", "(()())"]
func separateParenGroups(parenString: String) -> [String] {
// TODO: Implement this function
}
```
} // missing return in global function expected to return '[String]'
func separateParenGroups(parenString: String) -> [String] {
// Your code here
}
```swift
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// separateParenGroups(parenString: "( ) (( )) (( )( ))") == ["()", "(())", "(()())"]
func separateParenGroups(parenString: String) -> [String] {
// Your code here
}
```
} // missing return in global function expected to return '[String]'
func separateParenGroups(parenString: String) -> [String] {
// Your code here
}
```swift
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// separateParenGroups(parenString: "( ) (( )) (( )( ))") == ["()", "(())", "(()())"]
func separateParenGroups(parenString: String) -> [String] {
// Your code here
}
```
} // missing return in global function expected to return '[String]'
func separateParenGroups(parenString: String) -> [String] {
var result = [String]()
var stack = [String]()
var current = ""
for char in parenString {
if char == "(" {
if!current.isEmpty {
result.append(current)
current = ""
}
stack.append(current)
current = ""
} else if char == ")" {
if!current.isEmpty {
result.append(current)
current = ""
}
current = stack.removeLast() + current
} else {
current.append(char)
}
}
if!current.isEmpty {
result.append(current)
}
return result
}
```swift
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// separateParenGroups(parenString: "( ) (( )) (( )( ))") == ["()", "(())", "(()())"]
func separateParenGroups(parenString: String) -> [String] {
var result = [String]()
var stack = [String]()
var current = ""
for char in parenString {
if char == "(" {
if!current.isEmpty {
result.append(current)
current = ""
}
stack.append(current)
current = ""
} else if char == ")" {
if!current.isEmpty {
result.append(current)
current = ""
}
current = stack.removeLast() + current
} else {
current.append(char)
}
}
if!current.isEmpty {
result.append(current)
}
return result
}
```
if!current.isEmpty { // expected expression, var, or let in 'if' condition
if!current.isEmpty { // expected expression, var, or let in 'if' condition
if!current.isEmpty { // expected expression, var, or let in 'if' condition
func separateParenGroups(parenString: String) -> [String] {
// Your code here
}
```swift
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// separateParenGroups(parenString: "( ) (( )) (( )( ))") == ["()", "(())", "(()())"]
func separateParenGroups(parenString: String) -> [String] {
// Your code here
}
```
} // missing return in global function expected to return '[String]'
func separateParenGroups(parenString: String) -> [String] {
// Your code here
}
```swift
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// separateParenGroups(parenString: "( ) (( )) (( )( ))") == ["()", "(())", "(()())"]
func separateParenGroups(parenString: String) -> [String] {
// Your code here
}
```
} // missing return in global function expected to return '[String]'
func separateParenGroups(parenString: String) -> [String] {
// TODO: implement this function
}
```swift
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// separateParenGroups(parenString: "( ) (( )) (( )( ))") == ["()", "(())", "(()())"]
func separateParenGroups(parenString: String) -> [String] {
// TODO: implement this function
}
```
} // missing return in global function expected to return '[String]'
func separateParenGroups(parenString: String) -> [String] {
// TODO: Implement this function
}
```swift
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// separateParenGroups(parenString: "( ) (( )) (( )( ))") == ["()", "(())", "(()())"]
func separateParenGroups(parenString: String) -> [String] {
// TODO: Implement this function
}
```
} // missing return in global function expected to return '[String]'
func separateParenGroups(parenString: String) -> [String] {
// Your code here
}
```swift
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// separateParenGroups(parenString: "( ) (( )) (( )( ))") == ["()", "(())", "(()())"]
func separateParenGroups(parenString: String) -> [String] {
// Your code here
}
```
} // missing return in global function expected to return '[String]'
func truncateNumber(number: Double) -> Double {
return number - floor(number)
}
```swift
// Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
// Return the decimal part of the number.
// truncateNumber(number: 3.5) == 0.5
func truncateNumber(number: Double) -> Double {
return number - floor(number)
}
```
func truncateNumber(number: Double) -> Double {
let truncatedNumber = number - Double(Int(number))
return truncatedNumber
}
```swift
// Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
// Return the decimal part of the number.
// truncateNumber(number: 3.5) == 0.5
func truncateNumber(number: Double) -> Double {
let truncatedNumber = number - Double(Int(number))
return truncatedNumber
}
```
func truncateNumber(number: Double) -> Double {
return number - Double(Int(number))
}
```swift
// Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
// Return the decimal part of the number.
// truncateNumber(number: 3.5) == 0.5
func truncateNumber(number: Double) -> Double {
return number - Double(Int(number))
}
```
func truncateNumber(number: Double) -> Double {
let integerPart = Int(number)
let decimalPart = number - Double(integerPart)
return decimalPart
}
```swift
// Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
// Return the decimal part of the number.
// truncateNumber(number: 3.5) == 0.5
func truncateNumber(number: Double) -> Double {
let integerPart = Int(number)
let decimalPart = number - Double(integerPart)
return decimalPart
}
```
func truncateNumber(number: Double) -> Double {
return number - floor(number)
}
```swift
// Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
// Return the decimal part of the number.
// truncateNumber(number: 3.5) == 0.5
func truncateNumber(number: Double) -> Double {
return number - floor(number)
}
```
func truncateNumber(number: Double) -> Double {
return number - Double(Int(number))
}
```swift
// Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
// Return the decimal part of the number.
// truncateNumber(number: 3.5) == 0.5
func truncateNumber(number: Double) -> Double {
return number - Double(Int(number))
}
```
func truncateNumber(number: Double) -> Double {
let truncatedNumber = number - Double(Int(number))
return truncatedNumber
}
```swift
// Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
// Return the decimal part of the number.
// truncateNumber(number: 3.5) == 0.5
func truncateNumber(number: Double) -> Double {
let truncatedNumber = number - Double(Int(number))
return truncatedNumber
}
```
func truncateNumber(number: Double) -> Double {
return number - floor(number)
}
```swift
// Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
// Return the decimal part of the number.
// truncateNumber(number: 3.5) == 0.5
func truncateNumber(number: Double) -> Double {
return number - floor(number)
}
```
func truncateNumber(number: Double) -> Double {
let integerPart = Int(number)
let decimalPart = number - Double(integerPart)
return decimalPart
}
```swift
// Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
// Return the decimal part of the number.
// truncateNumber(number: 3.5) == 0.5
func truncateNumber(number: Double) -> Double {
let integerPart = Int(number)
let decimalPart = number - Double(integerPart)
return decimalPart
}
```
func truncateNumber(number: Double) -> Double {
let integerPart = Int(number)
let decimalPart = number - Double(integerPart)
return decimalPart
}
```swift
// Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
// Return the decimal part of the number.
// truncateNumber(number: 3.5) == 0.5
func truncateNumber(number: Double) -> Double {
let integerPart = Int(number)
let decimalPart = number - Double(integerPart)
return decimalPart
}
```
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```swift
// You're given an array of deposit and withdrawal operations on a bank account that starts with
// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
// at that point function should return true. Otherwise it should return false.
// belowZero(operations: [1, 2, 3]) == false
// belowZero(operations: [1, 2, -4, 5]) == true
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```swift
// You're given an array of deposit and withdrawal operations on a bank account that starts with
// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
// at that point function should return true. Otherwise it should return false.
// belowZero(operations: [1, 2, 3]) == false
// belowZero(operations: [1, 2, -4, 5]) == true
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```swift
// You're given an array of deposit and withdrawal operations on a bank account that starts with
// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
// at that point function should return true. Otherwise it should return false.
// belowZero(operations: [1, 2, 3]) == false
// belowZero(operations: [1, 2, -4, 5]) == true
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```swift
// You're given an array of deposit and withdrawal operations on a bank account that starts with
// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
// at that point function should return true. Otherwise it should return false.
// belowZero(operations: [1, 2, 3]) == false
// belowZero(operations: [1, 2, -4, 5]) == true
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```swift
// You're given an array of deposit and withdrawal operations on a bank account that starts with
// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
// at that point function should return true. Otherwise it should return false.
// belowZero(operations: [1, 2, 3]) == false
// belowZero(operations: [1, 2, -4, 5]) == true
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```swift
// You're given an array of deposit and withdrawal operations on a bank account that starts with
// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
// at that point function should return true. Otherwise it should return false.
// belowZero(operations: [1, 2, 3]) == false
// belowZero(operations: [1, 2, -4, 5]) == true
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```swift
// You're given an array of deposit and withdrawal operations on a bank account that starts with
// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
// at that point function should return true. Otherwise it should return false.
// belowZero(operations: [1, 2, 3]) == false
// belowZero(operations: [1, 2, -4, 5]) == true
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for op in operations {
balance += op
if balance < 0 {
return true
}
}
return false
}
```swift
// You're given an array of deposit and withdrawal operations on a bank account that starts with
// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
// at that point function should return true. Otherwise it should return false.
// belowZero(operations: [1, 2, 3]) == false
// belowZero(operations: [1, 2, -4, 5]) == true
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for op in operations {
balance += op
if balance < 0 {
return true
}
}
return false
}
```
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```swift
// You're given an array of deposit and withdrawal operations on a bank account that starts with
// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
// at that point function should return true. Otherwise it should return false.
// belowZero(operations: [1, 2, 3]) == false
// belowZero(operations: [1, 2, -4, 5]) == true
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```swift
// You're given an array of deposit and withdrawal operations on a bank account that starts with
// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
// at that point function should return true. Otherwise it should return false.
// belowZero(operations: [1, 2, 3]) == false
// belowZero(operations: [1, 2, -4, 5]) == true
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = mean(numbers: numbers)
let absoluteDeviations = numbers.map { abs($0 - mean) }
return mean(numbers: absoluteDeviations)
}
```swift
// For a given array of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute Deviation is the average absolute difference between each
// element and a centerpoint (mean in this case):
// MAD = average | x - x_mean |
// meanAbsoluteDeviation(numbers: [1.0, 2.0, 3.0, 4.0]) == 1.0
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = mean(numbers: numbers)
let absoluteDeviations = numbers.map { abs($0 - mean) }
return mean(numbers: absoluteDeviations)
}
```
let mean = mean(numbers: numbers) // use of local variable 'mean' before its declaration
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = mean(numbers: numbers)
let differences = numbers.map { abs($0 - mean) }
return mean(numbers: differences)
}
```swift
// For a given array of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute Deviation is the average absolute difference between each
// element and a centerpoint (mean in this case):
// MAD = average | x - x_mean |
// meanAbsoluteDeviation(numbers: [1.0, 2.0, 3.0, 4.0]) == 1.0
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = mean(numbers: numbers)
let differences = numbers.map { abs($0 - mean) }
return mean(numbers: differences)
}
```
let mean = mean(numbers: numbers) // use of local variable 'mean' before its declaration
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = mean(numbers: numbers)
let absoluteDeviations = numbers.map { abs($0 - mean) }
return mean(numbers: absoluteDeviations)
}
```swift
// For a given array of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute Deviation is the average absolute difference between each
// element and a centerpoint (mean in this case):
// MAD = average | x - x_mean |
// meanAbsoluteDeviation(numbers: [1.0, 2.0, 3.0, 4.0]) == 1.0
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = mean(numbers: numbers)
let absoluteDeviations = numbers.map { abs($0 - mean) }
return mean(numbers: absoluteDeviations)
}
```
let mean = mean(numbers: numbers) // use of local variable 'mean' before its declaration
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = mean(numbers: numbers)
let sum = numbers.reduce(0.0, { $0 + abs($1 - mean) })
return sum / Double(numbers.count)
}
```swift
// For a given array of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute Deviation is the average absolute difference between each
// element and a centerpoint (mean in this case):
// MAD = average | x - x_mean |
// meanAbsoluteDeviation(numbers: [1.0, 2.0, 3.0, 4.0]) == 1.0
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = mean(numbers: numbers)
let sum = numbers.reduce(0.0, { $0 + abs($1 - mean) })
return sum / Double(numbers.count)
}
```
let mean = mean(numbers: numbers) // use of local variable 'mean' before its declaration
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = mean(numbers: numbers)
let differences = numbers.map { abs($0 - mean) }
return mean(numbers: differences)
}
```swift
// For a given array of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute Deviation is the average absolute difference between each
// element and a centerpoint (mean in this case):
// MAD = average | x - x_mean |
// meanAbsoluteDeviation(numbers: [1.0, 2.0, 3.0, 4.0]) == 1.0
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = mean(numbers: numbers)
let differences = numbers.map { abs($0 - mean) }
return mean(numbers: differences)
}
```
let mean = mean(numbers: numbers) // use of local variable 'mean' before its declaration
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = mean(numbers: numbers)
let absoluteDeviations = numbers.map { abs($0 - mean) }
return mean(numbers: absoluteDeviations)
}
```swift
// For a given array of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute Deviation is the average absolute difference between each
// element and a centerpoint (mean in this case):
// MAD = average | x - x_mean |
// meanAbsoluteDeviation(numbers: [1.0, 2.0, 3.0, 4.0]) == 1.0
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = mean(numbers: numbers)
let absoluteDeviations = numbers.map { abs($0 - mean) }
return mean(numbers: absoluteDeviations)
}
```
let mean = mean(numbers: numbers) // use of local variable 'mean' before its declaration
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = mean(numbers: numbers)
let absoluteDeviations = numbers.map { abs($0 - mean) }
return mean(numbers: absoluteDeviations)
}
```swift
// For a given array of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute Deviation is the average absolute difference between each
// element and a centerpoint (mean in this case):
// MAD = average | x - x_mean |
// meanAbsoluteDeviation(numbers: [1.0, 2.0, 3.0, 4.0]) == 1.0
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = mean(numbers: numbers)
let absoluteDeviations = numbers.map { abs($0 - mean) }
return mean(numbers: absoluteDeviations)
}
```
let mean = mean(numbers: numbers) // use of local variable 'mean' before its declaration
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = mean(numbers: numbers)
let sum = numbers.reduce(0.0, { $0 + abs($1 - mean) })
return sum / Double(numbers.count)
}
```swift
// For a given array of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute Deviation is the average absolute difference between each
// element and a centerpoint (mean in this case):
// MAD = average | x - x_mean |
// meanAbsoluteDeviation(numbers: [1.0, 2.0, 3.0, 4.0]) == 1.0
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = mean(numbers: numbers)
let sum = numbers.reduce(0.0, { $0 + abs($1 - mean) })
return sum / Double(numbers.count)
}
```
let mean = mean(numbers: numbers) // use of local variable 'mean' before its declaration
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = mean(numbers: numbers)
let sum = numbers.reduce(0.0) { $0 + abs($1 - mean) }
return sum / Double(numbers.count)
}
```swift
// For a given array of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute Deviation is the average absolute difference between each
// element and a centerpoint (mean in this case):
// MAD = average | x - x_mean |
// meanAbsoluteDeviation(numbers: [1.0, 2.0, 3.0, 4.0]) == 1.0
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = mean(numbers: numbers)
let sum = numbers.reduce(0.0) { $0 + abs($1 - mean) }
return sum / Double(numbers.count)
}
```
let mean = mean(numbers: numbers) // use of local variable 'mean' before its declaration
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = mean(numbers: numbers)
let absoluteDeviations = numbers.map { abs($0 - mean) }
return mean(numbers: absoluteDeviations)
}
```swift
// For a given array of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute Deviation is the average absolute difference between each
// element and a centerpoint (mean in this case):
// MAD = average | x - x_mean |
// meanAbsoluteDeviation(numbers: [1.0, 2.0, 3.0, 4.0]) == 1.0
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = mean(numbers: numbers)
let absoluteDeviations = numbers.map { abs($0 - mean) }
return mean(numbers: absoluteDeviations)
}
```
let mean = mean(numbers: numbers) // use of local variable 'mean' before its declaration
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
var result: [Int] = []
for i in 0..<numbers.count {
result.append(numbers[i])
if i < numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```swift
// Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
// intersperse(numbers: [] as [Int], delimeter: 4) == [] as [Int]
// intersperse(numbers: [1, 2, 3], delimeter: 4) == [1, 4, 2, 4, 3]
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
var result: [Int] = []
for i in 0..<numbers.count {
result.append(numbers[i])
if i < numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
var result: [Int] = []
for (index, number) in numbers.enumerated() {
if index > 0 {
result.append(delimeter)
}
result.append(number)
}
return result
}
```swift
// Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
// intersperse(numbers: [] as [Int], delimeter: 4) == [] as [Int]
// intersperse(numbers: [1, 2, 3], delimeter: 4) == [1, 4, 2, 4, 3]
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
var result: [Int] = []
for (index, number) in numbers.enumerated() {
if index > 0 {
result.append(delimeter)
}
result.append(number)
}
return result
}
```
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
var result: [Int] = []
for (index, number) in numbers.enumerated() {
result.append(number)
if index < numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```swift
// Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
// intersperse(numbers: [] as [Int], delimeter: 4) == [] as [Int]
// intersperse(numbers: [1, 2, 3], delimeter: 4) == [1, 4, 2, 4, 3]
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
var result: [Int] = []
for (index, number) in numbers.enumerated() {
result.append(number)
if index < numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
var result: [Int] = []
for (index, number) in numbers.enumerated() {
result.append(number)
if index < numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```swift
// Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
// intersperse(numbers: [] as [Int], delimeter: 4) == [] as [Int]
// intersperse(numbers: [1, 2, 3], delimeter: 4) == [1, 4, 2, 4, 3]
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
var result: [Int] = []
for (index, number) in numbers.enumerated() {
result.append(number)
if index < numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
var result: [Int] = []
for i in 0..<numbers.count {
result.append(numbers[i])
if i < numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```swift
// Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
// intersperse(numbers: [] as [Int], delimeter: 4) == [] as [Int]
// intersperse(numbers: [1, 2, 3], delimeter: 4) == [1, 4, 2, 4, 3]
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
var result: [Int] = []
for i in 0..<numbers.count {
result.append(numbers[i])
if i < numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
var result: [Int] = []
for i in 0..<numbers.count {
result.append(numbers[i])
if i < numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```swift
// Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
// intersperse(numbers: [] as [Int], delimeter: 4) == [] as [Int]
// intersperse(numbers: [1, 2, 3], delimeter: 4) == [1, 4, 2, 4, 3]
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
var result: [Int] = []
for i in 0..<numbers.count {
result.append(numbers[i])
if i < numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
var result: [Int] = []
for (index, number) in numbers.enumerated() {
result.append(number)
if index < numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```swift
// Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
// intersperse(numbers: [] as [Int], delimeter: 4) == [] as [Int]
// intersperse(numbers: [1, 2, 3], delimeter: 4) == [1, 4, 2, 4, 3]
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
var result: [Int] = []
for (index, number) in numbers.enumerated() {
result.append(number)
if index < numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
var result: [Int] = []
for (index, number) in numbers.enumerated() {
result.append(number)
if index < numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```swift
// Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
// intersperse(numbers: [] as [Int], delimeter: 4) == [] as [Int]
// intersperse(numbers: [1, 2, 3], delimeter: 4) == [1, 4, 2, 4, 3]
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
var result: [Int] = []
for (index, number) in numbers.enumerated() {
result.append(number)
if index < numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
var result = [Int]()
for (index, number) in numbers.enumerated() {
result.append(number)
if index < numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```swift
// Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
// intersperse(numbers: [] as [Int], delimeter: 4) == [] as [Int]
// intersperse(numbers: [1, 2, 3], delimeter: 4) == [1, 4, 2, 4, 3]
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
var result = [Int]()
for (index, number) in numbers.enumerated() {
result.append(number)
if index < numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
var result = [Int]()
for i in 0..<numbers.count {
result.append(numbers[i])
if i < numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```swift
// Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
// intersperse(numbers: [] as [Int], delimeter: 4) == [] as [Int]
// intersperse(numbers: [1, 2, 3], delimeter: 4) == [1, 4, 2, 4, 3]
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
var result = [Int]()
for i in 0..<numbers.count {
result.append(numbers[i])
if i < numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```
func parseNestedParens(parenString: String) -> [Int] {
// TODO: Implement this function
}
```swift
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// parseNestedParens(parenString: "(()()) ((())) () ((())()())") == [2, 3, 1, 3]
func parseNestedParens(parenString: String) -> [Int] {
// TODO: Implement this function
}
```
} // missing return in global function expected to return '[Int]'
func parseNestedParens(parenString: String) -> [Int] {
var result = [Int]()
let parenArray = parenString.components(separatedBy: " ")
for paren in parenArray {
var max = 0
var current = 0
for char in paren {
if char == "(" {
current += 1
} else if char == ")" {
current -= 1
}
if current > max {
max = current
}
}
result.append(max)
}
return result
}
```swift
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// parseNestedParens(parenString: "(()()) ((())) () ((())()())") == [2, 3, 1, 3]
func parseNestedParens(parenString: String) -> [Int] {
var result = [Int]()
let parenArray = parenString.components(separatedBy: " ")
for paren in parenArray {
var max = 0
var current = 0
for char in paren {
if char == "(" {
current += 1
} else if char == ")" {
current -= 1
}
if current > max {
max = current
}
}
result.append(max)
}
return result
}
```
func parseNestedParens(parenString: String) -> [Int] {
var result = [Int]()
let parenArray = parenString.components(separatedBy: " ")
for paren in parenArray {
result.append(paren.maxDepthOfNesting())
}
return result
}
extension String {
func maxDepthOfNesting() -> Int {
var maxDepth = 0
var currentDepth = 0
for char in self {
if char == "(" {
currentDepth += 1
} else if char == ")" {
currentDepth -= 1
}
if currentDepth > maxDepth {
maxDepth = currentDepth
}
}
return maxDepth
}
}
```swift
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// parseNestedParens(parenString: "(()()) ((())) () ((())()())") == [2, 3, 1, 3]
func parseNestedParens(parenString: String) -> [Int] {
var result = [Int]()
let parenArray = parenString.components(separatedBy: " ")
for paren in parenArray {
result.append(paren.maxDepthOfNesting())
}
return result
}
extension String {
func maxDepthOfNesting() -> Int {
var maxDepth = 0
var currentDepth = 0
for char in self {
if char == "(" {
currentDepth += 1
} else if char == ")" {
currentDepth -= 1
}
if currentDepth > maxDepth {
maxDepth = currentDepth
}
}
return maxDepth
}
}
```
func parseNestedParens(parenString: String) -> [Int] {
var result = [Int]()
let parenStrings = parenString.componentsSeparatedByString(" ")
for parenString in parenStrings {
var maxLevel = 0
var level = 0
for char in parenString {
if char == "(" {
level += 1
if level > maxLevel {
maxLevel = level
}
} else if char == ")" {
level -= 1
}
}
result.append(maxLevel)
}
return result
}
```swift
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// parseNestedParens(parenString: "(()()) ((())) () ((())()())") == [2, 3, 1, 3]
func parseNestedParens(parenString: String) -> [Int] {
var result = [Int]()
let parenStrings = parenString.componentsSeparatedByString(" ")
for parenString in parenStrings {
var maxLevel = 0
var level = 0
for char in parenString {
if char == "(" {
level += 1
if level > maxLevel {
maxLevel = level
}
} else if char == ")" {
level -= 1
}
}
result.append(maxLevel)
}
return result
}
```
let parenStrings = parenString.componentsSeparatedByString(" ") // value of type 'String' has no member 'componentsSeparatedByString'
func parseNestedParens(parenString: String) -> [Int] {
// Your code here
}
```swift
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// parseNestedParens(parenString: "(()()) ((())) () ((())()())") == [2, 3, 1, 3]
func parseNestedParens(parenString: String) -> [Int] {
// Your code here
}
```
} // missing return in global function expected to return '[Int]'
func parseNestedParens(parenString: String) -> [Int] {
var result = [Int]()
var max = 0
var current = 0
var stack = [Int]()
for c in parenString {
if c == "(" {
stack.append(current)
current = 0
} else if c == ")" {
current += 1
max = max > current? max : current
}
}
result.append(max)
while!stack.isEmpty {
max = 0
current = 0
while!stack.isEmpty {
current += 1
max = max > current? max : current
if stack.last! == 0 {
stack.removeLast()
break
}
}
result.append(max)
}
return result
}
```swift
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// parseNestedParens(parenString: "(()()) ((())) () ((())()())") == [2, 3, 1, 3]
func parseNestedParens(parenString: String) -> [Int] {
var result = [Int]()
var max = 0
var current = 0
var stack = [Int]()
for c in parenString {
if c == "(" {
stack.append(current)
current = 0
} else if c == ")" {
current += 1
max = max > current? max : current
}
}
result.append(max)
while!stack.isEmpty {
max = 0
current = 0
while!stack.isEmpty {
current += 1
max = max > current? max : current
if stack.last! == 0 {
stack.removeLast()
break
}
}
result.append(max)
}
return result
}
```
max = max > current? max : current // consecutive statements on a line must be separated by ';'
max = max > current? max : current // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
max = max > current? max : current // expected expression
max = max > current? max : current // variable is unused
max = max > current? max : current // cannot use optional chaining on non-optional value of type 'Int'
max = max > current? max : current // consecutive statements on a line must be separated by ';'
max = max > current? max : current // cannot assign value of type 'Bool' to type 'Int'
while!stack.isEmpty { // expected expression, var, or let in 'while' condition
func parseNestedParens(parenString: String) -> [Int] {
var result: [Int] = []
let parenStrings = parenString.components(separatedBy: " ")
for parenString in parenStrings {
var maxLevel = 0
var level = 0
for char in parenString {
if char == "(" {
level += 1
if level > maxLevel {
maxLevel = level
}
} else {
level -= 1
}
}
result.append(maxLevel)
}
return result
}
```swift
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// parseNestedParens(parenString: "(()()) ((())) () ((())()())") == [2, 3, 1, 3]
func parseNestedParens(parenString: String) -> [Int] {
var result: [Int] = []
let parenStrings = parenString.components(separatedBy: " ")
for parenString in parenStrings {
var maxLevel = 0
var level = 0
for char in parenString {
if char == "(" {
level += 1
if level > maxLevel {
maxLevel = level
}
} else {
level -= 1
}
}
result.append(maxLevel)
}
return result
}
```
func parseNestedParens(parenString: String) -> [Int] {
// TODO: Implement this function
}
```swift
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// parseNestedParens(parenString: "(()()) ((())) () ((())()())") == [2, 3, 1, 3]
func parseNestedParens(parenString: String) -> [Int] {
// TODO: Implement this function
}
```
} // missing return in global function expected to return '[Int]'
func parseNestedParens(parenString: String) -> [Int] {
// TODO: Implement this function
}
```swift
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// parseNestedParens(parenString: "(()()) ((())) () ((())()())") == [2, 3, 1, 3]
func parseNestedParens(parenString: String) -> [Int] {
// TODO: Implement this function
}
```
} // missing return in global function expected to return '[Int]'
func parseNestedParens(parenString: String) -> [Int] {
var result = [Int]()
let groups = parenString.components(separatedBy: " ")
for group in groups {
var stack = [Character]()
for char in group {
if char == "(" {
stack.append(char)
} else if char == ")" {
stack.removeLast()
}
}
result.append(stack.count)
}
return result
}
```swift
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// parseNestedParens(parenString: "(()()) ((())) () ((())()())") == [2, 3, 1, 3]
func parseNestedParens(parenString: String) -> [Int] {
var result = [Int]()
let groups = parenString.components(separatedBy: " ")
for group in groups {
var stack = [Character]()
for char in group {
if char == "(" {
stack.append(char)
} else if char == ")" {
stack.removeLast()
}
}
result.append(stack.count)
}
return result
}
```
// XCTAssertTrue failed
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```swift
// Filter an input array of strings only for ones that contain given substring
// filterBySubstring(strings: [] as [String], substring: "a") == [] as [String]
// filterBySubstring(strings: ["abc", "bacd", "cde", "array"], substring: "a") == ["abc", "bacd", "array"]
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```swift
// Filter an input array of strings only for ones that contain given substring
// filterBySubstring(strings: [] as [String], substring: "a") == [] as [String]
// filterBySubstring(strings: ["abc", "bacd", "cde", "array"], substring: "a") == ["abc", "bacd", "array"]
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```swift
// Filter an input array of strings only for ones that contain given substring
// filterBySubstring(strings: [] as [String], substring: "a") == [] as [String]
// filterBySubstring(strings: ["abc", "bacd", "cde", "array"], substring: "a") == ["abc", "bacd", "array"]
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { (string) -> Bool in
return string.contains(substring)
}
}
```swift
// Filter an input array of strings only for ones that contain given substring
// filterBySubstring(strings: [] as [String], substring: "a") == [] as [String]
// filterBySubstring(strings: ["abc", "bacd", "cde", "array"], substring: "a") == ["abc", "bacd", "array"]
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { (string) -> Bool in
return string.contains(substring)
}
}
```
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { (string) -> Bool in
return string.contains(substring)
}
}
```swift
// Filter an input array of strings only for ones that contain given substring
// filterBySubstring(strings: [] as [String], substring: "a") == [] as [String]
// filterBySubstring(strings: ["abc", "bacd", "cde", "array"], substring: "a") == ["abc", "bacd", "array"]
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { (string) -> Bool in
return string.contains(substring)
}
}
```
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { (string) -> Bool in
return string.contains(substring)
}
}
```swift
// Filter an input array of strings only for ones that contain given substring
// filterBySubstring(strings: [] as [String], substring: "a") == [] as [String]
// filterBySubstring(strings: ["abc", "bacd", "cde", "array"], substring: "a") == ["abc", "bacd", "array"]
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { (string) -> Bool in
return string.contains(substring)
}
}
```
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { (string) -> Bool in
return string.contains(substring)
}
}
```swift
// Filter an input array of strings only for ones that contain given substring
// filterBySubstring(strings: [] as [String], substring: "a") == [] as [String]
// filterBySubstring(strings: ["abc", "bacd", "cde", "array"], substring: "a") == ["abc", "bacd", "array"]
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { (string) -> Bool in
return string.contains(substring)
}
}
```
func filterBySubstring(strings: [String], substring: String) -> [String] {
var result: [String] = []
for string in strings {
if string.contains(substring) {
result.append(string)
}
}
return result
}
```swift
// Filter an input array of strings only for ones that contain given substring
// filterBySubstring(strings: [] as [String], substring: "a") == [] as [String]
// filterBySubstring(strings: ["abc", "bacd", "cde", "array"], substring: "a") == ["abc", "bacd", "array"]
func filterBySubstring(strings: [String], substring: String) -> [String] {
var result: [String] = []
for string in strings {
if string.contains(substring) {
result.append(string)
}
}
return result
}
```
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { (string) -> Bool in
return string.contains(substring)
}
}
```swift
// Filter an input array of strings only for ones that contain given substring
// filterBySubstring(strings: [] as [String], substring: "a") == [] as [String]
// filterBySubstring(strings: ["abc", "bacd", "cde", "array"], substring: "a") == ["abc", "bacd", "array"]
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { (string) -> Bool in
return string.contains(substring)
}
}
```
func filterBySubstring(strings: [String], substring: String) -> [String] {
var result = [String]()
for string in strings {
if string.contains(substring) {
result.append(string)
}
}
return result
}
```swift
// Filter an input array of strings only for ones that contain given substring
// filterBySubstring(strings: [] as [String], substring: "a") == [] as [String]
// filterBySubstring(strings: ["abc", "bacd", "cde", "array"], substring: "a") == ["abc", "bacd", "array"]
func filterBySubstring(strings: [String], substring: String) -> [String] {
var result = [String]()
for string in strings {
if string.contains(substring) {
result.append(string)
}
}
return result
}
```
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```swift
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```swift
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```swift
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```swift
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```swift
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```swift
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```
func sumProduct(numbers: [Int]) -> (Int, Int) {
return (numbers.reduce(0, +), numbers.reduce(1, *))
}
```swift
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
return (numbers.reduce(0, +), numbers.reduce(1, *))
}
```
func sumProduct(numbers: [Int]) -> (Int, Int) {
return (numbers.reduce(0, +), numbers.reduce(1, *))
}
```swift
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
return (numbers.reduce(0, +), numbers.reduce(1, *))
}
```
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```swift
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```swift
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = 0
for number in numbers {
max = max > number? max : number
result.append(max)
}
return result
}
```swift
// From a given array of integers, generate an array of rolling maximum element found until given moment
// in the sequence.
// rollingMax(numbers: [1, 2, 3, 2, 3, 4, 2]) == [1, 2, 3, 3, 3, 4, 4]
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = 0
for number in numbers {
max = max > number? max : number
result.append(max)
}
return result
}
```
max = max > number? max : number // cannot assign value of type 'Bool' to type 'Int'
max = max > number? max : number // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
max = max > number? max : number // variable is unused
max = max > number? max : number // consecutive statements on a line must be separated by ';'
max = max > number? max : number // consecutive statements on a line must be separated by ';'
max = max > number? max : number // cannot use optional chaining on non-optional value of type 'Int'
max = max > number? max : number // expected expression
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = 0
for number in numbers {
max = max > number? max : number
result.append(max)
}
return result
}
```swift
// From a given array of integers, generate an array of rolling maximum element found until given moment
// in the sequence.
// rollingMax(numbers: [1, 2, 3, 2, 3, 4, 2]) == [1, 2, 3, 3, 3, 4, 4]
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = 0
for number in numbers {
max = max > number? max : number
result.append(max)
}
return result
}
```
max = max > number? max : number // cannot assign value of type 'Bool' to type 'Int'
max = max > number? max : number // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
max = max > number? max : number // variable is unused
max = max > number? max : number // consecutive statements on a line must be separated by ';'
max = max > number? max : number // consecutive statements on a line must be separated by ';'
max = max > number? max : number // cannot use optional chaining on non-optional value of type 'Int'
max = max > number? max : number // expected expression
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = numbers[0]
for number in numbers {
result.append(max)
max = max < number? number : max
}
return result
}
```swift
// From a given array of integers, generate an array of rolling maximum element found until given moment
// in the sequence.
// rollingMax(numbers: [1, 2, 3, 2, 3, 4, 2]) == [1, 2, 3, 3, 3, 4, 4]
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = numbers[0]
for number in numbers {
result.append(max)
max = max < number? number : max
}
return result
}
```
max = max < number? number : max // cannot use optional chaining on non-optional value of type 'Int'
max = max < number? number : max // expression of type 'Int' is unused
max = max < number? number : max // consecutive statements on a line must be separated by ';'
max = max < number? number : max // cannot assign value of type 'Bool' to type 'Int'
max = max < number? number : max // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
max = max < number? number : max // expected expression
max = max < number? number : max // consecutive statements on a line must be separated by ';'
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = numbers.first!
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```swift
// From a given array of integers, generate an array of rolling maximum element found until given moment
// in the sequence.
// rollingMax(numbers: [1, 2, 3, 2, 3, 4, 2]) == [1, 2, 3, 3, 3, 4, 4]
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = numbers.first!
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = numbers[0]
for number in numbers {
result.append(max)
if number > max {
max = number
}
}
return result
}
```swift
// From a given array of integers, generate an array of rolling maximum element found until given moment
// in the sequence.
// rollingMax(numbers: [1, 2, 3, 2, 3, 4, 2]) == [1, 2, 3, 3, 3, 4, 4]
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = numbers[0]
for number in numbers {
result.append(max)
if number > max {
max = number
}
}
return result
}
```
// Fatal error: Index out of range
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = 0
for number in numbers {
max = max > number? max : number
result.append(max)
}
return result
}
```swift
// From a given array of integers, generate an array of rolling maximum element found until given moment
// in the sequence.
// rollingMax(numbers: [1, 2, 3, 2, 3, 4, 2]) == [1, 2, 3, 3, 3, 4, 4]
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = 0
for number in numbers {
max = max > number? max : number
result.append(max)
}
return result
}
```
max = max > number? max : number // cannot assign value of type 'Bool' to type 'Int'
max = max > number? max : number // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
max = max > number? max : number // variable is unused
max = max > number? max : number // consecutive statements on a line must be separated by ';'
max = max > number? max : number // consecutive statements on a line must be separated by ';'
max = max > number? max : number // cannot use optional chaining on non-optional value of type 'Int'
max = max > number? max : number // expected expression
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = 0
for number in numbers {
max = max < number? number : max
result.append(max)
}
return result
}
```swift
// From a given array of integers, generate an array of rolling maximum element found until given moment
// in the sequence.
// rollingMax(numbers: [1, 2, 3, 2, 3, 4, 2]) == [1, 2, 3, 3, 3, 4, 4]
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = 0
for number in numbers {
max = max < number? number : max
result.append(max)
}
return result
}
```
max = max < number? number : max // consecutive statements on a line must be separated by ';'
max = max < number? number : max // consecutive statements on a line must be separated by ';'
max = max < number? number : max // cannot assign value of type 'Bool' to type 'Int'
max = max < number? number : max // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
max = max < number? number : max // expected expression
max = max < number? number : max // cannot use optional chaining on non-optional value of type 'Int'
max = max < number? number : max // expression of type 'Int' is unused
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = numbers[0]
for number in numbers {
result.append(max)
if number > max {
max = number
}
}
return result
}
```swift
// From a given array of integers, generate an array of rolling maximum element found until given moment
// in the sequence.
// rollingMax(numbers: [1, 2, 3, 2, 3, 4, 2]) == [1, 2, 3, 3, 3, 4, 4]
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = numbers[0]
for number in numbers {
result.append(max)
if number > max {
max = number
}
}
return result
}
```
// Fatal error: Index out of range
func rollingMax(numbers: [Int]) -> [Int] {
var result: [Int] = []
var max: Int = numbers[0]
for number in numbers {
result.append(max)
if number > max {
max = number
}
}
return result
}
```swift
// From a given array of integers, generate an array of rolling maximum element found until given moment
// in the sequence.
// rollingMax(numbers: [1, 2, 3, 2, 3, 4, 2]) == [1, 2, 3, 3, 3, 4, 4]
func rollingMax(numbers: [Int]) -> [Int] {
var result: [Int] = []
var max: Int = numbers[0]
for number in numbers {
result.append(max)
if number > max {
max = number
}
}
return result
}
```
// Fatal error: Index out of range
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = numbers.first!
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```swift
// From a given array of integers, generate an array of rolling maximum element found until given moment
// in the sequence.
// rollingMax(numbers: [1, 2, 3, 2, 3, 4, 2]) == [1, 2, 3, 3, 3, 4, 4]
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = numbers.first!
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func makePalindrome(string: String) -> String {
var result = string
var i = string.count - 1
while i > 0 {
let prefix = string[0..<i]
let suffix = string[i..<string.count]
if isPalindrome(string: suffix) {
result = String(prefix) + String(suffix.reversed())
break
}
i -= 1
}
return result
}
func isPalindrome(string: String) -> Bool {
var i = 0
var j = string.count - 1
while i < j {
if string[i]!= string[j] {
return false
}
i += 1
j -= 1
}
return true
}
```swift
// Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// makePalindrome(string: "") == ""
// makePalindrome(string: "cat") == "catac"
// makePalindrome(string: "cata") == "catac"
func makePalindrome(string: String) -> String {
var result = string
var i = string.count - 1
while i > 0 {
let prefix = string[0..<i]
let suffix = string[i..<string.count]
if isPalindrome(string: suffix) {
result = String(prefix) + String(suffix.reversed())
break
}
i -= 1
}
return result
}
// Check if a string is a palindrome.
// isPalindrome(string: "") == true
// isPalindrome(string: "cat") == false
// isPalindrome(string: "cata") == true
func isPalindrome(string: String) -> Bool {
var i = 0
var j = string.count - 1
while i < j {
if string[i]!= string[j] {
return false
}
i += 1
j -= 1
}
return true
}
```
let prefix = string[0..<i] // 'subscript(_:)' is unavailable: cannot subscript String with an integer range, use a String.Index range instead.
let suffix = string[i..<string.count] // 'subscript(_:)' is unavailable: cannot subscript String with an integer range, use a String.Index range instead.
if string[i]!= string[j] { // '=' must have consistent whitespace on both sides
if string[i]!= string[j] { // cannot force unwrap value of non-optional type 'Character'
if string[i]!= string[j] { // use of '=' in a boolean context, did you mean '=='?
func makePalindrome(string: String) -> String {
var result = string
var i = string.count - 1
while i > 0 {
let prefix = string[0..<i]
let suffix = string[i..<string.count]
if suffix == suffix.reversed() {
result = prefix.reversed() + suffix
break
}
i -= 1
}
return result
}
```swift
// Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// makePalindrome(string: "") == ""
// makePalindrome(string: "cat") == "catac"
// makePalindrome(string: "cata") == "catac"
func makePalindrome(string: String) -> String {
var result = string
var i = string.count - 1
while i > 0 {
let prefix = string[0..<i]
let suffix = string[i..<string.count]
if suffix == suffix.reversed() {
result = prefix.reversed() + suffix
break
}
i -= 1
}
return result
}
```
let prefix = string[0..<i] // 'subscript(_:)' is unavailable: cannot subscript String with an integer range, use a String.Index range instead.
let suffix = string[i..<string.count] // 'subscript(_:)' is unavailable: cannot subscript String with an integer range, use a String.Index range instead.
if suffix == suffix.reversed() { // binary operator '==' cannot be applied to operands of type 'String' and '[String.Element]' (aka 'Array<Character>')
func makePalindrome(string: String) -> String {
let reversedString = String(string.characters.reversed())
let longestPalindrome = longestPalindrome(string: string + reversedString)
let palindrome = String(longestPalindrome.characters.dropLast(reversedString.characters.count))
return palindrome
}
func longestPalindrome(string: String) -> String {
let reversedString = String(string.characters.reversed())
let palindrome1 = longestPalindrome(string: string)
let palindrome2 = longestPalindrome(string: reversedString)
if palindrome1 == palindrome2 {
return palindrome1
} else {
return palindrome1.characters.count > palindrome2.characters.count? palindrome1 : palindrome2
}
}
```swift
// Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// makePalindrome(string: "") == ""
// makePalindrome(string: "cat") == "catac"
// makePalindrome(string: "cata") == "catac"
func makePalindrome(string: String) -> String {
let reversedString = String(string.characters.reversed())
let longestPalindrome = longestPalindrome(string: string + reversedString)
let palindrome = String(longestPalindrome.characters.dropLast(reversedString.characters.count))
return palindrome
}
// Find the longest palindrome that is a substring of a supplied string.
// Algorithm idea is simple:
// - Find the longest palindrome that is a substring of a string.
// - Find the longest palindrome that is a substring of a reversed string.
// - If the palindromes are equal, return the palindrome.
// - If the palindromes are not equal, return the longer palindrome.
// longestPalindrome(string: "") == ""
// longestPalindrome(string: "cat") == "cat"
// longestPalindrome(string: "cata") == "ata"
// longestPalindrome(string: "cata") == "ata"
func longestPalindrome(string: String) -> String {
let reversedString = String(string.characters.reversed())
let palindrome1 = longestPalindrome(string: string)
let palindrome2 = longestPalindrome(string: reversedString)
if palindrome1 == palindrome2 {
return palindrome1
} else {
return palindrome1.characters.count > palindrome2.characters.count? palindrome1 : palindrome2
}
}
// Find the longest palindrome that is a substring of a supplied string.
// Algorithm idea is simple:
// - Find the longest palindrome that is a substring of a string.
// - Find the longest palindrome that is a substring of a reversed string.
// - If the palindromes are equal, return the palindrome.
// - If the palindromes are not equal, return the longer palindrome.
// longestPalindrome(string: "") == ""
// longestPalindrome(string: "cat") == "cat"
// longestPalindrome(string: "cata") == "ata"
// longestPalindrome(string: "cata") == "ata"
func longestPalindrome(string: String) -> String {
let reversedString = String(string.characters.reversed())
let palindrome1 = longestPalindrome(string: string)
let palindrome2 = longestPalindrome(string: reversedString)
if palindrome1 == palindrome2 {
return palindrome1
} else {
return palindrome1.characters.count > palindrome2.characters.count? palindrome1 : palindrome2
}
}
// Find the longest palindrome that is a substring of a supplied string.
// Algorithm idea is simple:
// - Find the longest palindrome that is a substring of a string.
// - Find the longest palindrome that is a substring of a reversed string.
// - If the palindromes are equal, return the palindrome.
// - If the palindromes are not equal, return the longer palindrome.
// longestPalindrome(string: "") == ""
// longestPalindrome(string: "cat") == "cat"
// longestPalindrome(string: "cata") == "ata"
// longestPalindrome(string: "cata") == "ata"
func longestPalindrome(string: String) -> String {
let reversedString = String(string.characters.reversed())
let palindrome1 = longestPalindrome(string: string)
let palindrome2 = longestPalindrome(string: reversedString)
if palindrome1 == palindrome2 {
return palindrome1
} else {
return palindrome1.characters.count > palindrome2.characters.count? palindrome1 : palindrome2
}
}
// Find the longest palindrome that is a substring of a supplied string.
// Algorithm idea is simple:
// - Find the longest palindrome that is a substring of a string.
// - Find the longest palindrome that is a substring of a reversed string.
// - If the palindromes are equal, return the palindrome.
// - If the palindromes are not equal, return the longer palindrome.
// longestPalindrome(string: "") == ""
// longestPalindrome(string: "cat") == "cat"
// longestPalindrome(string: "cata") == "ata"
// longestPalindrome(string: "cata") == "ata"
func longestPalindrome(string: String) -> String {
let reversedString = String(string.characters.reversed())
let palindrome1 = longestPalindrome(string: string)
let palindrome2 = longestPalindrome(string: reversedString)
if palindrome1
let reversedString = String(string.characters.reversed()) // 'characters' is unavailable: Please use String directly
let palindrome = String(longestPalindrome.characters.dropLast(reversedString.characters.count)) // 'characters' is unavailable: Please use String directly
let palindrome = String(longestPalindrome.characters.dropLast(reversedString.characters.count)) // 'characters' is unavailable: Please use String directly
let reversedString = String(string.characters.reversed()) // 'characters' is unavailable: Please use String directly
return palindrome1.characters.count > palindrome2.characters.count? palindrome1 : palindrome2 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
return palindrome1.characters.count > palindrome2.characters.count? palindrome1 : palindrome2 // cannot convert return expression of type 'Bool' to return type 'String'
return palindrome1.characters.count > palindrome2.characters.count? palindrome1 : palindrome2 // consecutive statements on a line must be separated by ';'
return palindrome1.characters.count > palindrome2.characters.count? palindrome1 : palindrome2 // cannot use optional chaining on non-optional value of type 'Int'
return palindrome1.characters.count > palindrome2.characters.count? palindrome1 : palindrome2 // expected expression
return palindrome1.characters.count > palindrome2.characters.count? palindrome1 : palindrome2 // expression of type 'String' is unused
return palindrome1.characters.count > palindrome2.characters.count? palindrome1 : palindrome2 // consecutive statements on a line must be separated by ';'
func makePalindrome(string: String) -> String {
var result = string
var i = 0
while i < result.count {
let prefix = result.prefix(i)
let suffix = result.suffix(result.count - i)
if isPalindrome(string: String(suffix)) {
result = String(prefix) + String(suffix.reversed())
break
}
i += 1
}
return result
}
func isPalindrome(string: String) -> Bool {
return string == String(string.reversed())
}
```swift
// Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// makePalindrome(string: "") == ""
// makePalindrome(string: "cat") == "catac"
// makePalindrome(string: "cata") == "catac"
func makePalindrome(string: String) -> String {
var result = string
var i = 0
while i < result.count {
let prefix = result.prefix(i)
let suffix = result.suffix(result.count - i)
if isPalindrome(string: String(suffix)) {
result = String(prefix) + String(suffix.reversed())
break
}
i += 1
}
return result
}
func isPalindrome(string: String) -> Bool {
return string == String(string.reversed())
}
```
// XCTAssertTrue failed
func makePalindrome(string: String) -> String {
var result = string
var reversed = ""
var i = string.count - 1
while i >= 0 {
reversed.append(string[i])
i -= 1
}
if string == reversed {
return result
}
result.append(reversed)
return result
}
```swift
// Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// makePalindrome(string: "") == ""
// makePalindrome(string: "cat") == "catac"
// makePalindrome(string: "cata") == "catac"
func makePalindrome(string: String) -> String {
var result = string
var reversed = ""
var i = string.count - 1
while i >= 0 {
reversed.append(string[i])
i -= 1
}
if string == reversed {
return result
}
result.append(reversed)
return result
}
```
reversed.append(string[i]) // 'subscript(_:)' is unavailable: cannot subscript String with an Int, use a String.Index instead.
func makePalindrome(string: String) -> String {
var result = string
var prefix = ""
var suffix = ""
for i in 0..<string.count {
let prefix = string.substring(to: string.index(string.startIndex, offsetBy: i))
let suffix = string.substring(from: string.index(string.endIndex, offsetBy: -i))
if prefix == suffix.reverse() {
result = prefix + suffix.reverse()
break
}
}
return result
}
```swift
// Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// makePalindrome(string: "") == ""
// makePalindrome(string: "cat") == "catac"
// makePalindrome(string: "cata") == "catac"
func makePalindrome(string: String) -> String {
var result = string
var prefix = ""
var suffix = ""
for i in 0..<string.count {
let prefix = string.substring(to: string.index(string.startIndex, offsetBy: i))
let suffix = string.substring(from: string.index(string.endIndex, offsetBy: -i))
if prefix == suffix.reverse() {
result = prefix + suffix.reverse()
break
}
}
return result
}
```
let prefix = string.substring(to: string.index(string.startIndex, offsetBy: i)) // 'substring(to:)' is deprecated: Please use String slicing subscript with a 'partial range upto' operator.
let suffix = string.substring(from: string.index(string.endIndex, offsetBy: -i)) // 'substring(from:)' is deprecated: Please use String slicing subscript with a 'partial range from' operator.
if prefix == suffix.reverse() { // value of type 'String' has no member 'reverse'
result = prefix + suffix.reverse() // value of type 'String' has no member 'reverse'
```swift
// Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// makePalindrome(string: "") == ""
// makePalindrome(string: "cat") == "catac"
// makePalindrome(string: "cata") == "catac"
func makePalindrome(string: String) -> String {
var prefix = ""
var suffix = ""
var palindrome = string
var isPalindrome = false
var isPrefix = false
var isSuffix = false
var isPalindromeFound = false
var isPalindromeFoundInSuffix = false
var isPalindromeFoundInPrefix = false
var isPalindromeFoundInString = false
var isPalindromeFoundInStringSuffix = false
var isPalindromeFoundInStringPrefix = false
var isPalindromeFoundInStringSuffixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringSuffixPrefix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindromeFoundInStringPrefixPrefix = false
var isPalindromeFoundInStringSuffixSuffix = false
var isPalindromeFoundInStringPrefixSuffix = false
var isPalindrome
XCTAssertTrue(makePalindrome(string: "") == "") // cannot find 'makePalindrome' in scope
XCTAssertTrue(makePalindrome(string: "x") == "x") // cannot find 'makePalindrome' in scope
XCTAssertTrue(makePalindrome(string: "xyz") == "xyzyx") // cannot find 'makePalindrome' in scope
XCTAssertTrue(makePalindrome(string: "xyx") == "xyx") // cannot find 'makePalindrome' in scope
XCTAssertTrue(makePalindrome(string: "jerry") == "jerryrrej") // cannot find 'makePalindrome' in scope
func makePalindrome(string: String) -> String {
let reversedString = String(string.reversed())
let longestPalindrome = longestPalindrome(string: string)
let prefix = string.substring(to: string.index(string.startIndex, offsetBy: longestPalindrome.count))
return prefix + reversedString
}
func longestPalindrome(string: String) -> String {
var longestPalindrome = ""
for i in 0..<string.count {
let left = string.index(string.startIndex, offsetBy: i)
let right = string.index(string.startIndex, offsetBy: string.count - i - 1)
let substring = string[left...right]
if substring == String(substring.reversed()) {
longestPalindrome = substring
}
}
return longestPalindrome
}
```swift
// Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// makePalindrome(string: "") == ""
// makePalindrome(string: "cat") == "catac"
// makePalindrome(string: "cata") == "catac"
func makePalindrome(string: String) -> String {
let reversedString = String(string.reversed())
let longestPalindrome = longestPalindrome(string: string)
let prefix = string.substring(to: string.index(string.startIndex, offsetBy: longestPalindrome.count))
return prefix + reversedString
}
// Find the longest palindrome in a string.
// Algorithm idea is simple:
// - Start with the first character.
// - Expand the palindrome to the left and right until it stops being a palindrome.
// longestPalindrome(string: "cat") == "c"
// longestPalindrome(string: "cata") == "a"
// longestPalindrome(string: "cata") == "a"
func longestPalindrome(string: String) -> String {
var longestPalindrome = ""
for i in 0..<string.count {
let left = string.index(string.startIndex, offsetBy: i)
let right = string.index(string.startIndex, offsetBy: string.count - i - 1)
let substring = string[left...right]
if substring == String(substring.reversed()) {
longestPalindrome = substring
}
}
return longestPalindrome
}
```
let prefix = string.substring(to: string.index(string.startIndex, offsetBy: longestPalindrome.count)) // 'substring(to:)' is deprecated: Please use String slicing subscript with a 'partial range upto' operator.
longestPalindrome = substring // cannot assign value of type 'String.SubSequence' (aka 'Substring') to type 'String'
func makePalindrome(string: String) -> String {
var palindrome = string
var i = 0
while i < palindrome.count {
let prefix = palindrome.prefix(i)
let suffix = palindrome.suffix(palindrome.count - i)
if suffix == suffix.reversed() {
palindrome = String(prefix) + String(suffix.reversed())
break
}
i += 1
}
return palindrome
}
```swift
// Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// makePalindrome(string: "") == ""
// makePalindrome(string: "cat") == "catac"
// makePalindrome(string: "cata") == "catac"
func makePalindrome(string: String) -> String {
var palindrome = string
var i = 0
while i < palindrome.count {
let prefix = palindrome.prefix(i)
let suffix = palindrome.suffix(palindrome.count - i)
if suffix == suffix.reversed() {
palindrome = String(prefix) + String(suffix.reversed())
break
}
i += 1
}
return palindrome
}
```
if suffix == suffix.reversed() { // cannot convert value of type '[Substring.Element]' (aka 'Array<Character>') to expected argument type 'String.SubSequence' (aka 'Substring')
func makePalindrome(string: String) -> String {
let reversedString = String(string.characters.reversed())
let reversedPrefix = string.characters.dropLast(reversedString.characters.count)
return String(reversedPrefix) + string + reversedString
}
```swift
// Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// makePalindrome(string: "") == ""
// makePalindrome(string: "cat") == "catac"
// makePalindrome(string: "cata") == "catac"
func makePalindrome(string: String) -> String {
let reversedString = String(string.characters.reversed())
let reversedPrefix = string.characters.dropLast(reversedString.characters.count)
return String(reversedPrefix) + string + reversedString
}
```
let reversedString = String(string.characters.reversed()) // 'characters' is unavailable: Please use String directly
let reversedPrefix = string.characters.dropLast(reversedString.characters.count) // 'characters' is unavailable: Please use String directly
let reversedPrefix = string.characters.dropLast(reversedString.characters.count) // 'characters' is unavailable: Please use String directly
func stringXor(a: String, b: String) -> String {
var result = ""
for i in 0..<a.count {
let charA = a[i]
let charB = b[i]
if charA == charB {
result += "0"
} else {
result += "1"
}
}
return result
}
```swift
// Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// stringXor(a: "010", b: "110") == "100"
func stringXor(a: String, b: String) -> String {
var result = ""
for i in 0..<a.count {
let charA = a[i]
let charB = b[i]
if charA == charB {
result += "0"
} else {
result += "1"
}
}
return result
}
```
let charA = a[i] // 'subscript(_:)' is unavailable: cannot subscript String with an Int, use a String.Index instead.
let charB = b[i] // 'subscript(_:)' is unavailable: cannot subscript String with an Int, use a String.Index instead.
func stringXor(a: String, b: String) -> String {
var result = ""
for i in 0..<max(a.count, b.count) {
let aChar = a.count > i? a[a.index(a.startIndex, offsetBy: i)] : "0"
let bChar = b.count > i? b[b.index(b.startIndex, offsetBy: i)] : "0"
if aChar == bChar {
result.append("0")
} else {
result.append("1")
}
}
return result
}
```swift
// Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// stringXor(a: "010", b: "110") == "100"
func stringXor(a: String, b: String) -> String {
var result = ""
for i in 0..<max(a.count, b.count) {
let aChar = a.count > i? a[a.index(a.startIndex, offsetBy: i)] : "0"
let bChar = b.count > i? b[b.index(b.startIndex, offsetBy: i)] : "0"
if aChar == bChar {
result.append("0")
} else {
result.append("1")
}
}
return result
}
```
let aChar = a.count > i? a[a.index(a.startIndex, offsetBy: i)] : "0" // consecutive statements on a line must be separated by ';'
let aChar = a.count > i? a[a.index(a.startIndex, offsetBy: i)] : "0" // expected expression
let aChar = a.count > i? a[a.index(a.startIndex, offsetBy: i)] : "0" // expression of type 'Character' is unused
let aChar = a.count > i? a[a.index(a.startIndex, offsetBy: i)] : "0" // cannot use optional chaining on non-optional value of type 'Int'
let aChar = a.count > i? a[a.index(a.startIndex, offsetBy: i)] : "0" // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
let aChar = a.count > i? a[a.index(a.startIndex, offsetBy: i)] : "0" // consecutive statements on a line must be separated by ';'
let bChar = b.count > i? b[b.index(b.startIndex, offsetBy: i)] : "0" // cannot use optional chaining on non-optional value of type 'Int'
let bChar = b.count > i? b[b.index(b.startIndex, offsetBy: i)] : "0" // expected expression
let bChar = b.count > i? b[b.index(b.startIndex, offsetBy: i)] : "0" // consecutive statements on a line must be separated by ';'
let bChar = b.count > i? b[b.index(b.startIndex, offsetBy: i)] : "0" // expression of type 'Character' is unused
let bChar = b.count > i? b[b.index(b.startIndex, offsetBy: i)] : "0" // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
let bChar = b.count > i? b[b.index(b.startIndex, offsetBy: i)] : "0" // consecutive statements on a line must be separated by ';'
func stringXor(a: String, b: String) -> String {
var result = ""
for i in 0..<a.count {
let charA = a[i]
let charB = b[i]
if charA == charB {
result.append("0")
} else {
result.append("1")
}
}
return result
}
```swift
// Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// stringXor(a: "010", b: "110") == "100"
func stringXor(a: String, b: String) -> String {
var result = ""
for i in 0..<a.count {
let charA = a[i]
let charB = b[i]
if charA == charB {
result.append("0")
} else {
result.append("1")
}
}
return result
}
```
let charA = a[i] // 'subscript(_:)' is unavailable: cannot subscript String with an Int, use a String.Index instead.
let charB = b[i] // 'subscript(_:)' is unavailable: cannot subscript String with an Int, use a String.Index instead.
func stringXor(a: String, b: String) -> String {
var result = ""
for i in 0..<max(a.count, b.count) {
let aChar = i < a.count? a[a.index(a.startIndex, offsetBy: i)] : "0"
let bChar = i < b.count? b[b.index(b.startIndex, offsetBy: i)] : "0"
let xor = (aChar == "1"? 1 : 0) ^ (bChar == "1"? 1 : 0)
result.append(xor == 1? "1" : "0")
}
return result
}
```swift
// Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// stringXor(a: "010", b: "110") == "100"
func stringXor(a: String, b: String) -> String {
var result = ""
for i in 0..<max(a.count, b.count) {
let aChar = i < a.count? a[a.index(a.startIndex, offsetBy: i)] : "0"
let bChar = i < b.count? b[b.index(b.startIndex, offsetBy: i)] : "0"
let xor = (aChar == "1"? 1 : 0) ^ (bChar == "1"? 1 : 0)
result.append(xor == 1? "1" : "0")
}
return result
}
```
let aChar = i < a.count? a[a.index(a.startIndex, offsetBy: i)] : "0" // consecutive statements on a line must be separated by ';'
let aChar = i < a.count? a[a.index(a.startIndex, offsetBy: i)] : "0" // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
let aChar = i < a.count? a[a.index(a.startIndex, offsetBy: i)] : "0" // cannot use optional chaining on non-optional value of type 'Int'
let aChar = i < a.count? a[a.index(a.startIndex, offsetBy: i)] : "0" // expression of type 'Character' is unused
let aChar = i < a.count? a[a.index(a.startIndex, offsetBy: i)] : "0" // expected expression
let aChar = i < a.count? a[a.index(a.startIndex, offsetBy: i)] : "0" // consecutive statements on a line must be separated by ';'
let bChar = i < b.count? b[b.index(b.startIndex, offsetBy: i)] : "0" // consecutive statements on a line must be separated by ';'
let bChar = i < b.count? b[b.index(b.startIndex, offsetBy: i)] : "0" // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
let bChar = i < b.count? b[b.index(b.startIndex, offsetBy: i)] : "0" // consecutive statements on a line must be separated by ';'
let bChar = i < b.count? b[b.index(b.startIndex, offsetBy: i)] : "0" // cannot use optional chaining on non-optional value of type 'Int'
let bChar = i < b.count? b[b.index(b.startIndex, offsetBy: i)] : "0" // expression of type 'Character' is unused
let bChar = i < b.count? b[b.index(b.startIndex, offsetBy: i)] : "0" // expected expression
let xor = (aChar == "1"? 1 : 0) ^ (bChar == "1"? 1 : 0) // binary operator '^' cannot be applied to two '(Bool, Int)' operands
let xor = (aChar == "1"? 1 : 0) ^ (bChar == "1"? 1 : 0) // expected ',' separator
let xor = (aChar == "1"? 1 : 0) ^ (bChar == "1"? 1 : 0) // cannot use optional chaining on non-optional value of type 'String'
let xor = (aChar == "1"? 1 : 0) ^ (bChar == "1"? 1 : 0) // cannot use optional chaining on non-optional value of type 'String'
let xor = (aChar == "1"? 1 : 0) ^ (bChar == "1"? 1 : 0) // expected ',' separator
result.append(xor == 1? "1" : "0") // cannot use optional chaining on non-optional value of type 'Int'
result.append(xor == 1? "1" : "0") // expected ',' separator
result.append(xor == 1? "1" : "0") // no exact matches in call to instance method 'append'
func stringXor(a: String, b: String) -> String {
var result = ""
for i in 0..<max(a.count, b.count) {
let aChar = a.index(a.startIndex, offsetBy: i)
let bChar = b.index(b.startIndex, offsetBy: i)
let aValue = a[aChar]
let bValue = b[bChar]
let xor = (aValue == bValue)? "0" : "1"
result.append(xor)
}
return result
}
```swift
// Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// stringXor(a: "010", b: "110") == "100"
func stringXor(a: String, b: String) -> String {
var result = ""
for i in 0..<max(a.count, b.count) {
let aChar = a.index(a.startIndex, offsetBy: i)
let bChar = b.index(b.startIndex, offsetBy: i)
let aValue = a[aChar]
let bValue = b[bChar]
let xor = (aValue == bValue)? "0" : "1"
result.append(xor)
}
return result
}
```
let xor = (aValue == bValue)? "0" : "1" // consecutive statements on a line must be separated by ';'
let xor = (aValue == bValue)? "0" : "1" // cannot use optional chaining on non-optional value of type 'Bool'
let xor = (aValue == bValue)? "0" : "1" // consecutive statements on a line must be separated by ';'
let xor = (aValue == bValue)? "0" : "1" // string literal is unused
let xor = (aValue == bValue)? "0" : "1" // expected expression
func stringXor(a: String, b: String) -> String {
var result = ""
for (index, char) in a.enumerated() {
let charB = b.index(b.startIndex, offsetBy: index)
let charB = b[charB]
if char == charB {
result.append("0")
} else {
result.append("1")
}
}
return result
}
```swift
// Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// stringXor(a: "010", b: "110") == "100"
func stringXor(a: String, b: String) -> String {
var result = ""
for (index, char) in a.enumerated() {
let charB = b.index(b.startIndex, offsetBy: index)
let charB = b[charB]
if char == charB {
result.append("0")
} else {
result.append("1")
}
}
return result
}
```
let charB = b[charB] // invalid redeclaration of 'charB'
func stringXor(a: String, b: String) -> String {
var result = ""
for (index, char) in a.enumerated() {
if char == b[index] {
result.append("0")
} else {
result.append("1")
}
}
return result
}
```swift
// Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// stringXor(a: "010", b: "110") == "100"
func stringXor(a: String, b: String) -> String {
var result = ""
for (index, char) in a.enumerated() {
if char == b[index] {
result.append("0")
} else {
result.append("1")
}
}
return result
}
```
if char == b[index] { // 'subscript(_:)' is unavailable: cannot subscript String with an Int, use a String.Index instead.
func stringXor(a: String, b: String) -> String {
var result = ""
for i in 0..<a.count {
let charA = a[i]
let charB = b[i]
let xor = charA == charB? "0" : "1"
result.append(xor)
}
return result
}
```swift
// Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// stringXor(a: "010", b: "110") == "100"
func stringXor(a: String, b: String) -> String {
var result = ""
for i in 0..<a.count {
let charA = a[i]
let charB = b[i]
let xor = charA == charB? "0" : "1"
result.append(xor)
}
return result
}
```
let charA = a[i] // 'subscript(_:)' is unavailable: cannot subscript String with an Int, use a String.Index instead.
let charB = b[i] // 'subscript(_:)' is unavailable: cannot subscript String with an Int, use a String.Index instead.
let xor = charA == charB? "0" : "1" // consecutive statements on a line must be separated by ';'
let xor = charA == charB? "0" : "1" // expected expression
let xor = charA == charB? "0" : "1" // cannot use optional chaining on non-optional value of type 'Character'
let xor = charA == charB? "0" : "1" // consecutive statements on a line must be separated by ';'
let xor = charA == charB? "0" : "1" // string literal is unused
func stringXor(a: String, b: String) -> String {
var result = ""
for i in 0..<a.count {
let charA = a[i]
let charB = b[i]
if charA == charB {
result.append("0")
} else {
result.append("1")
}
}
return result
}
```swift
// Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// stringXor(a: "010", b: "110") == "100"
func stringXor(a: String, b: String) -> String {
var result = ""
for i in 0..<a.count {
let charA = a[i]
let charB = b[i]
if charA == charB {
result.append("0")
} else {
result.append("1")
}
}
return result
}
```
let charA = a[i] // 'subscript(_:)' is unavailable: cannot subscript String with an Int, use a String.Index instead.
let charB = b[i] // 'subscript(_:)' is unavailable: cannot subscript String with an Int, use a String.Index instead.
func stringXor(a: String, b: String) -> String {
var result = ""
for i in 0..<a.count {
if a[i] == b[i] {
result.append("0")
} else {
result.append("1")
}
}
return result
}
```swift
// Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// stringXor(a: "010", b: "110") == "100"
func stringXor(a: String, b: String) -> String {
var result = ""
for i in 0..<a.count {
if a[i] == b[i] {
result.append("0")
} else {
result.append("1")
}
}
return result
}
```
if a[i] == b[i] { // 'subscript(_:)' is unavailable: cannot subscript String with an Int, use a String.Index instead.
if a[i] == b[i] { // 'subscript(_:)' is unavailable: cannot subscript String with an Int, use a String.Index instead.
func longest(strings: [String]) -> String? {
// Your code goes here
}
```swift
// Out of array of strings, return the longest one. Return the first one in case of multiple
// strings of the same length. Return nil in case the input array is empty.
// longest(strings: [] as [String]) == nil
// longest(strings: ["a", "b", "c"]) == "a"
// longest(strings: ["a", "bb", "ccc"]) == "ccc"
func longest(strings: [String]) -> String? {
// Your code goes here
}
```
} // missing return in global function expected to return 'String?'
func longest(strings: [String]) -> String? {
// TODO: implement
}
```swift
// Out of array of strings, return the longest one. Return the first one in case of multiple
// strings of the same length. Return nil in case the input array is empty.
// longest(strings: [] as [String]) == nil
// longest(strings: ["a", "b", "c"]) == "a"
// longest(strings: ["a", "bb", "ccc"]) == "ccc"
func longest(strings: [String]) -> String? {
// TODO: implement
}
```
} // missing return in global function expected to return 'String?'
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```swift
// Out of array of strings, return the longest one. Return the first one in case of multiple
// strings of the same length. Return nil in case the input array is empty.
// longest(strings: [] as [String]) == nil
// longest(strings: ["a", "b", "c"]) == "a"
// longest(strings: ["a", "bb", "ccc"]) == "ccc"
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```
func longest(strings: [String]) -> String? {
// TODO: implement
}
```swift
// Out of array of strings, return the longest one. Return the first one in case of multiple
// strings of the same length. Return nil in case the input array is empty.
// longest(strings: [] as [String]) == nil
// longest(strings: ["a", "b", "c"]) == "a"
// longest(strings: ["a", "bb", "ccc"]) == "ccc"
func longest(strings: [String]) -> String? {
// TODO: implement
}
```
} // missing return in global function expected to return 'String?'
func longest(strings: [String]) -> String? {
// TODO: implement
}
```swift
// Out of array of strings, return the longest one. Return the first one in case of multiple
// strings of the same length. Return nil in case the input array is empty.
// longest(strings: [] as [String]) == nil
// longest(strings: ["a", "b", "c"]) == "a"
// longest(strings: ["a", "bb", "ccc"]) == "ccc"
func longest(strings: [String]) -> String? {
// TODO: implement
}
```
} // missing return in global function expected to return 'String?'
func longest(strings: [String]) -> String? {
return nil
}
```swift
// Out of array of strings, return the longest one. Return the first one in case of multiple
// strings of the same length. Return nil in case the input array is empty.
// longest(strings: [] as [String]) == nil
// longest(strings: ["a", "b", "c"]) == "a"
// longest(strings: ["a", "bb", "ccc"]) == "ccc"
func longest(strings: [String]) -> String? {
return nil
}
```
// XCTAssertTrue failed
func longest(strings: [String]) -> String? {
return strings.max { $0.count < $1.count }
}
```swift
// Out of array of strings, return the longest one. Return the first one in case of multiple
// strings of the same length. Return nil in case the input array is empty.
// longest(strings: [] as [String]) == nil
// longest(strings: ["a", "b", "c"]) == "a"
// longest(strings: ["a", "bb", "ccc"]) == "ccc"
func longest(strings: [String]) -> String? {
return strings.max { $0.count < $1.count }
}
```
func longest(strings: [String]) -> String? {
// TODO: implement me
return nil
}
```swift
// Out of array of strings, return the longest one. Return the first one in case of multiple
// strings of the same length. Return nil in case the input array is empty.
// longest(strings: [] as [String]) == nil
// longest(strings: ["a", "b", "c"]) == "a"
// longest(strings: ["a", "bb", "ccc"]) == "ccc"
func longest(strings: [String]) -> String? {
// TODO: implement me
return nil
}
```
// XCTAssertTrue failed
func longest(strings: [String]) -> String? {
return nil
}
```swift
// Out of array of strings, return the longest one. Return the first one in case of multiple
// strings of the same length. Return nil in case the input array is empty.
// longest(strings: [] as [String]) == nil
// longest(strings: ["a", "b", "c"]) == "a"
// longest(strings: ["a", "bb", "ccc"]) == "ccc"
func longest(strings: [String]) -> String? {
return nil
}
```
// XCTAssertTrue failed
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```swift
// Out of array of strings, return the longest one. Return the first one in case of multiple
// strings of the same length. Return nil in case the input array is empty.
// longest(strings: [] as [String]) == nil
// longest(strings: ["a", "b", "c"]) == "a"
// longest(strings: ["a", "bb", "ccc"]) == "ccc"
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if b == 0 {
return a
}
return greatestCommonDivisor(a: b, b: a % b)
}
```swift
// Return a greatest common divisor of two integers a and b
// greatestCommonDivisor(a: 3, b: 5) == 1
// greatestCommonDivisor(a: 25, b: 15) == 5
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if b == 0 {
return a
}
return greatestCommonDivisor(a: b, b: a % b)
}
```
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if b == 0 {
return a
}
return greatestCommonDivisor(a: b, b: a % b)
}
```swift
// Return a greatest common divisor of two integers a and b
// greatestCommonDivisor(a: 3, b: 5) == 1
// greatestCommonDivisor(a: 25, b: 15) == 5
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if b == 0 {
return a
}
return greatestCommonDivisor(a: b, b: a % b)
}
```
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if b == 0 {
return a
}
return greatestCommonDivisor(a: b, b: a % b)
}
```swift
// Return a greatest common divisor of two integers a and b
// greatestCommonDivisor(a: 3, b: 5) == 1
// greatestCommonDivisor(a: 25, b: 15) == 5
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if b == 0 {
return a
}
return greatestCommonDivisor(a: b, b: a % b)
}
```
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if b == 0 {
return a
}
return greatestCommonDivisor(a: b, b: a % b)
}
```swift
// Return a greatest common divisor of two integers a and b
// greatestCommonDivisor(a: 3, b: 5) == 1
// greatestCommonDivisor(a: 25, b: 15) == 5
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if b == 0 {
return a
}
return greatestCommonDivisor(a: b, b: a % b)
}
```
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if b == 0 {
return a
} else {
return greatestCommonDivisor(a: b, b: a % b)
}
}
```swift
// Return a greatest common divisor of two integers a and b
// greatestCommonDivisor(a: 3, b: 5) == 1
// greatestCommonDivisor(a: 25, b: 15) == 5
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if b == 0 {
return a
} else {
return greatestCommonDivisor(a: b, b: a % b)
}
}
```
func greatestCommonDivisor(a: Int, b: Int) -> Int {
// TODO: implement this function
}
```swift
// Return a greatest common divisor of two integers a and b
// greatestCommonDivisor(a: 3, b: 5) == 1
// greatestCommonDivisor(a: 25, b: 15) == 5
func greatestCommonDivisor(a: Int, b: Int) -> Int {
// TODO: implement this function
}
```
} // missing return in global function expected to return 'Int'
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if b == 0 {
return a
} else {
return greatestCommonDivisor(a: b, b: a % b)
}
}
```swift
// Return a greatest common divisor of two integers a and b
// greatestCommonDivisor(a: 3, b: 5) == 1
// greatestCommonDivisor(a: 25, b: 15) == 5
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if b == 0 {
return a
} else {
return greatestCommonDivisor(a: b, b: a % b)
}
}
```
func greatestCommonDivisor(a: Int, b: Int) -> Int {
// 1. If b is zero, return a
if b == 0 {
return a
}
// 2. Otherwise, return greatestCommonDivisor(a: b, b: a % b)
return greatestCommonDivisor(a: b, b: a % b)
}
```swift
// Return a greatest common divisor of two integers a and b
// greatestCommonDivisor(a: 3, b: 5) == 1
// greatestCommonDivisor(a: 25, b: 15) == 5
func greatestCommonDivisor(a: Int, b: Int) -> Int {
// 1. If b is zero, return a
if b == 0 {
return a
}
// 2. Otherwise, return greatestCommonDivisor(a: b, b: a % b)
return greatestCommonDivisor(a: b, b: a % b)
}
```
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if a == 0 || b == 0 {
return 0
}
if a == b {
return a
}
if a > b {
return greatestCommonDivisor(a: a - b, b: b)
} else {
return greatestCommonDivisor(a: a, b: b - a)
}
}
```swift
// Return a greatest common divisor of two integers a and b
// greatestCommonDivisor(a: 3, b: 5) == 1
// greatestCommonDivisor(a: 25, b: 15) == 5
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if a == 0 || b == 0 {
return 0
}
if a == b {
return a
}
if a > b {
return greatestCommonDivisor(a: a - b, b: b)
} else {
return greatestCommonDivisor(a: a, b: b - a)
}
}
```
func greatestCommonDivisor(a: Int, b: Int) -> Int {
// 1. Find a remainder of a and b
let remainder = a % b
// 2. If remainder is zero, then b is the greatest common divisor
if remainder == 0 {
return b
}
// 3. Otherwise, find a greatest common divisor of b and remainder
return greatestCommonDivisor(a: b, b: remainder)
}
```swift
// Return a greatest common divisor of two integers a and b
// greatestCommonDivisor(a: 3, b: 5) == 1
// greatestCommonDivisor(a: 25, b: 15) == 5
func greatestCommonDivisor(a: Int, b: Int) -> Int {
// 1. Find a remainder of a and b
let remainder = a % b
// 2. If remainder is zero, then b is the greatest common divisor
if remainder == 0 {
return b
}
// 3. Otherwise, find a greatest common divisor of b and remainder
return greatestCommonDivisor(a: b, b: remainder)
}
```
func allPrefixes(string: String) -> [String] {
var result: [String] = []
for i in 0...string.count {
result.append(string.prefix(i))
}
return result
}
```swift
// Return array of all prefixes from shortest to longest of the input string
// allPrefixes(string: "abc") == ["a", "ab", "abc"]
func allPrefixes(string: String) -> [String] {
var result: [String] = []
for i in 0...string.count {
result.append(string.prefix(i))
}
return result
}
```
result.append(string.prefix(i)) // no exact matches in call to instance method 'append'
func allPrefixes(string: String) -> [String] {
var result: [String] = []
for index in 0...string.count {
result.append(string.prefix(index))
}
return result
}
```swift
// Return array of all prefixes from shortest to longest of the input string
// allPrefixes(string: "abc") == ["a", "ab", "abc"]
func allPrefixes(string: String) -> [String] {
var result: [String] = []
for index in 0...string.count {
result.append(string.prefix(index))
}
return result
}
```
result.append(string.prefix(index)) // no exact matches in call to instance method 'append'
func allPrefixes(string: String) -> [String] {
var result: [String] = []
for i in 0...string.count {
result.append(String(string.prefix(i)))
}
return result
}
```swift
// Return array of all prefixes from shortest to longest of the input string
// allPrefixes(string: "abc") == ["a", "ab", "abc"]
func allPrefixes(string: String) -> [String] {
var result: [String] = []
for i in 0...string.count {
result.append(String(string.prefix(i)))
}
return result
}
```
// XCTAssertTrue failed
func allPrefixes(string: String) -> [String] {
var result: [String] = []
for i in 0...string.count {
result.append(String(string.prefix(i)))
}
return result
}
```swift
// Return array of all prefixes from shortest to longest of the input string
// allPrefixes(string: "abc") == ["a", "ab", "abc"]
func allPrefixes(string: String) -> [String] {
var result: [String] = []
for i in 0...string.count {
result.append(String(string.prefix(i)))
}
return result
}
```
// XCTAssertTrue failed
func allPrefixes(string: String) -> [String] {
var result: [String] = []
for i in 0...string.count {
result.append(String(string.prefix(i)))
}
return result
}
```swift
// Return array of all prefixes from shortest to longest of the input string
// allPrefixes(string: "abc") == ["a", "ab", "abc"]
func allPrefixes(string: String) -> [String] {
var result: [String] = []
for i in 0...string.count {
result.append(String(string.prefix(i)))
}
return result
}
```
// XCTAssertTrue failed
func allPrefixes(string: String) -> [String] {
var result: [String] = []
for i in 0...string.count {
result.append(String(string.prefix(i)))
}
return result
}
```swift
// Return array of all prefixes from shortest to longest of the input string
// allPrefixes(string: "abc") == ["a", "ab", "abc"]
func allPrefixes(string: String) -> [String] {
var result: [String] = []
for i in 0...string.count {
result.append(String(string.prefix(i)))
}
return result
}
```
// XCTAssertTrue failed
func allPrefixes(string: String) -> [String] {
var result: [String] = []
for i in 0...string.count {
result.append(string.prefix(i))
}
return result
}
```swift
// Return array of all prefixes from shortest to longest of the input string
// allPrefixes(string: "abc") == ["a", "ab", "abc"]
func allPrefixes(string: String) -> [String] {
var result: [String] = []
for i in 0...string.count {
result.append(string.prefix(i))
}
return result
}
```
result.append(string.prefix(i)) // no exact matches in call to instance method 'append'
func allPrefixes(string: String) -> [String] {
var result: [String] = []
for index in 0...string.count {
result.append(String(string.prefix(index)))
}
return result
}
```swift
// Return array of all prefixes from shortest to longest of the input string
// allPrefixes(string: "abc") == ["a", "ab", "abc"]
func allPrefixes(string: String) -> [String] {
var result: [String] = []
for index in 0...string.count {
result.append(String(string.prefix(index)))
}
return result
}
```
// XCTAssertTrue failed
func allPrefixes(string: String) -> [String] {
var result: [String] = []
for i in 0...string.count {
result.append(String(string.prefix(i)))
}
return result
}
```swift
// Return array of all prefixes from shortest to longest of the input string
// allPrefixes(string: "abc") == ["a", "ab", "abc"]
func allPrefixes(string: String) -> [String] {
var result: [String] = []
for i in 0...string.count {
result.append(String(string.prefix(i)))
}
return result
}
```
// XCTAssertTrue failed
func allPrefixes(string: String) -> [String] {
var result: [String] = []
for i in 1...string.count {
let prefix = string.prefix(i)
result.append(String(prefix))
}
return result
}
```swift
// Return array of all prefixes from shortest to longest of the input string
// allPrefixes(string: "abc") == ["a", "ab", "abc"]
func allPrefixes(string: String) -> [String] {
var result: [String] = []
for i in 1...string.count {
let prefix = string.prefix(i)
result.append(String(prefix))
}
return result
}
```
// Fatal error: Range requires lowerBound <= upperBound
func stringSequence(n: Int) -> String {
var result = ""
for i in 0...n {
result += "\(i) "
}
return result
}
```swift
// Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// stringSequence(n: 0) == "0"
// stringSequence(n: 5) == "0 1 2 3 4 5"
func stringSequence(n: Int) -> String {
var result = ""
for i in 0...n {
result += "\(i) "
}
return result
}
```
// XCTAssertTrue failed
func stringSequence(n: Int) -> String {
var result = ""
for i in 0...n {
result += "\(i) "
}
return result
}
```swift
// Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// stringSequence(n: 0) == "0"
// stringSequence(n: 5) == "0 1 2 3 4 5"
func stringSequence(n: Int) -> String {
var result = ""
for i in 0...n {
result += "\(i) "
}
return result
}
```
// XCTAssertTrue failed
func stringSequence(n: Int) -> String {
var result = ""
for i in 0...n {
result += "\(i) "
}
return result
}
```swift
// Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// stringSequence(n: 0) == "0"
// stringSequence(n: 5) == "0 1 2 3 4 5"
func stringSequence(n: Int) -> String {
var result = ""
for i in 0...n {
result += "\(i) "
}
return result
}
```
// XCTAssertTrue failed
func stringSequence(n: Int) -> String {
var result = ""
for i in 0...n {
result += "\(i) "
}
return result
}
```swift
// Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// stringSequence(n: 0) == "0"
// stringSequence(n: 5) == "0 1 2 3 4 5"
func stringSequence(n: Int) -> String {
var result = ""
for i in 0...n {
result += "\(i) "
}
return result
}
```
// XCTAssertTrue failed
func stringSequence(n: Int) -> String {
var result = ""
for i in 0...n {
result += "\(i) "
}
return result
}
```swift
// Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// stringSequence(n: 0) == "0"
// stringSequence(n: 5) == "0 1 2 3 4 5"
func stringSequence(n: Int) -> String {
var result = ""
for i in 0...n {
result += "\(i) "
}
return result
}
```
// XCTAssertTrue failed
func stringSequence(n: Int) -> String {
var result = ""
for i in 0...n {
result += "\(i) "
}
return result
}
```swift
// Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// stringSequence(n: 0) == "0"
// stringSequence(n: 5) == "0 1 2 3 4 5"
func stringSequence(n: Int) -> String {
var result = ""
for i in 0...n {
result += "\(i) "
}
return result
}
```
// XCTAssertTrue failed
func stringSequence(n: Int) -> String {
var result = ""
for i in 0...n {
result += "\(i) "
}
return result
}
```swift
// Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// stringSequence(n: 0) == "0"
// stringSequence(n: 5) == "0 1 2 3 4 5"
func stringSequence(n: Int) -> String {
var result = ""
for i in 0...n {
result += "\(i) "
}
return result
}
```
// XCTAssertTrue failed
func stringSequence(n: Int) -> String {
var result = ""
for i in 0...n {
result += "\(i) "
}
return result
}
```swift
// Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// stringSequence(n: 0) == "0"
// stringSequence(n: 5) == "0 1 2 3 4 5"
func stringSequence(n: Int) -> String {
var result = ""
for i in 0...n {
result += "\(i) "
}
return result
}
```
// XCTAssertTrue failed
func stringSequence(n: Int) -> String {
var result = ""
for i in 0...n {
result += "\(i) "
}
return result
}
```swift
// Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// stringSequence(n: 0) == "0"
// stringSequence(n: 5) == "0 1 2 3 4 5"
func stringSequence(n: Int) -> String {
var result = ""
for i in 0...n {
result += "\(i) "
}
return result
}
```
// XCTAssertTrue failed
func stringSequence(n: Int) -> String {
var result = ""
for i in 0...n {
result += "\(i) "
}
return result
}
```swift
// Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// stringSequence(n: 0) == "0"
// stringSequence(n: 5) == "0 1 2 3 4 5"
func stringSequence(n: Int) -> String {
var result = ""
for i in 0...n {
result += "\(i) "
}
return result
}
```
// XCTAssertTrue failed
func countDistinctCharacters(string: String) -> Int {
// TODO: Write your code here
}
```swift
// Given a string, find out how many distinct characters (regardless of case) does it consist of
// countDistinctCharacters(string: "xyzXYZ") == 3
// countDistinctCharacters(string: "Jerry") == 4
func countDistinctCharacters(string: String) -> Int {
// TODO: Write your code here
}
```
} // missing return in global function expected to return 'Int'
func countDistinctCharacters(string: String) -> Int {
// TODO: Write your code here
}
```swift
// Given a string, find out how many distinct characters (regardless of case) does it consist of
// countDistinctCharacters(string: "xyzXYZ") == 3
// countDistinctCharacters(string: "Jerry") == 4
func countDistinctCharacters(string: String) -> Int {
// TODO: Write your code here
}
```
} // missing return in global function expected to return 'Int'
func countDistinctCharacters(string: String) -> Int {
// TODO: Write your code here
}
```swift
// Given a string, find out how many distinct characters (regardless of case) does it consist of
// countDistinctCharacters(string: "xyzXYZ") == 3
// countDistinctCharacters(string: "Jerry") == 4
func countDistinctCharacters(string: String) -> Int {
// TODO: Write your code here
}
```
} // missing return in global function expected to return 'Int'
func countDistinctCharacters(string: String) -> Int {
var count = 0
var characters = Set<Character>()
for character in string {
if!characters.contains(character) {
characters.insert(character)
count += 1
}
}
return count
}
```swift
// Given a string, find out how many distinct characters (regardless of case) does it consist of
// countDistinctCharacters(string: "xyzXYZ") == 3
// countDistinctCharacters(string: "Jerry") == 4
func countDistinctCharacters(string: String) -> Int {
var count = 0
var characters = Set<Character>()
for character in string {
if!characters.contains(character) {
characters.insert(character)
count += 1
}
}
return count
}
```
if!characters.contains(character) { // expected expression, var, or let in 'if' condition
func countDistinctCharacters(string: String) -> Int {
return Set(string.lowercased()).count
}
```swift
// Given a string, find out how many distinct characters (regardless of case) does it consist of
// countDistinctCharacters(string: "xyzXYZ") == 3
// countDistinctCharacters(string: "Jerry") == 4
func countDistinctCharacters(string: String) -> Int {
return Set(string.lowercased()).count
}
```
func countDistinctCharacters(string: String) -> Int {
var distinctCharacters = Set<Character>()
for character in string {
distinctCharacters.insert(character)
}
return distinctCharacters.count
}
```swift
// Given a string, find out how many distinct characters (regardless of case) does it consist of
// countDistinctCharacters(string: "xyzXYZ") == 3
// countDistinctCharacters(string: "Jerry") == 4
func countDistinctCharacters(string: String) -> Int {
var distinctCharacters = Set<Character>()
for character in string {
distinctCharacters.insert(character)
}
return distinctCharacters.count
}
```
// XCTAssertTrue failed
func countDistinctCharacters(string: String) -> Int {
var distinctCharacters = Set<Character>()
for character in string {
distinctCharacters.insert(character)
}
return distinctCharacters.count
}
```swift
// Given a string, find out how many distinct characters (regardless of case) does it consist of
// countDistinctCharacters(string: "xyzXYZ") == 3
// countDistinctCharacters(string: "Jerry") == 4
func countDistinctCharacters(string: String) -> Int {
var distinctCharacters = Set<Character>()
for character in string {
distinctCharacters.insert(character)
}
return distinctCharacters.count
}
```
// XCTAssertTrue failed
func countDistinctCharacters(string: String) -> Int {
// TODO: Write your code here
}
```swift
// Given a string, find out how many distinct characters (regardless of case) does it consist of
// countDistinctCharacters(string: "xyzXYZ") == 3
// countDistinctCharacters(string: "Jerry") == 4
func countDistinctCharacters(string: String) -> Int {
// TODO: Write your code here
}
```
} // missing return in global function expected to return 'Int'
func countDistinctCharacters(string: String) -> Int {
var distinctCharacters = Set<Character>()
for character in string {
distinctCharacters.insert(character)
}
return distinctCharacters.count
}
```swift
// Given a string, find out how many distinct characters (regardless of case) does it consist of
// countDistinctCharacters(string: "xyzXYZ") == 3
// countDistinctCharacters(string: "Jerry") == 4
func countDistinctCharacters(string: String) -> Int {
var distinctCharacters = Set<Character>()
for character in string {
distinctCharacters.insert(character)
}
return distinctCharacters.count
}
```
// XCTAssertTrue failed
func countDistinctCharacters(string: String) -> Int {
var distinctCharacters = Set<Character>()
for character in string {
distinctCharacters.insert(character)
}
return distinctCharacters.count
}
```swift
// Given a string, find out how many distinct characters (regardless of case) does it consist of
// countDistinctCharacters(string: "xyzXYZ") == 3
// countDistinctCharacters(string: "Jerry") == 4
func countDistinctCharacters(string: String) -> Int {
var distinctCharacters = Set<Character>()
for character in string {
distinctCharacters.insert(character)
}
return distinctCharacters.count
}
```
// XCTAssertTrue failed
func parseMusic(musicString: String) -> [Int] {
var result: [Int] = []
for char in musicString {
switch char {
case "o":
result.append(4)
case "o|":
result.append(2)
case ".|":
result.append(1)
default:
break
}
}
return result
}
```swift
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - quater note, lasts one beat
// parseMusic(musicString: "o o| .| o| o| .| .| .| .| o o") == [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
func parseMusic(musicString: String) -> [Int] {
var result: [Int] = []
for char in musicString {
switch char {
case "o":
result.append(4)
case "o|":
result.append(2)
case ".|":
result.append(1)
default:
break
}
}
return result
}
```
case "o|": // expression pattern of type 'String' cannot match values of type 'Character'
case ".|": // expression pattern of type 'String' cannot match values of type 'Character'
func parseMusic(musicString: String) -> [Int] {
// Write your code here
}
```swift
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - quater note, lasts one beat
// parseMusic(musicString: "o o| .| o| o| .| .| .| .| o o") == [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
func parseMusic(musicString: String) -> [Int] {
// Write your code here
}
```
} // missing return in global function expected to return '[Int]'
func parseMusic(musicString: String) -> [Int] {
var result: [Int] = []
for char in musicString {
switch char {
case "o":
result.append(4)
case "o|":
result.append(2)
case ".|":
result.append(1)
default:
break
}
}
return result
}
```swift
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - quater note, lasts one beat
// parseMusic(musicString: "o o| .| o| o| .| .| .| .| o o") == [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
func parseMusic(musicString: String) -> [Int] {
var result: [Int] = []
for char in musicString {
switch char {
case "o":
result.append(4)
case "o|":
result.append(2)
case ".|":
result.append(1)
default:
break
}
}
return result
}
```
case "o|": // expression pattern of type 'String' cannot match values of type 'Character'
case ".|": // expression pattern of type 'String' cannot match values of type 'Character'
func parseMusic(musicString: String) -> [Int] {
// your code here
}
```swift
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - quater note, lasts one beat
// parseMusic(musicString: "o o| .| o| o| .| .| .| .| o o") == [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
func parseMusic(musicString: String) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func parseMusic(musicString: String) -> [Int] {
// your code here
}
```swift
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - quater note, lasts one beat
// parseMusic(musicString: "o o| .| o| o| .| .| .| .| o o") == [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
func parseMusic(musicString: String) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func parseMusic(musicString: String) -> [Int] {
var result = [Int]()
var currentNote = 0
for char in musicString {
switch char {
case "o":
currentNote += 4
case "o|":
currentNote += 2
case ".|":
currentNote += 1
default:
break
}
if char == " " {
result.append(currentNote)
currentNote = 0
}
}
return result
}
```swift
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - quater note, lasts one beat
// parseMusic(musicString: "o o| .| o| o| .| .| .| .| o o") == [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
func parseMusic(musicString: String) -> [Int] {
var result = [Int]()
var currentNote = 0
for char in musicString {
switch char {
case "o":
currentNote += 4
case "o|":
currentNote += 2
case ".|":
currentNote += 1
default:
break
}
if char == " " {
result.append(currentNote)
currentNote = 0
}
}
return result
}
```
case "o|": // expression pattern of type 'String' cannot match values of type 'Character'
case ".|": // expression pattern of type 'String' cannot match values of type 'Character'
func parseMusic(musicString: String) -> [Int] {
var result: [Int] = []
var temp: String = ""
for char in musicString {
if char == "o" {
result.append(4)
} else if char == "o|" {
result.append(2)
} else if char == ".|" {
result.append(1)
} else {
temp += String(char)
}
}
if temp!= "" {
result.append(Int(temp)!)
}
return result
}
```swift
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - quater note, lasts one beat
// parseMusic(musicString: "o o| .| o| o| .| .| .| .| o o") == [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
func parseMusic(musicString: String) -> [Int] {
var result: [Int] = []
var temp: String = ""
for char in musicString {
if char == "o" {
result.append(4)
} else if char == "o|" {
result.append(2)
} else if char == ".|" {
result.append(1)
} else {
temp += String(char)
}
}
if temp!= "" {
result.append(Int(temp)!)
}
return result
}
```
} else if char == "o|" { // binary operator '==' cannot be applied to operands of type 'Character' and 'String'
} else if char == ".|" { // binary operator '==' cannot be applied to operands of type 'Character' and 'String'
if temp!= "" { // use of '=' in a boolean context, did you mean '=='?
if temp!= "" { // '=' must have consistent whitespace on both sides
if temp!= "" { // cannot force unwrap value of non-optional type 'String'
func parseMusic(musicString: String) -> [Int] {
var result = [Int]()
var currentNote = 0
for char in musicString {
switch char {
case "o":
currentNote += 4
case "o|":
currentNote += 2
case ".|":
currentNote += 1
default:
break
}
if char == " " {
result.append(currentNote)
currentNote = 0
}
}
return result
}
```swift
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - quater note, lasts one beat
// parseMusic(musicString: "o o| .| o| o| .| .| .| .| o o") == [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
func parseMusic(musicString: String) -> [Int] {
var result = [Int]()
var currentNote = 0
for char in musicString {
switch char {
case "o":
currentNote += 4
case "o|":
currentNote += 2
case ".|":
currentNote += 1
default:
break
}
if char == " " {
result.append(currentNote)
currentNote = 0
}
}
return result
}
```
case "o|": // expression pattern of type 'String' cannot match values of type 'Character'
case ".|": // expression pattern of type 'String' cannot match values of type 'Character'
func parseMusic(musicString: String) -> [Int] {
var result = [Int]()
var beats = 0
for char in musicString {
switch char {
case "o":
beats += 4
case "o|":
beats += 2
case ".|":
beats += 1
default:
break
}
if char == " " || char == "|" {
result.append(beats)
beats = 0
}
}
return result
}
```swift
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - quater note, lasts one beat
// parseMusic(musicString: "o o| .| o| o| .| .| .| .| o o") == [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
func parseMusic(musicString: String) -> [Int] {
var result = [Int]()
var beats = 0
for char in musicString {
switch char {
case "o":
beats += 4
case "o|":
beats += 2
case ".|":
beats += 1
default:
break
}
if char == " " || char == "|" {
result.append(beats)
beats = 0
}
}
return result
}
```
case "o|": // expression pattern of type 'String' cannot match values of type 'Character'
case ".|": // expression pattern of type 'String' cannot match values of type 'Character'
func parseMusic(musicString: String) -> [Int] {
var result: [Int] = []
let notes = musicString.split(separator: " ")
for note in notes {
if note == "o" {
result.append(4)
} else if note == "o|" {
result.append(2)
} else if note == ".|" {
result.append(1)
}
}
return result
}
```swift
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - quater note, lasts one beat
// parseMusic(musicString: "o o| .| o| o| .| .| .| .| o o") == [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
func parseMusic(musicString: String) -> [Int] {
var result: [Int] = []
let notes = musicString.split(separator: " ")
for note in notes {
if note == "o" {
result.append(4)
} else if note == "o|" {
result.append(2)
} else if note == ".|" {
result.append(1)
}
}
return result
}
```
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while let range = string.range(of: substring, range: index..<string.endIndex) {
count += 1
index = range.upperBound
}
return count
}
```swift
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// howManyTimes(string: "", substring: "a") == 0
// howManyTimes(string: "aaa", substring: "a") == 3
// howManyTimes(string: "aaaa", substring: "aa") == 3
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while let range = string.range(of: substring, range: index..<string.endIndex) {
count += 1
index = range.upperBound
}
return count
}
```
// XCTAssertTrue failed
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var startIndex = string.startIndex
while let range = string.range(of: substring, range: startIndex..<string.endIndex) {
count += 1
startIndex = range.upperBound
}
return count
}
```swift
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// howManyTimes(string: "", substring: "a") == 0
// howManyTimes(string: "aaa", substring: "a") == 3
// howManyTimes(string: "aaaa", substring: "aa") == 3
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var startIndex = string.startIndex
while let range = string.range(of: substring, range: startIndex..<string.endIndex) {
count += 1
startIndex = range.upperBound
}
return count
}
```
// XCTAssertTrue failed
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while let range = string.range(of: substring, options: [], range: index..<string.endIndex, locale: nil) {
count += 1
index = range.upperBound
}
return count
}
```swift
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// howManyTimes(string: "", substring: "a") == 0
// howManyTimes(string: "aaa", substring: "a") == 3
// howManyTimes(string: "aaaa", substring: "aa") == 3
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while let range = string.range(of: substring, options: [], range: index..<string.endIndex, locale: nil) {
count += 1
index = range.upperBound
}
return count
}
```
// XCTAssertTrue failed
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var startIndex = string.startIndex
while let range = string.range(of: substring, options: [], range: startIndex..<string.endIndex, locale: nil) {
count += 1
startIndex = range.upperBound
}
return count
}
```swift
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// howManyTimes(string: "", substring: "a") == 0
// howManyTimes(string: "aaa", substring: "a") == 3
// howManyTimes(string: "aaaa", substring: "aa") == 3
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var startIndex = string.startIndex
while let range = string.range(of: substring, options: [], range: startIndex..<string.endIndex, locale: nil) {
count += 1
startIndex = range.upperBound
}
return count
}
```
// XCTAssertTrue failed
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while let range = string.range(of: substring, options: [], range: index..<string.endIndex, locale: nil) {
count += 1
index = range.upperBound
}
return count
}
```swift
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// howManyTimes(string: "", substring: "a") == 0
// howManyTimes(string: "aaa", substring: "a") == 3
// howManyTimes(string: "aaaa", substring: "aa") == 3
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while let range = string.range(of: substring, options: [], range: index..<string.endIndex, locale: nil) {
count += 1
index = range.upperBound
}
return count
}
```
// XCTAssertTrue failed
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while index < string.endIndex {
if string.substring(from: index) == substring {
count += 1
index = string.index(index, offsetBy: substring.count)
} else {
index = string.index(index, offsetBy: 1)
}
}
return count
}
```swift
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// howManyTimes(string: "", substring: "a") == 0
// howManyTimes(string: "aaa", substring: "a") == 3
// howManyTimes(string: "aaaa", substring: "aa") == 3
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while index < string.endIndex {
if string.substring(from: index) == substring {
count += 1
index = string.index(index, offsetBy: substring.count)
} else {
index = string.index(index, offsetBy: 1)
}
}
return count
}
```
if string.substring(from: index) == substring { // 'substring(from:)' is deprecated: Please use String slicing subscript with a 'partial range from' operator.
// XCTAssertTrue failed
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while let range = string.range(of: substring, options: [], range: index..<string.endIndex, locale: nil) {
count += 1
index = range.upperBound
}
return count
}
```swift
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// howManyTimes(string: "", substring: "a") == 0
// howManyTimes(string: "aaa", substring: "a") == 3
// howManyTimes(string: "aaaa", substring: "aa") == 3
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while let range = string.range(of: substring, options: [], range: index..<string.endIndex, locale: nil) {
count += 1
index = range.upperBound
}
return count
}
```
// XCTAssertTrue failed
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while index < string.endIndex {
let range = string.range(of: substring, range: index..<string.endIndex)
if let range = range {
count += 1
index = range.upperBound
} else {
break
}
}
return count
}
```swift
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// howManyTimes(string: "", substring: "a") == 0
// howManyTimes(string: "aaa", substring: "a") == 3
// howManyTimes(string: "aaaa", substring: "aa") == 3
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while index < string.endIndex {
let range = string.range(of: substring, range: index..<string.endIndex)
if let range = range {
count += 1
index = range.upperBound
} else {
break
}
}
return count
}
```
// XCTAssertTrue failed
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while let range = string.range(of: substring, range: index..<string.endIndex) {
count += 1
index = range.upperBound
}
return count
}
```swift
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// howManyTimes(string: "", substring: "a") == 0
// howManyTimes(string: "aaa", substring: "a") == 3
// howManyTimes(string: "aaaa", substring: "aa") == 3
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while let range = string.range(of: substring, range: index..<string.endIndex) {
count += 1
index = range.upperBound
}
return count
}
```
// XCTAssertTrue failed
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while let range = string.range(of: substring, options: [], range: index..<string.endIndex, locale: nil) {
count += 1
index = range.upperBound
}
return count
}
```swift
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// howManyTimes(string: "", substring: "a") == 0
// howManyTimes(string: "aaa", substring: "a") == 3
// howManyTimes(string: "aaaa", substring: "aa") == 3
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while let range = string.range(of: substring, options: [], range: index..<string.endIndex, locale: nil) {
count += 1
index = range.upperBound
}
return count
}
```
// XCTAssertTrue failed
func sortNumbers(numbers: String) -> String {
let numbers = numbers.components(separatedBy: " ")
let sortedNumbers = numbers.sorted()
return sortedNumbers.joined(separator: " ")
}
```swift
// Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// sortNumbers(numbers: "three one five") == "one three five"
func sortNumbers(numbers: String) -> String {
let numbers = numbers.components(separatedBy: " ")
let sortedNumbers = numbers.sorted()
return sortedNumbers.joined(separator: " ")
}
```
// XCTAssertTrue failed
func sortNumbers(numbers: String) -> String {
let numbers = numbers.components(separatedBy: " ")
let sortedNumbers = numbers.sorted()
return sortedNumbers.joined(separator: " ")
}
```swift
// Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// sortNumbers(numbers: "three one five") == "one three five"
func sortNumbers(numbers: String) -> String {
let numbers = numbers.components(separatedBy: " ")
let sortedNumbers = numbers.sorted()
return sortedNumbers.joined(separator: " ")
}
```
// XCTAssertTrue failed
func sortNumbers(numbers: String) -> String {
// Write your code here.
}
```swift
// Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// sortNumbers(numbers: "three one five") == "one three five"
func sortNumbers(numbers: String) -> String {
// Write your code here.
}
```
} // missing return in global function expected to return 'String'
func sortNumbers(numbers: String) -> String {
// Your code here
}
```swift
// Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// sortNumbers(numbers: "three one five") == "one three five"
func sortNumbers(numbers: String) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func sortNumbers(numbers: String) -> String {
let numbers = numbers.split(separator: " ")
let sorted = numbers.sorted()
return sorted.joined(separator: " ")
}
```swift
// Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// sortNumbers(numbers: "three one five") == "one three five"
func sortNumbers(numbers: String) -> String {
let numbers = numbers.split(separator: " ")
let sorted = numbers.sorted()
return sorted.joined(separator: " ")
}
```
// XCTAssertTrue failed
func sortNumbers(numbers: String) -> String {
// TODO: Write your code here
return ""
}
```swift
// Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// sortNumbers(numbers: "three one five") == "one three five"
func sortNumbers(numbers: String) -> String {
// TODO: Write your code here
return ""
}
```
// XCTAssertTrue failed
func sortNumbers(numbers: String) -> String {
let numbers = numbers.split(separator: " ").map { String($0) }
let sortedNumbers = numbers.sorted()
return sortedNumbers.joined(separator: " ")
}
```swift
// Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// sortNumbers(numbers: "three one five") == "one three five"
func sortNumbers(numbers: String) -> String {
let numbers = numbers.split(separator: " ").map { String($0) }
let sortedNumbers = numbers.sorted()
return sortedNumbers.joined(separator: " ")
}
```
// XCTAssertTrue failed
func sortNumbers(numbers: String) -> String {
// Write your code here.
let numbers = numbers.components(separatedBy: " ")
let sortedNumbers = numbers.sorted()
return sortedNumbers.joined(separator: " ")
}
```swift
// Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// sortNumbers(numbers: "three one five") == "one three five"
func sortNumbers(numbers: String) -> String {
// Write your code here.
let numbers = numbers.components(separatedBy: " ")
let sortedNumbers = numbers.sorted()
return sortedNumbers.joined(separator: " ")
}
```
// XCTAssertTrue failed
func sortNumbers(numbers: String) -> String {
let numbers = numbers.components(separatedBy: " ")
let sortedNumbers = numbers.sorted()
return sortedNumbers.joined(separator: " ")
}
```swift
// Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// sortNumbers(numbers: "three one five") == "one three five"
func sortNumbers(numbers: String) -> String {
let numbers = numbers.components(separatedBy: " ")
let sortedNumbers = numbers.sorted()
return sortedNumbers.joined(separator: " ")
}
```
// XCTAssertTrue failed
func sortNumbers(numbers: String) -> String {
let numbers = numbers.components(separatedBy: " ")
let sortedNumbers = numbers.sorted()
return sortedNumbers.joined(separator: " ")
}
```swift
// Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// sortNumbers(numbers: "three one five") == "one three five"
func sortNumbers(numbers: String) -> String {
let numbers = numbers.components(separatedBy: " ")
let sortedNumbers = numbers.sorted()
return sortedNumbers.joined(separator: " ")
}
```
// XCTAssertTrue failed
func findClosestElements(numbers: [Double]) -> (Double, Double) {
// TODO: implement this function
}
```swift
// From a supplied array of numbers (of length at least two) select and return two that are the closest to each
// other and return them in order (smaller number, larger number).
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2)
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) == (2.0, 2.0)
func findClosestElements(numbers: [Double]) -> (Double, Double) {
// TODO: implement this function
}
```
} // missing return in global function expected to return '(Double, Double)'
func findClosestElements(numbers: [Double]) -> (Double, Double) {
return (0, 0)
}
```swift
// From a supplied array of numbers (of length at least two) select and return two that are the closest to each
// other and return them in order (smaller number, larger number).
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2)
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) == (2.0, 2.0)
func findClosestElements(numbers: [Double]) -> (Double, Double) {
return (0, 0)
}
```
// XCTAssertTrue failed
func findClosestElements(numbers: [Double]) -> (Double, Double) {
let sortedNumbers = numbers.sorted()
var closestElements = (sortedNumbers[0], sortedNumbers[1])
var closestDistance = abs(closestElements.0 - closestElements.1)
for i in 1..<sortedNumbers.count - 1 {
let distance = abs(sortedNumbers[i] - sortedNumbers[i + 1])
if distance < closestDistance {
closestDistance = distance
closestElements = (sortedNumbers[i], sortedNumbers[i + 1])
}
}
return closestElements
}
```swift
// From a supplied array of numbers (of length at least two) select and return two that are the closest to each
// other and return them in order (smaller number, larger number).
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2)
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) == (2.0, 2.0)
func findClosestElements(numbers: [Double]) -> (Double, Double) {
let sortedNumbers = numbers.sorted()
var closestElements = (sortedNumbers[0], sortedNumbers[1])
var closestDistance = abs(closestElements.0 - closestElements.1)
for i in 1..<sortedNumbers.count - 1 {
let distance = abs(sortedNumbers[i] - sortedNumbers[i + 1])
if distance < closestDistance {
closestDistance = distance
closestElements = (sortedNumbers[i], sortedNumbers[i + 1])
}
}
return closestElements
}
```
func findClosestElements(numbers: [Double]) -> (Double, Double) {
// TODO: Implement this function
}
```swift
// From a supplied array of numbers (of length at least two) select and return two that are the closest to each
// other and return them in order (smaller number, larger number).
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2)
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) == (2.0, 2.0)
func findClosestElements(numbers: [Double]) -> (Double, Double) {
// TODO: Implement this function
}
```
} // missing return in global function expected to return '(Double, Double)'
func findClosestElements(numbers: [Double]) -> (Double, Double) {
// TODO: implement this function
}
```swift
// From a supplied array of numbers (of length at least two) select and return two that are the closest to each
// other and return them in order (smaller number, larger number).
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2)
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) == (2.0, 2.0)
func findClosestElements(numbers: [Double]) -> (Double, Double) {
// TODO: implement this function
}
```
} // missing return in global function expected to return '(Double, Double)'
func findClosestElements(numbers: [Double]) -> (Double, Double) {
// TODO: Implement this function
}
```swift
// From a supplied array of numbers (of length at least two) select and return two that are the closest to each
// other and return them in order (smaller number, larger number).
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2)
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) == (2.0, 2.0)
func findClosestElements(numbers: [Double]) -> (Double, Double) {
// TODO: Implement this function
}
```
} // missing return in global function expected to return '(Double, Double)'
func findClosestElements(numbers: [Double]) -> (Double, Double) {
var closest = (numbers[0], numbers[1])
for i in 0..<numbers.count - 1 {
let (a, b) = (numbers[i], numbers[i + 1])
if abs(a - b) < abs(closest.0 - closest.1) {
closest = (a, b)
}
}
return closest
}
```swift
// From a supplied array of numbers (of length at least two) select and return two that are the closest to each
// other and return them in order (smaller number, larger number).
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2)
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) == (2.0, 2.0)
func findClosestElements(numbers: [Double]) -> (Double, Double) {
var closest = (numbers[0], numbers[1])
for i in 0..<numbers.count - 1 {
let (a, b) = (numbers[i], numbers[i + 1])
if abs(a - b) < abs(closest.0 - closest.1) {
closest = (a, b)
}
}
return closest
}
```
// XCTAssertTrue failed
func findClosestElements(numbers: [Double]) -> (Double, Double) {
var closestNumbers = (Double.greatestFiniteMagnitude, Double.greatestFiniteMagnitude)
for i in 0..<numbers.count {
let number = numbers[i]
if number < closestNumbers.0 {
closestNumbers.0 = number
closestNumbers.1 = numbers[i + 1]
} else if number < closestNumbers.1 {
closestNumbers.1 = number
}
}
return closestNumbers
}
```swift
// From a supplied array of numbers (of length at least two) select and return two that are the closest to each
// other and return them in order (smaller number, larger number).
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2)
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) == (2.0, 2.0)
func findClosestElements(numbers: [Double]) -> (Double, Double) {
var closestNumbers = (Double.greatestFiniteMagnitude, Double.greatestFiniteMagnitude)
for i in 0..<numbers.count {
let number = numbers[i]
if number < closestNumbers.0 {
closestNumbers.0 = number
closestNumbers.1 = numbers[i + 1]
} else if number < closestNumbers.1 {
closestNumbers.1 = number
}
}
return closestNumbers
}
```
// XCTAssertTrue failed
func findClosestElements(numbers: [Double]) -> (Double, Double) {
var closest = (numbers[0], numbers[1])
for i in 1..<numbers.count {
let diff = abs(numbers[i] - closest.0)
if diff < abs(closest.1 - closest.0) {
closest = (numbers[i], closest.0)
}
}
return closest
}
```swift
// From a supplied array of numbers (of length at least two) select and return two that are the closest to each
// other and return them in order (smaller number, larger number).
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2)
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) == (2.0, 2.0)
func findClosestElements(numbers: [Double]) -> (Double, Double) {
var closest = (numbers[0], numbers[1])
for i in 1..<numbers.count {
let diff = abs(numbers[i] - closest.0)
if diff < abs(closest.1 - closest.0) {
closest = (numbers[i], closest.0)
}
}
return closest
}
```
// XCTAssertTrue failed
func findClosestElements(numbers: [Double]) -> (Double, Double) {
let sortedNumbers = numbers.sorted()
let firstNumber = sortedNumbers[0]
let lastNumber = sortedNumbers[sortedNumbers.count - 1]
let distance = lastNumber - firstNumber
let midPoint = firstNumber + distance / 2
var closestNumbers = (firstNumber, lastNumber)
for number in sortedNumbers {
if abs(number - midPoint) < abs(lastNumber - firstNumber) {
closestNumbers = (number, lastNumber)
}
}
return closestNumbers
}
```swift
// From a supplied array of numbers (of length at least two) select and return two that are the closest to each
// other and return them in order (smaller number, larger number).
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2)
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) == (2.0, 2.0)
func findClosestElements(numbers: [Double]) -> (Double, Double) {
let sortedNumbers = numbers.sorted()
let firstNumber = sortedNumbers[0]
let lastNumber = sortedNumbers[sortedNumbers.count - 1]
let distance = lastNumber - firstNumber
let midPoint = firstNumber + distance / 2
var closestNumbers = (firstNumber, lastNumber)
for number in sortedNumbers {
if abs(number - midPoint) < abs(lastNumber - firstNumber) {
closestNumbers = (number, lastNumber)
}
}
return closestNumbers
}
```
// XCTAssertTrue failed
func rescaleToUnit(numbers: [Double]) -> [Double] {
let min = numbers.min()!
let max = numbers.max()!
let range = max - min
return numbers.map { $0 - min }
.map { $0 / range }
}
```swift
// Given array of numbers (of at least two elements), apply a linear transform to that array,
// such that the smallest number will become 0 and the largest will become 1
// rescaleToUnit(numbers: [1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]
func rescaleToUnit(numbers: [Double]) -> [Double] {
let min = numbers.min()!
let max = numbers.max()!
let range = max - min
return numbers.map { $0 - min }
.map { $0 / range }
}
```
func rescaleToUnit(numbers: [Double]) -> [Double] {
let min = numbers.min()!
let max = numbers.max()!
let range = max - min
return numbers.map { $0 - min }
.map { $0 / range }
}
```swift
// Given array of numbers (of at least two elements), apply a linear transform to that array,
// such that the smallest number will become 0 and the largest will become 1
// rescaleToUnit(numbers: [1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]
func rescaleToUnit(numbers: [Double]) -> [Double] {
let min = numbers.min()!
let max = numbers.max()!
let range = max - min
return numbers.map { $0 - min }
.map { $0 / range }
}
```
func rescaleToUnit(numbers: [Double]) -> [Double] {
let min = numbers.min()!
let max = numbers.max()!
let range = max - min
return numbers.map { $0 - min }
.map { $0 / range }
}
```swift
// Given array of numbers (of at least two elements), apply a linear transform to that array,
// such that the smallest number will become 0 and the largest will become 1
// rescaleToUnit(numbers: [1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]
func rescaleToUnit(numbers: [Double]) -> [Double] {
let min = numbers.min()!
let max = numbers.max()!
let range = max - min
return numbers.map { $0 - min }
.map { $0 / range }
}
```
func rescaleToUnit(numbers: [Double]) -> [Double] {
var min = numbers[0]
var max = numbers[0]
for number in numbers {
if number < min {
min = number
}
if number > max {
max = number
}
}
var result = [Double]()
for number in numbers {
result.append((number - min) / (max - min))
}
return result
}
```swift
// Given array of numbers (of at least two elements), apply a linear transform to that array,
// such that the smallest number will become 0 and the largest will become 1
// rescaleToUnit(numbers: [1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]
func rescaleToUnit(numbers: [Double]) -> [Double] {
var min = numbers[0]
var max = numbers[0]
for number in numbers {
if number < min {
min = number
}
if number > max {
max = number
}
}
var result = [Double]()
for number in numbers {
result.append((number - min) / (max - min))
}
return result
}
```
func rescaleToUnit(numbers: [Double]) -> [Double] {
var min = numbers[0]
var max = numbers[0]
for number in numbers {
if number < min {
min = number
}
if number > max {
max = number
}
}
var result: [Double] = []
for number in numbers {
result.append((number - min) / (max - min))
}
return result
}
```swift
// Given array of numbers (of at least two elements), apply a linear transform to that array,
// such that the smallest number will become 0 and the largest will become 1
// rescaleToUnit(numbers: [1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]
func rescaleToUnit(numbers: [Double]) -> [Double] {
var min = numbers[0]
var max = numbers[0]
for number in numbers {
if number < min {
min = number
}
if number > max {
max = number
}
}
var result: [Double] = []
for number in numbers {
result.append((number - min) / (max - min))
}
return result
}
```
func rescaleToUnit(numbers: [Double]) -> [Double] {
let min = numbers.min()!
let max = numbers.max()!
let range = max - min
return numbers.map { $0 - min }
.map { $0 / range }
}
```swift
// Given array of numbers (of at least two elements), apply a linear transform to that array,
// such that the smallest number will become 0 and the largest will become 1
// rescaleToUnit(numbers: [1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]
func rescaleToUnit(numbers: [Double]) -> [Double] {
let min = numbers.min()!
let max = numbers.max()!
let range = max - min
return numbers.map { $0 - min }
.map { $0 / range }
}
```
func rescaleToUnit(numbers: [Double]) -> [Double] {
// TODO: implement this function
}
```swift
// Given array of numbers (of at least two elements), apply a linear transform to that array,
// such that the smallest number will become 0 and the largest will become 1
// rescaleToUnit(numbers: [1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]
func rescaleToUnit(numbers: [Double]) -> [Double] {
// TODO: implement this function
}
```
} // missing return in global function expected to return '[Double]'
func rescaleToUnit(numbers: [Double]) -> [Double] {
var min = numbers[0]
var max = numbers[0]
for number in numbers {
if number < min {
min = number
}
if number > max {
max = number
}
}
var result = [Double]()
for number in numbers {
result.append((number - min) / (max - min))
}
return result
}
```swift
// Given array of numbers (of at least two elements), apply a linear transform to that array,
// such that the smallest number will become 0 and the largest will become 1
// rescaleToUnit(numbers: [1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]
func rescaleToUnit(numbers: [Double]) -> [Double] {
var min = numbers[0]
var max = numbers[0]
for number in numbers {
if number < min {
min = number
}
if number > max {
max = number
}
}
var result = [Double]()
for number in numbers {
result.append((number - min) / (max - min))
}
return result
}
```
func rescaleToUnit(numbers: [Double]) -> [Double] {
var min = numbers[0]
var max = numbers[0]
for number in numbers {
if number < min {
min = number
}
if number > max {
max = number
}
}
var result: [Double] = []
for number in numbers {
result.append((number - min) / (max - min))
}
return result
}
```swift
// Given array of numbers (of at least two elements), apply a linear transform to that array,
// such that the smallest number will become 0 and the largest will become 1
// rescaleToUnit(numbers: [1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]
func rescaleToUnit(numbers: [Double]) -> [Double] {
var min = numbers[0]
var max = numbers[0]
for number in numbers {
if number < min {
min = number
}
if number > max {
max = number
}
}
var result: [Double] = []
for number in numbers {
result.append((number - min) / (max - min))
}
return result
}
```
func rescaleToUnit(numbers: [Double]) -> [Double] {
var min = numbers[0]
var max = numbers[0]
for number in numbers {
if number < min {
min = number
}
if number > max {
max = number
}
}
var result = [Double]()
for number in numbers {
result.append((number - min) / (max - min))
}
return result
}
```swift
// Given array of numbers (of at least two elements), apply a linear transform to that array,
// such that the smallest number will become 0 and the largest will become 1
// rescaleToUnit(numbers: [1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]
func rescaleToUnit(numbers: [Double]) -> [Double] {
var min = numbers[0]
var max = numbers[0]
for number in numbers {
if number < min {
min = number
}
if number > max {
max = number
}
}
var result = [Double]()
for number in numbers {
result.append((number - min) / (max - min))
}
return result
}
```
func filterIntegers(values: [AnyHashable]) -> [Int] {
var result: [Int] = []
for value in values {
if let intValue = value as? Int {
result.append(intValue)
}
}
return result
}
```swift
// Filter given array of any swiftthon values only for integers
// filterIntegers(values: ["a", 3.14, 5]) == [5]
// filterIntegers(values: [1, 2, 3, "abc", [:] as [AnyHashable : AnyHashable], [] as [AnyHashable]]) == [1, 2, 3]
func filterIntegers(values: [AnyHashable]) -> [Int] {
var result: [Int] = []
for value in values {
if let intValue = value as? Int {
result.append(intValue)
}
}
return result
}
```
func filterIntegers(values: [AnyHashable]) -> [Int] {
var result: [Int] = []
for value in values {
if let intValue = value as? Int {
result.append(intValue)
}
}
return result
}
```swift
// Filter given array of any swiftthon values only for integers
// filterIntegers(values: ["a", 3.14, 5]) == [5]
// filterIntegers(values: [1, 2, 3, "abc", [:] as [AnyHashable : AnyHashable], [] as [AnyHashable]]) == [1, 2, 3]
func filterIntegers(values: [AnyHashable]) -> [Int] {
var result: [Int] = []
for value in values {
if let intValue = value as? Int {
result.append(intValue)
}
}
return result
}
```
func filterIntegers(values: [AnyHashable]) -> [Int] {
var result: [Int] = []
for value in values {
if let intValue = value as? Int {
result.append(intValue)
}
}
return result
}
```swift
// Filter given array of any swiftthon values only for integers
// filterIntegers(values: ["a", 3.14, 5]) == [5]
// filterIntegers(values: [1, 2, 3, "abc", [:] as [AnyHashable : AnyHashable], [] as [AnyHashable]]) == [1, 2, 3]
func filterIntegers(values: [AnyHashable]) -> [Int] {
var result: [Int] = []
for value in values {
if let intValue = value as? Int {
result.append(intValue)
}
}
return result
}
```
func filterIntegers(values: [AnyHashable]) -> [Int] {
var result: [Int] = []
for value in values {
if let intValue = value as? Int {
result.append(intValue)
}
}
return result
}
```swift
// Filter given array of any swiftthon values only for integers
// filterIntegers(values: ["a", 3.14, 5]) == [5]
// filterIntegers(values: [1, 2, 3, "abc", [:] as [AnyHashable : AnyHashable], [] as [AnyHashable]]) == [1, 2, 3]
func filterIntegers(values: [AnyHashable]) -> [Int] {
var result: [Int] = []
for value in values {
if let intValue = value as? Int {
result.append(intValue)
}
}
return result
}
```
func filterIntegers(values: [AnyHashable]) -> [Int] {
var result: [Int] = []
for value in values {
if let value = value as? Int {
result.append(value)
}
}
return result
}
```swift
// Filter given array of any swiftthon values only for integers
// filterIntegers(values: ["a", 3.14, 5]) == [5]
// filterIntegers(values: [1, 2, 3, "abc", [:] as [AnyHashable : AnyHashable], [] as [AnyHashable]]) == [1, 2, 3]
func filterIntegers(values: [AnyHashable]) -> [Int] {
var result: [Int] = []
for value in values {
if let value = value as? Int {
result.append(value)
}
}
return result
}
```
func filterIntegers(values: [AnyHashable]) -> [Int] {
var result: [Int] = []
for value in values {
if let intValue = value as? Int {
result.append(intValue)
}
}
return result
}
```swift
// Filter given array of any swiftthon values only for integers
// filterIntegers(values: ["a", 3.14, 5]) == [5]
// filterIntegers(values: [1, 2, 3, "abc", [:] as [AnyHashable : AnyHashable], [] as [AnyHashable]]) == [1, 2, 3]
func filterIntegers(values: [AnyHashable]) -> [Int] {
var result: [Int] = []
for value in values {
if let intValue = value as? Int {
result.append(intValue)
}
}
return result
}
```
func filterIntegers(values: [AnyHashable]) -> [Int] {
var result: [Int] = []
for value in values {
if let intValue = value as? Int {
result.append(intValue)
}
}
return result
}
```swift
// Filter given array of any swiftthon values only for integers
// filterIntegers(values: ["a", 3.14, 5]) == [5]
// filterIntegers(values: [1, 2, 3, "abc", [:] as [AnyHashable : AnyHashable], [] as [AnyHashable]]) == [1, 2, 3]
func filterIntegers(values: [AnyHashable]) -> [Int] {
var result: [Int] = []
for value in values {
if let intValue = value as? Int {
result.append(intValue)
}
}
return result
}
```
func filterIntegers(values: [AnyHashable]) -> [Int] {
var result: [Int] = []
for value in values {
if let intValue = value as? Int {
result.append(intValue)
}
}
return result
}
```swift
// Filter given array of any swiftthon values only for integers
// filterIntegers(values: ["a", 3.14, 5]) == [5]
// filterIntegers(values: [1, 2, 3, "abc", [:] as [AnyHashable : AnyHashable], [] as [AnyHashable]]) == [1, 2, 3]
func filterIntegers(values: [AnyHashable]) -> [Int] {
var result: [Int] = []
for value in values {
if let intValue = value as? Int {
result.append(intValue)
}
}
return result
}
```
func filterIntegers(values: [AnyHashable]) -> [Int] {
var result = [Int]()
for value in values {
if let intValue = value as? Int {
result.append(intValue)
}
}
return result
}
```swift
// Filter given array of any swiftthon values only for integers
// filterIntegers(values: ["a", 3.14, 5]) == [5]
// filterIntegers(values: [1, 2, 3, "abc", [:] as [AnyHashable : AnyHashable], [] as [AnyHashable]]) == [1, 2, 3]
func filterIntegers(values: [AnyHashable]) -> [Int] {
var result = [Int]()
for value in values {
if let intValue = value as? Int {
result.append(intValue)
}
}
return result
}
```
func filterIntegers(values: [AnyHashable]) -> [Int] {
var result: [Int] = []
for value in values {
if let intValue = value as? Int {
result.append(intValue)
}
}
return result
}
```swift
// Filter given array of any swiftthon values only for integers
// filterIntegers(values: ["a", 3.14, 5]) == [5]
// filterIntegers(values: [1, 2, 3, "abc", [:] as [AnyHashable : AnyHashable], [] as [AnyHashable]]) == [1, 2, 3]
func filterIntegers(values: [AnyHashable]) -> [Int] {
var result: [Int] = []
for value in values {
if let intValue = value as? Int {
result.append(intValue)
}
}
return result
}
```
func strlen(string: String) -> Int {
return string.characters.count
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
return string.characters.count
}
```
return string.characters.count // 'characters' is unavailable: Please use String directly
func strlen(string: String) -> Int {
return string.characters.count
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
return string.characters.count
}
```
return string.characters.count // 'characters' is unavailable: Please use String directly
func strlen(string: String) -> Int {
return string.characters.count
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
return string.characters.count
}
```
return string.characters.count // 'characters' is unavailable: Please use String directly
func strlen(string: String) -> Int {
return string.characters.count
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
return string.characters.count
}
```
return string.characters.count // 'characters' is unavailable: Please use String directly
func strlen(string: String) -> Int {
return string.count
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
return string.count
}
```
func strlen(string: String) -> Int {
return string.characters.count
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
return string.characters.count
}
```
return string.characters.count // 'characters' is unavailable: Please use String directly
func strlen(string: String) -> Int {
return string.characters.count
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
return string.characters.count
}
```
return string.characters.count // 'characters' is unavailable: Please use String directly
func strlen(string: String) -> Int {
return string.characters.count
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
return string.characters.count
}
```
return string.characters.count // 'characters' is unavailable: Please use String directly
func strlen(string: String) -> Int {
return string.characters.count
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
return string.characters.count
}
```
return string.characters.count // 'characters' is unavailable: Please use String directly
func strlen(string: String) -> Int {
return string.characters.count
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
return string.characters.count
}
```
return string.characters.count // 'characters' is unavailable: Please use String directly
func largestDivisor(n: Int) -> Int {
var divisor = n
while divisor > 1 {
if n % divisor == 0 {
return divisor
}
divisor -= 1
}
return divisor
}
```swift
// For a given number n, find the largest number that divides n evenly, smaller than n
// largestDivisor(n: 15) == 5
func largestDivisor(n: Int) -> Int {
var divisor = n
while divisor > 1 {
if n % divisor == 0 {
return divisor
}
divisor -= 1
}
return divisor
}
```
// XCTAssertTrue failed
func largestDivisor(n: Int) -> Int {
var divisor = n
while divisor > 0 {
if n % divisor == 0 {
return divisor
}
divisor -= 1
}
return 0
}
```swift
// For a given number n, find the largest number that divides n evenly, smaller than n
// largestDivisor(n: 15) == 5
func largestDivisor(n: Int) -> Int {
var divisor = n
while divisor > 0 {
if n % divisor == 0 {
return divisor
}
divisor -= 1
}
return 0
}
```
// XCTAssertTrue failed
func largestDivisor(n: Int) -> Int {
var divisor = n
while divisor > 0 {
if n % divisor == 0 {
return divisor
}
divisor -= 1
}
return 0
}
```swift
// For a given number n, find the largest number that divides n evenly, smaller than n
// largestDivisor(n: 15) == 5
func largestDivisor(n: Int) -> Int {
var divisor = n
while divisor > 0 {
if n % divisor == 0 {
return divisor
}
divisor -= 1
}
return 0
}
```
// XCTAssertTrue failed
func largestDivisor(n: Int) -> Int {
var divisor = n
while divisor > 0 {
if n % divisor == 0 {
return divisor
}
divisor -= 1
}
return 1
}
```swift
// For a given number n, find the largest number that divides n evenly, smaller than n
// largestDivisor(n: 15) == 5
func largestDivisor(n: Int) -> Int {
var divisor = n
while divisor > 0 {
if n % divisor == 0 {
return divisor
}
divisor -= 1
}
return 1
}
```
// XCTAssertTrue failed
func largestDivisor(n: Int) -> Int {
var divisor = n - 1
while divisor > 0 {
if n % divisor == 0 {
return divisor
}
divisor -= 1
}
return 1
}
```swift
// For a given number n, find the largest number that divides n evenly, smaller than n
// largestDivisor(n: 15) == 5
func largestDivisor(n: Int) -> Int {
var divisor = n - 1
while divisor > 0 {
if n % divisor == 0 {
return divisor
}
divisor -= 1
}
return 1
}
```
func largestDivisor(n: Int) -> Int {
var divisor = n - 1
while divisor > 0 {
if n % divisor == 0 {
return divisor
}
divisor -= 1
}
return 1
}
```swift
// For a given number n, find the largest number that divides n evenly, smaller than n
// largestDivisor(n: 15) == 5
func largestDivisor(n: Int) -> Int {
var divisor = n - 1
while divisor > 0 {
if n % divisor == 0 {
return divisor
}
divisor -= 1
}
return 1
}
```
func largestDivisor(n: Int) -> Int {
var divisor = n
while divisor > 0 {
if n % divisor == 0 {
return divisor
}
divisor -= 1
}
return 0
}
```swift
// For a given number n, find the largest number that divides n evenly, smaller than n
// largestDivisor(n: 15) == 5
func largestDivisor(n: Int) -> Int {
var divisor = n
while divisor > 0 {
if n % divisor == 0 {
return divisor
}
divisor -= 1
}
return 0
}
```
// XCTAssertTrue failed
func largestDivisor(n: Int) -> Int {
var divisor = n - 1
while divisor > 0 {
if n % divisor == 0 {
return divisor
}
divisor -= 1
}
return divisor
}
```swift
// For a given number n, find the largest number that divides n evenly, smaller than n
// largestDivisor(n: 15) == 5
func largestDivisor(n: Int) -> Int {
var divisor = n - 1
while divisor > 0 {
if n % divisor == 0 {
return divisor
}
divisor -= 1
}
return divisor
}
```
func largestDivisor(n: Int) -> Int {
var divisor = n
while divisor > 0 {
if n % divisor == 0 {
return divisor
}
divisor -= 1
}
return 1
}
```swift
// For a given number n, find the largest number that divides n evenly, smaller than n
// largestDivisor(n: 15) == 5
func largestDivisor(n: Int) -> Int {
var divisor = n
while divisor > 0 {
if n % divisor == 0 {
return divisor
}
divisor -= 1
}
return 1
}
```
// XCTAssertTrue failed
func largestDivisor(n: Int) -> Int {
var divisor = n - 1
while divisor > 0 {
if n % divisor == 0 {
return divisor
}
divisor -= 1
}
return 1
}
```swift
// For a given number n, find the largest number that divides n evenly, smaller than n
// largestDivisor(n: 15) == 5
func largestDivisor(n: Int) -> Int {
var divisor = n - 1
while divisor > 0 {
if n % divisor == 0 {
return divisor
}
divisor -= 1
}
return 1
}
```
func factorize(n: Int) -> [Int] {
var result: [Int] = []
var number = n
var divisor = 2
while number > 1 {
if number % divisor == 0 {
result.append(divisor)
number /= divisor
} else {
divisor += 1
}
}
return result
}
```swift
// Return array of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be arrayed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// factorize(n: 8) == [2, 2, 2]
// factorize(n: 25) == [5, 5]
// factorize(n: 70) == [2, 5, 7]
func factorize(n: Int) -> [Int] {
var result: [Int] = []
var number = n
var divisor = 2
while number > 1 {
if number % divisor == 0 {
result.append(divisor)
number /= divisor
} else {
divisor += 1
}
}
return result
}
```
func factorize(n: Int) -> [Int] {
var n = n
var factors = [Int]()
var i = 2
while n > 1 {
if n % i == 0 {
factors.append(i)
n /= i
} else {
i += 1
}
}
return factors
}
```swift
// Return array of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be arrayed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// factorize(n: 8) == [2, 2, 2]
// factorize(n: 25) == [5, 5]
// factorize(n: 70) == [2, 5, 7]
func factorize(n: Int) -> [Int] {
var n = n
var factors = [Int]()
var i = 2
while n > 1 {
if n % i == 0 {
factors.append(i)
n /= i
} else {
i += 1
}
}
return factors
}
```
func factorize(n: Int) -> [Int] {
var factors = [Int]()
var num = n
var i = 2
while num > 1 {
if num % i == 0 {
factors.append(i)
num /= i
} else {
i += 1
}
}
return factors
}
```swift
// Return array of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be arrayed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// factorize(n: 8) == [2, 2, 2]
// factorize(n: 25) == [5, 5]
// factorize(n: 70) == [2, 5, 7]
func factorize(n: Int) -> [Int] {
var factors = [Int]()
var num = n
var i = 2
while num > 1 {
if num % i == 0 {
factors.append(i)
num /= i
} else {
i += 1
}
}
return factors
}
```
func factorize(n: Int) -> [Int] {
var result: [Int] = []
var number = n
var divisor = 2
while number > 1 {
if number % divisor == 0 {
result.append(divisor)
number /= divisor
} else {
divisor += 1
}
}
return result
}
```swift
// Return array of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be arrayed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// factorize(n: 8) == [2, 2, 2]
// factorize(n: 25) == [5, 5]
// factorize(n: 70) == [2, 5, 7]
func factorize(n: Int) -> [Int] {
var result: [Int] = []
var number = n
var divisor = 2
while number > 1 {
if number % divisor == 0 {
result.append(divisor)
number /= divisor
} else {
divisor += 1
}
}
return result
}
```
func factorize(n: Int) -> [Int] {
var result = [Int]()
var number = n
var divisor = 2
while number > 1 {
if number % divisor == 0 {
result.append(divisor)
number /= divisor
} else {
divisor += 1
}
}
return result
}
```swift
// Return array of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be arrayed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// factorize(n: 8) == [2, 2, 2]
// factorize(n: 25) == [5, 5]
// factorize(n: 70) == [2, 5, 7]
func factorize(n: Int) -> [Int] {
var result = [Int]()
var number = n
var divisor = 2
while number > 1 {
if number % divisor == 0 {
result.append(divisor)
number /= divisor
} else {
divisor += 1
}
}
return result
}
```
func factorize(n: Int) -> [Int] {
var result = [Int]()
var n = n
var i = 2
while n > 1 {
if n % i == 0 {
result.append(i)
n /= i
} else {
i += 1
}
}
return result
}
```swift
// Return array of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be arrayed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// factorize(n: 8) == [2, 2, 2]
// factorize(n: 25) == [5, 5]
// factorize(n: 70) == [2, 5, 7]
func factorize(n: Int) -> [Int] {
var result = [Int]()
var n = n
var i = 2
while n > 1 {
if n % i == 0 {
result.append(i)
n /= i
} else {
i += 1
}
}
return result
}
```
func factorize(n: Int) -> [Int] {
var result = [Int]()
var number = n
var divisor = 2
while number > 1 {
while number % divisor == 0 {
result.append(divisor)
number /= divisor
}
divisor += 1
}
return result
}
```swift
// Return array of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be arrayed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// factorize(n: 8) == [2, 2, 2]
// factorize(n: 25) == [5, 5]
// factorize(n: 70) == [2, 5, 7]
func factorize(n: Int) -> [Int] {
var result = [Int]()
var number = n
var divisor = 2
while number > 1 {
while number % divisor == 0 {
result.append(divisor)
number /= divisor
}
divisor += 1
}
return result
}
```
func factorize(n: Int) -> [Int] {
var n = n
var factors = [Int]()
var i = 2
while n > 1 {
while n % i == 0 {
factors.append(i)
n /= i
}
i += 1
}
return factors
}
```swift
// Return array of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be arrayed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// factorize(n: 8) == [2, 2, 2]
// factorize(n: 25) == [5, 5]
// factorize(n: 70) == [2, 5, 7]
func factorize(n: Int) -> [Int] {
var n = n
var factors = [Int]()
var i = 2
while n > 1 {
while n % i == 0 {
factors.append(i)
n /= i
}
i += 1
}
return factors
}
```
func factorize(n: Int) -> [Int] {
var result = [Int]()
var number = n
for i in 2...number {
while number % i == 0 {
result.append(i)
number /= i
}
}
return result
}
```swift
// Return array of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be arrayed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// factorize(n: 8) == [2, 2, 2]
// factorize(n: 25) == [5, 5]
// factorize(n: 70) == [2, 5, 7]
func factorize(n: Int) -> [Int] {
var result = [Int]()
var number = n
for i in 2...number {
while number % i == 0 {
result.append(i)
number /= i
}
}
return result
}
```
func factorize(n: Int) -> [Int] {
var result = [Int]()
var number = n
for i in 2...number {
while number % i == 0 {
result.append(i)
number /= i
}
}
return result
}
```swift
// Return array of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be arrayed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// factorize(n: 8) == [2, 2, 2]
// factorize(n: 25) == [5, 5]
// factorize(n: 70) == [2, 5, 7]
func factorize(n: Int) -> [Int] {
var result = [Int]()
var number = n
for i in 2...number {
while number % i == 0 {
result.append(i)
number /= i
}
}
return result
}
```
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
for number in numbers {
if!result.contains(number) {
result.append(number)
}
}
return result
}
```swift
// From an array of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// removeDuplicates(numbers: [1, 2, 3, 2, 4]) == [1, 3, 4]
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
for number in numbers {
if!result.contains(number) {
result.append(number)
}
}
return result
}
```
if!result.contains(number) { // expected expression, var, or let in 'if' condition
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
for number in numbers {
if!result.contains(number) {
result.append(number)
}
}
return result
}
```swift
// From an array of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// removeDuplicates(numbers: [1, 2, 3, 2, 4]) == [1, 3, 4]
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
for number in numbers {
if!result.contains(number) {
result.append(number)
}
}
return result
}
```
if!result.contains(number) { // expected expression, var, or let in 'if' condition
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
for number in numbers {
if!result.contains(number) {
result.append(number)
}
}
return result
}
```swift
// From an array of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// removeDuplicates(numbers: [1, 2, 3, 2, 4]) == [1, 3, 4]
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
for number in numbers {
if!result.contains(number) {
result.append(number)
}
}
return result
}
```
if!result.contains(number) { // expected expression, var, or let in 'if' condition
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
for number in numbers {
if!result.contains(number) {
result.append(number)
}
}
return result
}
```swift
// From an array of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// removeDuplicates(numbers: [1, 2, 3, 2, 4]) == [1, 3, 4]
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
for number in numbers {
if!result.contains(number) {
result.append(number)
}
}
return result
}
```
if!result.contains(number) { // expected expression, var, or let in 'if' condition
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
for number in numbers {
if!result.contains(number) {
result.append(number)
}
}
return result
}
```swift
// From an array of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// removeDuplicates(numbers: [1, 2, 3, 2, 4]) == [1, 3, 4]
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
for number in numbers {
if!result.contains(number) {
result.append(number)
}
}
return result
}
```
if!result.contains(number) { // expected expression, var, or let in 'if' condition
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
var seen = Set<Int>()
for number in numbers {
if!seen.contains(number) {
result.append(number)
seen.insert(number)
}
}
return result
}
```swift
// From an array of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// removeDuplicates(numbers: [1, 2, 3, 2, 4]) == [1, 3, 4]
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
var seen = Set<Int>()
for number in numbers {
if!seen.contains(number) {
result.append(number)
seen.insert(number)
}
}
return result
}
```
if!seen.contains(number) { // expected expression, var, or let in 'if' condition
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
var set = Set<Int>()
for number in numbers {
if!set.contains(number) {
result.append(number)
set.insert(number)
}
}
return result
}
```swift
// From an array of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// removeDuplicates(numbers: [1, 2, 3, 2, 4]) == [1, 3, 4]
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
var set = Set<Int>()
for number in numbers {
if!set.contains(number) {
result.append(number)
set.insert(number)
}
}
return result
}
```
if!set.contains(number) { // expected expression, var, or let in 'if' condition
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
var seen = Set<Int>()
for number in numbers {
if!seen.contains(number) {
result.append(number)
seen.insert(number)
}
}
return result
}
```swift
// From an array of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// removeDuplicates(numbers: [1, 2, 3, 2, 4]) == [1, 3, 4]
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
var seen = Set<Int>()
for number in numbers {
if!seen.contains(number) {
result.append(number)
seen.insert(number)
}
}
return result
}
```
if!seen.contains(number) { // expected expression, var, or let in 'if' condition
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
for number in numbers {
if!result.contains(number) {
result.append(number)
}
}
return result
}
```swift
// From an array of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// removeDuplicates(numbers: [1, 2, 3, 2, 4]) == [1, 3, 4]
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
for number in numbers {
if!result.contains(number) {
result.append(number)
}
}
return result
}
```
if!result.contains(number) { // expected expression, var, or let in 'if' condition
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
var seen = Set<Int>()
for number in numbers {
if seen.contains(number) {
continue
}
result.append(number)
seen.insert(number)
}
return result
}
```swift
// From an array of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// removeDuplicates(numbers: [1, 2, 3, 2, 4]) == [1, 3, 4]
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
var seen = Set<Int>()
for number in numbers {
if seen.contains(number) {
continue
}
result.append(number)
seen.insert(number)
}
return result
}
```
// XCTAssertTrue failed
func flipCase(string: String) -> String {
var result = ""
for character in string {
if character.isLowercase {
result.append(character.uppercased())
} else {
result.append(character.lowercased())
}
}
return result
}
```swift
// For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// flipCase(string: "Hello") == "hELLO"
func flipCase(string: String) -> String {
var result = ""
for character in string {
if character.isLowercase {
result.append(character.uppercased())
} else {
result.append(character.lowercased())
}
}
return result
}
```
func flipCase(string: String) -> String {
var result = ""
for character in string {
if character.isUppercase {
result.append(character.lowercased())
} else {
result.append(character.uppercased())
}
}
return result
}
```swift
// For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// flipCase(string: "Hello") == "hELLO"
func flipCase(string: String) -> String {
var result = ""
for character in string {
if character.isUppercase {
result.append(character.lowercased())
} else {
result.append(character.uppercased())
}
}
return result
}
```
func flipCase(string: String) -> String {
var result = ""
for char in string {
if char.isUppercase {
result += char.lowercased()
} else {
result += char.uppercased()
}
}
return result
}
```swift
// For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// flipCase(string: "Hello") == "hELLO"
func flipCase(string: String) -> String {
var result = ""
for char in string {
if char.isUppercase {
result += char.lowercased()
} else {
result += char.uppercased()
}
}
return result
}
```
func flipCase(string: String) -> String {
var result = ""
for char in string {
if char.isUppercase {
result += char.lowercased()
} else {
result += char.uppercased()
}
}
return result
}
```swift
// For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// flipCase(string: "Hello") == "hELLO"
func flipCase(string: String) -> String {
var result = ""
for char in string {
if char.isUppercase {
result += char.lowercased()
} else {
result += char.uppercased()
}
}
return result
}
```
func flipCase(string: String) -> String {
var result = ""
for char in string {
if char.isUppercase {
result.append(char.lowercased())
} else {
result.append(char.uppercased())
}
}
return result
}
```swift
// For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// flipCase(string: "Hello") == "hELLO"
func flipCase(string: String) -> String {
var result = ""
for char in string {
if char.isUppercase {
result.append(char.lowercased())
} else {
result.append(char.uppercased())
}
}
return result
}
```
func flipCase(string: String) -> String {
var result = ""
for char in string {
if char.isLowercase {
result.append(char.uppercased())
} else {
result.append(char.lowercased())
}
}
return result
}
```swift
// For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// flipCase(string: "Hello") == "hELLO"
func flipCase(string: String) -> String {
var result = ""
for char in string {
if char.isLowercase {
result.append(char.uppercased())
} else {
result.append(char.lowercased())
}
}
return result
}
```
func flipCase(string: String) -> String {
var result = ""
for char in string {
if char.isUppercase {
result += char.lowercased()
} else {
result += char.uppercased()
}
}
return result
}
```swift
// For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// flipCase(string: "Hello") == "hELLO"
func flipCase(string: String) -> String {
var result = ""
for char in string {
if char.isUppercase {
result += char.lowercased()
} else {
result += char.uppercased()
}
}
return result
}
```
func flipCase(string: String) -> String {
var result = ""
for char in string {
if char.isLowercase {
result.append(char.uppercased())
} else {
result.append(char.lowercased())
}
}
return result
}
```swift
// For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// flipCase(string: "Hello") == "hELLO"
func flipCase(string: String) -> String {
var result = ""
for char in string {
if char.isLowercase {
result.append(char.uppercased())
} else {
result.append(char.lowercased())
}
}
return result
}
```
func flipCase(string: String) -> String {
var result = ""
for char in string {
if char.isLowercase {
result += char.uppercased()
} else {
result += char.lowercased()
}
}
return result
}
```swift
// For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// flipCase(string: "Hello") == "hELLO"
func flipCase(string: String) -> String {
var result = ""
for char in string {
if char.isLowercase {
result += char.uppercased()
} else {
result += char.lowercased()
}
}
return result
}
```
func flipCase(string: String) -> String {
var result = ""
for char in string {
if char.isUppercase {
result.append(char.lowercased())
} else {
result.append(char.uppercased())
}
}
return result
}
```swift
// For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// flipCase(string: "Hello") == "hELLO"
func flipCase(string: String) -> String {
var result = ""
for char in string {
if char.isUppercase {
result.append(char.lowercased())
} else {
result.append(char.uppercased())
}
}
return result
}
```
func concatenate(strings: [String]) -> String {
var result = ""
for string in strings {
result += string
}
return result
}
```swift
// Concatenate array of strings into a single string
// concatenate(strings: [] as [String]) == ""
// concatenate(strings: ["a", "b", "c"]) == "abc"
func concatenate(strings: [String]) -> String {
var result = ""
for string in strings {
result += string
}
return result
}
```
func concatenate(strings: [String]) -> String {
var result = ""
for string in strings {
result += string
}
return result
}
```swift
// Concatenate array of strings into a single string
// concatenate(strings: [] as [String]) == ""
// concatenate(strings: ["a", "b", "c"]) == "abc"
func concatenate(strings: [String]) -> String {
var result = ""
for string in strings {
result += string
}
return result
}
```
func concatenate(strings: [String]) -> String {
var result = ""
for string in strings {
result += string
}
return result
}
```swift
// Concatenate array of strings into a single string
// concatenate(strings: [] as [String]) == ""
// concatenate(strings: ["a", "b", "c"]) == "abc"
func concatenate(strings: [String]) -> String {
var result = ""
for string in strings {
result += string
}
return result
}
```
func concatenate(strings: [String]) -> String {
var result = ""
for string in strings {
result += string
}
return result
}
```swift
// Concatenate array of strings into a single string
// concatenate(strings: [] as [String]) == ""
// concatenate(strings: ["a", "b", "c"]) == "abc"
func concatenate(strings: [String]) -> String {
var result = ""
for string in strings {
result += string
}
return result
}
```
func concatenate(strings: [String]) -> String {
var result = ""
for string in strings {
result += string
}
return result
}
```swift
// Concatenate array of strings into a single string
// concatenate(strings: [] as [String]) == ""
// concatenate(strings: ["a", "b", "c"]) == "abc"
func concatenate(strings: [String]) -> String {
var result = ""
for string in strings {
result += string
}
return result
}
```
func concatenate(strings: [String]) -> String {
var result = ""
for string in strings {
result += string
}
return result
}
```swift
// Concatenate array of strings into a single string
// concatenate(strings: [] as [String]) == ""
// concatenate(strings: ["a", "b", "c"]) == "abc"
func concatenate(strings: [String]) -> String {
var result = ""
for string in strings {
result += string
}
return result
}
```
func concatenate(strings: [String]) -> String {
var result = ""
for string in strings {
result += string
}
return result
}
```swift
// Concatenate array of strings into a single string
// concatenate(strings: [] as [String]) == ""
// concatenate(strings: ["a", "b", "c"]) == "abc"
func concatenate(strings: [String]) -> String {
var result = ""
for string in strings {
result += string
}
return result
}
```
func concatenate(strings: [String]) -> String {
var result = ""
for string in strings {
result += string
}
return result
}
```swift
// Concatenate array of strings into a single string
// concatenate(strings: [] as [String]) == ""
// concatenate(strings: ["a", "b", "c"]) == "abc"
func concatenate(strings: [String]) -> String {
var result = ""
for string in strings {
result += string
}
return result
}
```
func concatenate(strings: [String]) -> String {
var result = ""
for string in strings {
result += string
}
return result
}
```swift
// Concatenate array of strings into a single string
// concatenate(strings: [] as [String]) == ""
// concatenate(strings: ["a", "b", "c"]) == "abc"
func concatenate(strings: [String]) -> String {
var result = ""
for string in strings {
result += string
}
return result
}
```
func concatenate(strings: [String]) -> String {
var result = ""
for string in strings {
result += string
}
return result
}
```swift
// Concatenate array of strings into a single string
// concatenate(strings: [] as [String]) == ""
// concatenate(strings: ["a", "b", "c"]) == "abc"
func concatenate(strings: [String]) -> String {
var result = ""
for string in strings {
result += string
}
return result
}
```
func filterByPrefix(strings: [String], prefix: String) -> [String] {
var filteredStrings = [String]()
for string in strings {
if string.hasPrefix(prefix) {
filteredStrings.append(string)
}
}
return filteredStrings
}
```swift
// Filter an input array of strings only for ones that start with a given prefix.
// filterByPrefix(strings: [] as [String], prefix: "a") == [] as [String]
// filterByPrefix(strings: ["abc", "bcd", "cde", "array"], prefix: "a") == ["abc", "array"]
func filterByPrefix(strings: [String], prefix: String) -> [String] {
var filteredStrings = [String]()
for string in strings {
if string.hasPrefix(prefix) {
filteredStrings.append(string)
}
}
return filteredStrings
}
```
func filterByPrefix(strings: [String], prefix: String) -> [String] {
var result: [String] = []
for string in strings {
if string.hasPrefix(prefix) {
result.append(string)
}
}
return result
}
```swift
// Filter an input array of strings only for ones that start with a given prefix.
// filterByPrefix(strings: [] as [String], prefix: "a") == [] as [String]
// filterByPrefix(strings: ["abc", "bcd", "cde", "array"], prefix: "a") == ["abc", "array"]
func filterByPrefix(strings: [String], prefix: String) -> [String] {
var result: [String] = []
for string in strings {
if string.hasPrefix(prefix) {
result.append(string)
}
}
return result
}
```
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```swift
// Filter an input array of strings only for ones that start with a given prefix.
// filterByPrefix(strings: [] as [String], prefix: "a") == [] as [String]
// filterByPrefix(strings: ["abc", "bcd", "cde", "array"], prefix: "a") == ["abc", "array"]
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
// Filter an input array of strings only for ones that start with a given prefix.
// filterByPrefix(strings: [] as [String], prefix: "a") == [] as [String]
// filterByPrefix(strings: ["abc", "bcd", "cde", "array"], prefix: "a") == ["abc", "array"]
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```
func filterByPrefix(strings: [String], prefix: String) -> [String] {
var filteredStrings = [String]()
for string in strings {
if string.hasPrefix(prefix) {
filteredStrings.append(string)
}
}
return filteredStrings
}
```swift
// Filter an input array of strings only for ones that start with a given prefix.
// filterByPrefix(strings: [] as [String], prefix: "a") == [] as [String]
// filterByPrefix(strings: ["abc", "bcd", "cde", "array"], prefix: "a") == ["abc", "array"]
func filterByPrefix(strings: [String], prefix: String) -> [String] {
var filteredStrings = [String]()
for string in strings {
if string.hasPrefix(prefix) {
filteredStrings.append(string)
}
}
return filteredStrings
}
```
func filterByPrefix(strings: [String], prefix: String) -> [String] {
var result: [String] = []
for string in strings {
if string.hasPrefix(prefix) {
result.append(string)
}
}
return result
}
```swift
// Filter an input array of strings only for ones that start with a given prefix.
// filterByPrefix(strings: [] as [String], prefix: "a") == [] as [String]
// filterByPrefix(strings: ["abc", "bcd", "cde", "array"], prefix: "a") == ["abc", "array"]
func filterByPrefix(strings: [String], prefix: String) -> [String] {
var result: [String] = []
for string in strings {
if string.hasPrefix(prefix) {
result.append(string)
}
}
return result
}
```
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```swift
// Filter an input array of strings only for ones that start with a given prefix.
// filterByPrefix(strings: [] as [String], prefix: "a") == [] as [String]
// filterByPrefix(strings: ["abc", "bcd", "cde", "array"], prefix: "a") == ["abc", "array"]
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { (string) -> Bool in
return string.hasPrefix(prefix)
}
}
```swift
// Filter an input array of strings only for ones that start with a given prefix.
// filterByPrefix(strings: [] as [String], prefix: "a") == [] as [String]
// filterByPrefix(strings: ["abc", "bcd", "cde", "array"], prefix: "a") == ["abc", "array"]
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { (string) -> Bool in
return string.hasPrefix(prefix)
}
}
```
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { (string) -> Bool in
return string.hasPrefix(prefix)
}
}
```swift
// Filter an input array of strings only for ones that start with a given prefix.
// filterByPrefix(strings: [] as [String], prefix: "a") == [] as [String]
// filterByPrefix(strings: ["abc", "bcd", "cde", "array"], prefix: "a") == ["abc", "array"]
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { (string) -> Bool in
return string.hasPrefix(prefix)
}
}
```
func filterByPrefix(strings: [String], prefix: String) -> [String] {
var filteredStrings = [String]()
for string in strings {
if string.hasPrefix(prefix) {
filteredStrings.append(string)
}
}
return filteredStrings
}
```swift
// Filter an input array of strings only for ones that start with a given prefix.
// filterByPrefix(strings: [] as [String], prefix: "a") == [] as [String]
// filterByPrefix(strings: ["abc", "bcd", "cde", "array"], prefix: "a") == ["abc", "array"]
func filterByPrefix(strings: [String], prefix: String) -> [String] {
var filteredStrings = [String]()
for string in strings {
if string.hasPrefix(prefix) {
filteredStrings.append(string)
}
}
return filteredStrings
}
```
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { (string) -> Bool in
return string.hasPrefix(prefix)
}
}
```swift
// Filter an input array of strings only for ones that start with a given prefix.
// filterByPrefix(strings: [] as [String], prefix: "a") == [] as [String]
// filterByPrefix(strings: ["abc", "bcd", "cde", "array"], prefix: "a") == ["abc", "array"]
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { (string) -> Bool in
return string.hasPrefix(prefix)
}
}
```
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```swift
// Return only positive numbers in the array.
// getPositive(l: [-1, 2, -4, 5, 6]) == [2, 5, 6]
// getPositive(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 9, 123, 1]
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```swift
// Return only positive numbers in the array.
// getPositive(l: [-1, 2, -4, 5, 6]) == [2, 5, 6]
// getPositive(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 9, 123, 1]
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```swift
// Return only positive numbers in the array.
// getPositive(l: [-1, 2, -4, 5, 6]) == [2, 5, 6]
// getPositive(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 9, 123, 1]
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```swift
// Return only positive numbers in the array.
// getPositive(l: [-1, 2, -4, 5, 6]) == [2, 5, 6]
// getPositive(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 9, 123, 1]
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```swift
// Return only positive numbers in the array.
// getPositive(l: [-1, 2, -4, 5, 6]) == [2, 5, 6]
// getPositive(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 9, 123, 1]
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```swift
// Return only positive numbers in the array.
// getPositive(l: [-1, 2, -4, 5, 6]) == [2, 5, 6]
// getPositive(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 9, 123, 1]
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```swift
// Return only positive numbers in the array.
// getPositive(l: [-1, 2, -4, 5, 6]) == [2, 5, 6]
// getPositive(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 9, 123, 1]
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```swift
// Return only positive numbers in the array.
// getPositive(l: [-1, 2, -4, 5, 6]) == [2, 5, 6]
// getPositive(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 9, 123, 1]
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```swift
// Return only positive numbers in the array.
// getPositive(l: [-1, 2, -4, 5, 6]) == [2, 5, 6]
// getPositive(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 9, 123, 1]
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```swift
// Return only positive numbers in the array.
// getPositive(l: [-1, 2, -4, 5, 6]) == [2, 5, 6]
// getPositive(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 9, 123, 1]
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```
func isPrime(n: Int) -> Bool {
guard n > 1 else { return false }
guard n!= 2 else { return true }
guard n % 2!= 0 else { return false }
for i in stride(from: 3, through: Int(sqrt(Double(n))), by: 2) {
if n % i == 0 { return false }
}
return true
}
```swift
// Return true if a given number is prime, and false otherwise.
// isPrime(n: 6) == false
// isPrime(n: 101) == true
// isPrime(n: 11) == true
// isPrime(n: 13441) == true
// isPrime(n: 61) == true
// isPrime(n: 4) == false
// isPrime(n: 1) == false
func isPrime(n: Int) -> Bool {
guard n > 1 else { return false }
guard n!= 2 else { return true }
guard n % 2!= 0 else { return false }
for i in stride(from: 3, through: Int(sqrt(Double(n))), by: 2) {
if n % i == 0 { return false }
}
return true
}
```
guard n!= 2 else { return true } // use of '=' in a boolean context, did you mean '=='?
guard n!= 2 else { return true } // cannot force unwrap value of non-optional type 'Int'
guard n!= 2 else { return true } // '=' must have consistent whitespace on both sides
guard n % 2!= 0 else { return false } // '=' must have consistent whitespace on both sides
guard n % 2!= 0 else { return false } // cannot force unwrap value of non-optional type 'Int'
guard n % 2!= 0 else { return false } // use of '=' in a boolean context, did you mean '=='?
guard n % 2!= 0 else { return false } // expression is not assignable: binary operator returns immutable value
func isPrime(n: Int) -> Bool {
// TODO: implement this function
}
```swift
// Return true if a given number is prime, and false otherwise.
// isPrime(n: 6) == false
// isPrime(n: 101) == true
// isPrime(n: 11) == true
// isPrime(n: 13441) == true
// isPrime(n: 61) == true
// isPrime(n: 4) == false
// isPrime(n: 1) == false
func isPrime(n: Int) -> Bool {
// TODO: implement this function
}
```
} // missing return in global function expected to return 'Bool'
func isPrime(n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```swift
// Return true if a given number is prime, and false otherwise.
// isPrime(n: 6) == false
// isPrime(n: 101) == true
// isPrime(n: 11) == true
// isPrime(n: 13441) == true
// isPrime(n: 61) == true
// isPrime(n: 4) == false
// isPrime(n: 1) == false
func isPrime(n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```
func isPrime(n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2...Int(sqrt(Double(n))) {
if n % i == 0 {
return false
}
}
return true
}
```swift
// Return true if a given number is prime, and false otherwise.
// isPrime(n: 6) == false
// isPrime(n: 101) == true
// isPrime(n: 11) == true
// isPrime(n: 13441) == true
// isPrime(n: 61) == true
// isPrime(n: 4) == false
// isPrime(n: 1) == false
func isPrime(n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2...Int(sqrt(Double(n))) {
if n % i == 0 {
return false
}
}
return true
}
```
```swift
// Return true if a given number is prime, and false otherwise.
// isPrime(n: 6) == false
// isPrime(n: 101) == true
// isPrime(n: 11) == true
// isPrime(n: 13441) == true
// isPrime(n: 61) == true
// isPrime(n: 4) == false
// isPrime(n: 1) == false
func isPrime(n: Int) -> Bool {
// 1 is not a prime number
if n == 1 {
return false
}
// 2 is a prime number
if n == 2 {
return true
}
// 3 is a prime number
if n == 3 {
return true
}
// 4 is not a prime number
if n == 4 {
return false
}
// 5 is a prime number
if n == 5 {
return true
}
// 6 is not a prime number
if n == 6 {
return false
}
// 7 is a prime number
if n == 7 {
return true
}
// 8 is not a prime number
if n == 8 {
return false
}
// 9 is not a prime number
if n == 9 {
return false
}
// 10 is not a prime number
if n == 10 {
return false
}
// 11 is a prime number
if n == 11 {
return true
}
// 12 is not a prime number
if n == 12 {
return false
}
// 13 is a prime number
if n == 13 {
return true
}
// 14 is not a prime number
if n == 14 {
return false
}
// 15 is not a prime number
if n == 15 {
return false
}
// 16 is not a prime number
if n == 16 {
return false
}
// 17 is a prime number
if n == 17 {
return true
}
// 18 is not a prime number
if n == 18 {
return false
}
// 19 is a prime number
if n == 19 {
return true
}
// 20 is not a prime number
if n == 20 {
return false
}
// 21 is not a prime number
if n == 21 {
return false
}
// 22 is not a prime number
if n == 22 {
return false
}
// 23 is a prime number
if n == 23 {
return true
}
// 24 is not a prime number
if n == 24 {
return false
}
// 25 is not a prime number
if n == 25 {
return false
}
// 26 is not a prime number
if n == 26 {
return false
}
// 27 is not a prime number
if n == 27 {
return false
}
// 28 is not a prime number
if n == 28 {
return false
}
// 29 is a prime number
if n == 29 {
return true
}
// 30 is not a prime number
if n == 30 {
return false
}
// 31 is a prime number
if n == 31 {
return true
}
// 32 is not a prime number
if n == 32 {
return false
}
// 33 is not a prime number
if n == 33 {
return false
}
// 34 is not a prime number
if n == 34 {
return false
}
// 35 is not a prime number
if n == 35 {
return false
}
// 36 is not a prime number
if n == 36 {
return false
}
// 37 is a prime number
if n == 37 {
return true
}
// 38 is not a prime number
if n == 38 {
return false
}
// 39 is not a prime number
if n == 39 {
return false
}
// 40 is not a prime number
if n == 40 {
return false
}
// 41 is a prime number
if n == 41 {
return true
}
// 42 is not a prime number
if n == 42 {
return false
}
// 43 is a prime number
if n == 43 {
return true
}
// 44 is not a prime number
if n == 44 {
return false
}
// 45 is not a prime number
if n == 45 {
return false
}
// 46 is not a prime number
if n == 46 {
return false
XCTAssertTrue(isPrime(n: 6) == false) // cannot find 'isPrime' in scope
XCTAssertTrue(isPrime(n: 101) == true) // cannot find 'isPrime' in scope
XCTAssertTrue(isPrime(n: 11) == true) // cannot find 'isPrime' in scope
XCTAssertTrue(isPrime(n: 13441) == true) // cannot find 'isPrime' in scope
XCTAssertTrue(isPrime(n: 61) == true) // cannot find 'isPrime' in scope
XCTAssertTrue(isPrime(n: 4) == false) // cannot find 'isPrime' in scope
XCTAssertTrue(isPrime(n: 1) == false) // cannot find 'isPrime' in scope
XCTAssertTrue(isPrime(n: 5) == true) // cannot find 'isPrime' in scope
XCTAssertTrue(isPrime(n: 11) == true) // cannot find 'isPrime' in scope
XCTAssertTrue(isPrime(n: 17) == true) // cannot find 'isPrime' in scope
XCTAssertTrue(isPrime(n: 85) == false) // cannot find 'isPrime' in scope
XCTAssertTrue(isPrime(n: 77) == false) // cannot find 'isPrime' in scope
XCTAssertTrue(isPrime(n: 255379) == false) // cannot find 'isPrime' in scope
func isPrime(n: Int) -> Bool {
if n <= 1 { return false }
if n <= 3 { return true }
if n % 2 == 0 { return false }
if n % 3 == 0 { return false }
var i = 5
while i * i <= n {
if n % i == 0 { return false }
if n % (i + 2) == 0 { return false }
i += 6
}
return true
}
```swift
// Return true if a given number is prime, and false otherwise.
// isPrime(n: 6) == false
// isPrime(n: 101) == true
// isPrime(n: 11) == true
// isPrime(n: 13441) == true
// isPrime(n: 61) == true
// isPrime(n: 4) == false
// isPrime(n: 1) == false
func isPrime(n: Int) -> Bool {
if n <= 1 { return false }
if n <= 3 { return true }
if n % 2 == 0 { return false }
if n % 3 == 0 { return false }
var i = 5
while i * i <= n {
if n % i == 0 { return false }
if n % (i + 2) == 0 { return false }
i += 6
}
return true
}
```
func isPrime(n: Int) -> Bool {
guard n > 1 else { return false }
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```swift
// Return true if a given number is prime, and false otherwise.
// isPrime(n: 6) == false
// isPrime(n: 101) == true
// isPrime(n: 11) == true
// isPrime(n: 13441) == true
// isPrime(n: 61) == true
// isPrime(n: 4) == false
// isPrime(n: 1) == false
func isPrime(n: Int) -> Bool {
guard n > 1 else { return false }
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```
func isPrime(n: Int) -> Bool {
if n <= 1 { return false }
if n <= 3 { return true }
if n % 2 == 0 || n % 3 == 0 { return false }
var i = 5
while i * i <= n {
if n % i == 0 || n % (i + 2) == 0 {
return false
}
i += 6
}
return true
}
```swift
// Return true if a given number is prime, and false otherwise.
// isPrime(n: 6) == false
// isPrime(n: 101) == true
// isPrime(n: 11) == true
// isPrime(n: 13441) == true
// isPrime(n: 61) == true
// isPrime(n: 4) == false
// isPrime(n: 1) == false
func isPrime(n: Int) -> Bool {
if n <= 1 { return false }
if n <= 3 { return true }
if n % 2 == 0 || n % 3 == 0 { return false }
var i = 5
while i * i <= n {
if n % i == 0 || n % (i + 2) == 0 {
return false
}
i += 6
}
return true
}
```
func isPrime(n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2...Int(sqrt(Double(n))) {
if n % i == 0 {
return false
}
}
return true
}
```swift
// Return true if a given number is prime, and false otherwise.
// isPrime(n: 6) == false
// isPrime(n: 101) == true
// isPrime(n: 11) == true
// isPrime(n: 13441) == true
// isPrime(n: 61) == true
// isPrime(n: 4) == false
// isPrime(n: 1) == false
func isPrime(n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2...Int(sqrt(Double(n))) {
if n % i == 0 {
return false
}
}
return true
}
```
func isPrime(n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```swift
// Return true if a given number is prime, and false otherwise.
// isPrime(n: 6) == false
// isPrime(n: 101) == true
// isPrime(n: 11) == true
// isPrime(n: 13441) == true
// isPrime(n: 61) == true
// isPrime(n: 4) == false
// isPrime(n: 1) == false
func isPrime(n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```
func sortThird(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<l.count {
if i % 3 == 0 {
lPrime[i] = l.sorted()[i]
}
}
return lPrime
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// sortThird(l: [1, 2, 3]) == [1, 2, 3]
// sortThird(l: [5, 6, 3, 4, 8, 9, 2]) == [2, 6, 3, 4, 8, 9, 5]
func sortThird(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<l.count {
if i % 3 == 0 {
lPrime[i] = l.sorted()[i]
}
}
return lPrime
}
```
// XCTAssertTrue failed
func sortThird(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<l.count {
if i % 3 == 0 {
lPrime[i] = lPrime.sorted()[i]
}
}
return lPrime
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// sortThird(l: [1, 2, 3]) == [1, 2, 3]
// sortThird(l: [5, 6, 3, 4, 8, 9, 2]) == [2, 6, 3, 4, 8, 9, 5]
func sortThird(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<l.count {
if i % 3 == 0 {
lPrime[i] = lPrime.sorted()[i]
}
}
return lPrime
}
```
// XCTAssertTrue failed
func sortThird(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 3 == 0 {
l[i] = l[i].sorted()
}
}
return l
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// sortThird(l: [1, 2, 3]) == [1, 2, 3]
// sortThird(l: [5, 6, 3, 4, 8, 9, 2]) == [2, 6, 3, 4, 8, 9, 5]
func sortThird(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 3 == 0 {
l[i] = l[i].sorted()
}
}
return l
}
```
l[i] = l[i].sorted() // value of type 'Int' has no member 'sorted'
func sortThird(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<l.count {
if i % 3 == 0 {
lPrime[i] = lPrime.sorted()[i]
}
}
return lPrime
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// sortThird(l: [1, 2, 3]) == [1, 2, 3]
// sortThird(l: [5, 6, 3, 4, 8, 9, 2]) == [2, 6, 3, 4, 8, 9, 5]
func sortThird(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<l.count {
if i % 3 == 0 {
lPrime[i] = lPrime.sorted()[i]
}
}
return lPrime
}
```
// XCTAssertTrue failed
func sortThird(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 3 == 0 {
l.sort()
}
}
return l
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// sortThird(l: [1, 2, 3]) == [1, 2, 3]
// sortThird(l: [5, 6, 3, 4, 8, 9, 2]) == [2, 6, 3, 4, 8, 9, 5]
func sortThird(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 3 == 0 {
l.sort()
}
}
return l
}
```
// XCTAssertTrue failed
func sortThird(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<l.count {
if i % 3 == 0 {
lPrime[i] = lPrime[i].sorted()
}
}
return lPrime
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// sortThird(l: [1, 2, 3]) == [1, 2, 3]
// sortThird(l: [5, 6, 3, 4, 8, 9, 2]) == [2, 6, 3, 4, 8, 9, 5]
func sortThird(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<l.count {
if i % 3 == 0 {
lPrime[i] = lPrime[i].sorted()
}
}
return lPrime
}
```
lPrime[i] = lPrime[i].sorted() // value of type 'Int' has no member 'sorted'
func sortThird(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<l.count {
if i % 3 == 0 {
lPrime[i] = lPrime.sorted()[i]
}
}
return lPrime
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// sortThird(l: [1, 2, 3]) == [1, 2, 3]
// sortThird(l: [5, 6, 3, 4, 8, 9, 2]) == [2, 6, 3, 4, 8, 9, 5]
func sortThird(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<l.count {
if i % 3 == 0 {
lPrime[i] = lPrime.sorted()[i]
}
}
return lPrime
}
```
// XCTAssertTrue failed
func sortThird(l: [Int]) -> [Int] {
var l = l
var lPrime = [Int]()
for i in 0..<l.count {
if i % 3 == 0 {
lPrime.append(l[i])
} else {
lPrime.append(l[i])
lPrime.sort()
}
}
return lPrime
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// sortThird(l: [1, 2, 3]) == [1, 2, 3]
// sortThird(l: [5, 6, 3, 4, 8, 9, 2]) == [2, 6, 3, 4, 8, 9, 5]
func sortThird(l: [Int]) -> [Int] {
var l = l
var lPrime = [Int]()
for i in 0..<l.count {
if i % 3 == 0 {
lPrime.append(l[i])
} else {
lPrime.append(l[i])
lPrime.sort()
}
}
return lPrime
}
```
var l = l // variable 'l' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func sortThird(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<lPrime.count {
if i % 3 == 0 {
lPrime[i] = lPrime.sorted()[i]
}
}
return lPrime
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// sortThird(l: [1, 2, 3]) == [1, 2, 3]
// sortThird(l: [5, 6, 3, 4, 8, 9, 2]) == [2, 6, 3, 4, 8, 9, 5]
func sortThird(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<lPrime.count {
if i % 3 == 0 {
lPrime[i] = lPrime.sorted()[i]
}
}
return lPrime
}
```
// XCTAssertTrue failed
func sortThird(l: [Int]) -> [Int] {
var l = l
var lPrime = [Int]()
for i in 0..<l.count {
if i % 3 == 0 {
lPrime.append(l[i])
} else {
lPrime.append(l[i])
lPrime.sort()
}
}
return lPrime
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// sortThird(l: [1, 2, 3]) == [1, 2, 3]
// sortThird(l: [5, 6, 3, 4, 8, 9, 2]) == [2, 6, 3, 4, 8, 9, 5]
func sortThird(l: [Int]) -> [Int] {
var l = l
var lPrime = [Int]()
for i in 0..<l.count {
if i % 3 == 0 {
lPrime.append(l[i])
} else {
lPrime.append(l[i])
lPrime.sort()
}
}
return lPrime
}
```
var l = l // variable 'l' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func unique(l: [Int]) -> [Int] {
var result: [Int] = []
for i in l {
if!result.contains(i) {
result.append(i)
}
}
return result
}
```swift
// Return sorted unique elements in an array
// unique(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123]
func unique(l: [Int]) -> [Int] {
var result: [Int] = []
for i in l {
if!result.contains(i) {
result.append(i)
}
}
return result
}
```
if!result.contains(i) { // expected expression, var, or let in 'if' condition
func unique(l: [Int]) -> [Int] {
var result: [Int] = []
for i in l {
if!result.contains(i) {
result.append(i)
}
}
return result
}
```swift
// Return sorted unique elements in an array
// unique(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123]
func unique(l: [Int]) -> [Int] {
var result: [Int] = []
for i in l {
if!result.contains(i) {
result.append(i)
}
}
return result
}
```
if!result.contains(i) { // expected expression, var, or let in 'if' condition
func unique(l: [Int]) -> [Int] {
var unique = [Int]()
for i in l {
if!unique.contains(i) {
unique.append(i)
}
}
return unique
}
```swift
// Return sorted unique elements in an array
// unique(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123]
func unique(l: [Int]) -> [Int] {
var unique = [Int]()
for i in l {
if!unique.contains(i) {
unique.append(i)
}
}
return unique
}
```
if!unique.contains(i) { // expected expression, var, or let in 'if' condition
func unique(l: [Int]) -> [Int] {
var unique = [Int]()
for i in l {
if!unique.contains(i) {
unique.append(i)
}
}
return unique
}
```swift
// Return sorted unique elements in an array
// unique(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123]
func unique(l: [Int]) -> [Int] {
var unique = [Int]()
for i in l {
if!unique.contains(i) {
unique.append(i)
}
}
return unique
}
```
if!unique.contains(i) { // expected expression, var, or let in 'if' condition
func unique(l: [Int]) -> [Int] {
var unique = [Int]()
for i in l {
if!unique.contains(i) {
unique.append(i)
}
}
return unique
}
```swift
// Return sorted unique elements in an array
// unique(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123]
func unique(l: [Int]) -> [Int] {
var unique = [Int]()
for i in l {
if!unique.contains(i) {
unique.append(i)
}
}
return unique
}
```
if!unique.contains(i) { // expected expression, var, or let in 'if' condition
func unique(l: [Int]) -> [Int] {
var result: [Int] = []
for i in l {
if!result.contains(i) {
result.append(i)
}
}
return result
}
```swift
// Return sorted unique elements in an array
// unique(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123]
func unique(l: [Int]) -> [Int] {
var result: [Int] = []
for i in l {
if!result.contains(i) {
result.append(i)
}
}
return result
}
```
if!result.contains(i) { // expected expression, var, or let in 'if' condition
func unique(l: [Int]) -> [Int] {
var unique = [Int]()
for i in l {
if!unique.contains(i) {
unique.append(i)
}
}
return unique
}
```swift
// Return sorted unique elements in an array
// unique(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123]
func unique(l: [Int]) -> [Int] {
var unique = [Int]()
for i in l {
if!unique.contains(i) {
unique.append(i)
}
}
return unique
}
```
if!unique.contains(i) { // expected expression, var, or let in 'if' condition
func unique(l: [Int]) -> [Int] {
var result: [Int] = []
for i in l {
if!result.contains(i) {
result.append(i)
}
}
return result
}
```swift
// Return sorted unique elements in an array
// unique(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123]
func unique(l: [Int]) -> [Int] {
var result: [Int] = []
for i in l {
if!result.contains(i) {
result.append(i)
}
}
return result
}
```
if!result.contains(i) { // expected expression, var, or let in 'if' condition
func unique(l: [Int]) -> [Int] {
var unique = [Int]()
for i in l {
if!unique.contains(i) {
unique.append(i)
}
}
return unique
}
```swift
// Return sorted unique elements in an array
// unique(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123]
func unique(l: [Int]) -> [Int] {
var unique = [Int]()
for i in l {
if!unique.contains(i) {
unique.append(i)
}
}
return unique
}
```
if!unique.contains(i) { // expected expression, var, or let in 'if' condition
func unique(l: [Int]) -> [Int] {
var unique = [Int]()
for i in l {
if!unique.contains(i) {
unique.append(i)
}
}
return unique
}
```swift
// Return sorted unique elements in an array
// unique(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123]
func unique(l: [Int]) -> [Int] {
var unique = [Int]()
for i in l {
if!unique.contains(i) {
unique.append(i)
}
}
return unique
}
```
if!unique.contains(i) { // expected expression, var, or let in 'if' condition
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in l {
if i > max {
max = i
}
}
return max
}
```swift
// Return maximum element in the array.
// maxElement(l: [1, 2, 3]) == 3
// maxElement(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == 123
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in l {
if i > max {
max = i
}
}
return max
}
```
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in l {
if i > max {
max = i
}
}
return max
}
```swift
// Return maximum element in the array.
// maxElement(l: [1, 2, 3]) == 3
// maxElement(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == 123
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in l {
if i > max {
max = i
}
}
return max
}
```
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in l {
if i > max {
max = i
}
}
return max
}
```swift
// Return maximum element in the array.
// maxElement(l: [1, 2, 3]) == 3
// maxElement(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == 123
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in l {
if i > max {
max = i
}
}
return max
}
```
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in 1..<l.count {
if l[i] > max {
max = l[i]
}
}
return max
}
```swift
// Return maximum element in the array.
// maxElement(l: [1, 2, 3]) == 3
// maxElement(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == 123
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in 1..<l.count {
if l[i] > max {
max = l[i]
}
}
return max
}
```
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in l {
if i > max {
max = i
}
}
return max
}
```swift
// Return maximum element in the array.
// maxElement(l: [1, 2, 3]) == 3
// maxElement(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == 123
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in l {
if i > max {
max = i
}
}
return max
}
```
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in 1..<l.count {
if l[i] > max {
max = l[i]
}
}
return max
}
```swift
// Return maximum element in the array.
// maxElement(l: [1, 2, 3]) == 3
// maxElement(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == 123
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in 1..<l.count {
if l[i] > max {
max = l[i]
}
}
return max
}
```
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in 1..<l.count {
if l[i] > max {
max = l[i]
}
}
return max
}
```swift
// Return maximum element in the array.
// maxElement(l: [1, 2, 3]) == 3
// maxElement(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == 123
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in 1..<l.count {
if l[i] > max {
max = l[i]
}
}
return max
}
```
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in l {
if i > max {
max = i
}
}
return max
}
```swift
// Return maximum element in the array.
// maxElement(l: [1, 2, 3]) == 3
// maxElement(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == 123
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in l {
if i > max {
max = i
}
}
return max
}
```
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in 1..<l.count {
if l[i] > max {
max = l[i]
}
}
return max
}
```swift
// Return maximum element in the array.
// maxElement(l: [1, 2, 3]) == 3
// maxElement(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == 123
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in 1..<l.count {
if l[i] > max {
max = l[i]
}
}
return max
}
```
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in 1..<l.count {
if l[i] > max {
max = l[i]
}
}
return max
}
```swift
// Return maximum element in the array.
// maxElement(l: [1, 2, 3]) == 3
// maxElement(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == 123
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in 1..<l.count {
if l[i] > max {
max = l[i]
}
}
return max
}
```
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1...n {
if i % 11 == 0 || i % 13 == 0 {
count += 1
}
}
return count
}
```swift
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// fizzBuzz(n: 50) == 0
// fizzBuzz(n: 78) == 2
// fizzBuzz(n: 79) == 3
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1...n {
if i % 11 == 0 || i % 13 == 0 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1...n {
if i % 11 == 0 || i % 13 == 0 {
count += 1
}
}
return count
}
```swift
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// fizzBuzz(n: 50) == 0
// fizzBuzz(n: 78) == 2
// fizzBuzz(n: 79) == 3
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1...n {
if i % 11 == 0 || i % 13 == 0 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1...n {
if i % 11 == 0 || i % 13 == 0 {
count += 1
}
}
return count
}
```swift
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// fizzBuzz(n: 50) == 0
// fizzBuzz(n: 78) == 2
// fizzBuzz(n: 79) == 3
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1...n {
if i % 11 == 0 || i % 13 == 0 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1...n {
if i % 11 == 0 || i % 13 == 0 {
count += 1
}
}
return count
}
```swift
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// fizzBuzz(n: 50) == 0
// fizzBuzz(n: 78) == 2
// fizzBuzz(n: 79) == 3
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1...n {
if i % 11 == 0 || i % 13 == 0 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1...n {
if i % 11 == 0 || i % 13 == 0 {
count += 1
}
}
return count
}
```swift
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// fizzBuzz(n: 50) == 0
// fizzBuzz(n: 78) == 2
// fizzBuzz(n: 79) == 3
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1...n {
if i % 11 == 0 || i % 13 == 0 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1...n {
if i % 11 == 0 || i % 13 == 0 {
count += 1
}
}
return count
}
```swift
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// fizzBuzz(n: 50) == 0
// fizzBuzz(n: 78) == 2
// fizzBuzz(n: 79) == 3
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1...n {
if i % 11 == 0 || i % 13 == 0 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1...n {
if i % 11 == 0 || i % 13 == 0 {
count += 1
}
}
return count
}
```swift
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// fizzBuzz(n: 50) == 0
// fizzBuzz(n: 78) == 2
// fizzBuzz(n: 79) == 3
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1...n {
if i % 11 == 0 || i % 13 == 0 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1...n {
if i % 11 == 0 || i % 13 == 0 {
count += 1
}
}
return count
}
```swift
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// fizzBuzz(n: 50) == 0
// fizzBuzz(n: 78) == 2
// fizzBuzz(n: 79) == 3
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1...n {
if i % 11 == 0 || i % 13 == 0 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1...n {
if i % 11 == 0 || i % 13 == 0 {
count += 1
}
}
return count
}
```swift
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// fizzBuzz(n: 50) == 0
// fizzBuzz(n: 78) == 2
// fizzBuzz(n: 79) == 3
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1...n {
if i % 11 == 0 || i % 13 == 0 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1...n {
if i % 11 == 0 || i % 13 == 0 {
count += 1
}
}
return count
}
```swift
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// fizzBuzz(n: 50) == 0
// fizzBuzz(n: 78) == 2
// fizzBuzz(n: 79) == 3
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1...n {
if i % 11 == 0 || i % 13 == 0 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func sortEven(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<l.count {
if i % 2 == 0 {
lPrime[i] = l[i]
} else {
lPrime[i] = l[i].sorted()
}
}
return lPrime
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// sortEven(l: [1, 2, 3]) == [1, 2, 3]
// sortEven(l: [5, 6, 3, 4]) == [3, 6, 5, 4]
func sortEven(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<l.count {
if i % 2 == 0 {
lPrime[i] = l[i]
} else {
lPrime[i] = l[i].sorted()
}
}
return lPrime
}
```
lPrime[i] = l[i].sorted() // value of type 'Int' has no member 'sorted'
func sortEven(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 2 == 0 {
l[i] = l[i].sorted()
}
}
return l
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// sortEven(l: [1, 2, 3]) == [1, 2, 3]
// sortEven(l: [5, 6, 3, 4]) == [3, 6, 5, 4]
func sortEven(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 2 == 0 {
l[i] = l[i].sorted()
}
}
return l
}
```
l[i] = l[i].sorted() // value of type 'Int' has no member 'sorted'
func sortEven(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<l.count {
if i % 2 == 0 {
lPrime[i] = l[i]
} else {
lPrime[i] = l[i].sorted()
}
}
return lPrime
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// sortEven(l: [1, 2, 3]) == [1, 2, 3]
// sortEven(l: [5, 6, 3, 4]) == [3, 6, 5, 4]
func sortEven(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<l.count {
if i % 2 == 0 {
lPrime[i] = l[i]
} else {
lPrime[i] = l[i].sorted()
}
}
return lPrime
}
```
lPrime[i] = l[i].sorted() // value of type 'Int' has no member 'sorted'
func sortEven(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<l.count {
if i % 2 == 0 {
lPrime[i] = l[i]
} else {
lPrime[i] = l[i].sorted()
}
}
return lPrime
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// sortEven(l: [1, 2, 3]) == [1, 2, 3]
// sortEven(l: [5, 6, 3, 4]) == [3, 6, 5, 4]
func sortEven(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<l.count {
if i % 2 == 0 {
lPrime[i] = l[i]
} else {
lPrime[i] = l[i].sorted()
}
}
return lPrime
}
```
lPrime[i] = l[i].sorted() // value of type 'Int' has no member 'sorted'
func sortEven(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<l.count {
if i % 2 == 0 {
lPrime[i] = l[i]
} else {
lPrime[i] = l[i].sorted()
}
}
return lPrime
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// sortEven(l: [1, 2, 3]) == [1, 2, 3]
// sortEven(l: [5, 6, 3, 4]) == [3, 6, 5, 4]
func sortEven(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<l.count {
if i % 2 == 0 {
lPrime[i] = l[i]
} else {
lPrime[i] = l[i].sorted()
}
}
return lPrime
}
```
lPrime[i] = l[i].sorted() // value of type 'Int' has no member 'sorted'
func sortEven(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<lPrime.count {
if i % 2 == 0 {
lPrime[i] = l[i]
} else {
lPrime[i] = l[i].sorted()
}
}
return lPrime
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// sortEven(l: [1, 2, 3]) == [1, 2, 3]
// sortEven(l: [5, 6, 3, 4]) == [3, 6, 5, 4]
func sortEven(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<lPrime.count {
if i % 2 == 0 {
lPrime[i] = l[i]
} else {
lPrime[i] = l[i].sorted()
}
}
return lPrime
}
```
lPrime[i] = l[i].sorted() // value of type 'Int' has no member 'sorted'
func sortEven(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<l.count {
if i % 2 == 0 {
lPrime[i] = l[i]
} else {
lPrime[i] = l[i].sorted()
}
}
return lPrime
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// sortEven(l: [1, 2, 3]) == [1, 2, 3]
// sortEven(l: [5, 6, 3, 4]) == [3, 6, 5, 4]
func sortEven(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<l.count {
if i % 2 == 0 {
lPrime[i] = l[i]
} else {
lPrime[i] = l[i].sorted()
}
}
return lPrime
}
```
lPrime[i] = l[i].sorted() // value of type 'Int' has no member 'sorted'
func sortEven(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 2 == 0 {
l[i] = l.sorted()[i / 2]
}
}
return l
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// sortEven(l: [1, 2, 3]) == [1, 2, 3]
// sortEven(l: [5, 6, 3, 4]) == [3, 6, 5, 4]
func sortEven(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 2 == 0 {
l[i] = l.sorted()[i / 2]
}
}
return l
}
```
// XCTAssertTrue failed
func sortEven(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<lPrime.count {
if i % 2 == 0 {
lPrime[i] = l[i]
}
}
lPrime.sort()
return lPrime
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// sortEven(l: [1, 2, 3]) == [1, 2, 3]
// sortEven(l: [5, 6, 3, 4]) == [3, 6, 5, 4]
func sortEven(l: [Int]) -> [Int] {
var lPrime = l
for i in 0..<lPrime.count {
if i % 2 == 0 {
lPrime[i] = l[i]
}
}
lPrime.sort()
return lPrime
}
```
// XCTAssertTrue failed
func sortEven(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 2 == 0 {
l[i] = l.sorted()[i]
}
}
return l
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// sortEven(l: [1, 2, 3]) == [1, 2, 3]
// sortEven(l: [5, 6, 3, 4]) == [3, 6, 5, 4]
func sortEven(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 2 == 0 {
l[i] = l.sorted()[i]
}
}
return l
}
```
// XCTAssertTrue failed
func primeFib(n: Int) -> Int {
var fib = [1, 2]
var i = 2
while fib.count < n {
if isPrime(fib[i-1] + fib[i-2]) {
fib.append(fib[i-1] + fib[i-2])
}
i += 1
}
return fib[n-1]
}
```swift
// prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// primeFib(n: 1) == 2
// primeFib(n: 2) == 3
// primeFib(n: 3) == 5
// primeFib(n: 4) == 13
// primeFib(n: 5) == 89
func primeFib(n: Int) -> Int {
var fib = [1, 2]
var i = 2
while fib.count < n {
if isPrime(fib[i-1] + fib[i-2]) {
fib.append(fib[i-1] + fib[i-2])
}
i += 1
}
return fib[n-1]
}
```
if isPrime(fib[i-1] + fib[i-2]) { // cannot find 'isPrime' in scope
func primeFib(n: Int) -> Int {
var fib = [1, 2]
var i = 2
while fib.count < n {
let next = fib[i - 1] + fib[i - 2]
if isPrime(next) {
fib.append(next)
}
i += 1
}
return fib[n - 1]
}
```swift
// prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// primeFib(n: 1) == 2
// primeFib(n: 2) == 3
// primeFib(n: 3) == 5
// primeFib(n: 4) == 13
// primeFib(n: 5) == 89
func primeFib(n: Int) -> Int {
var fib = [1, 2]
var i = 2
while fib.count < n {
let next = fib[i - 1] + fib[i - 2]
if isPrime(next) {
fib.append(next)
}
i += 1
}
return fib[n - 1]
}
```
if isPrime(next) { // cannot find 'isPrime' in scope
func primeFib(n: Int) -> Int {
var a = 1, b = 1, c = 0
for _ in 1..<n {
c = a + b
a = b
b = c
}
return c
}
```swift
// prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// primeFib(n: 1) == 2
// primeFib(n: 2) == 3
// primeFib(n: 3) == 5
// primeFib(n: 4) == 13
// primeFib(n: 5) == 89
func primeFib(n: Int) -> Int {
var a = 1, b = 1, c = 0
for _ in 1..<n {
c = a + b
a = b
b = c
}
return c
}
```
// XCTAssertTrue failed
func primeFib(n: Int) -> Int {
var fib = [1, 2]
var i = 2
while fib.count < n {
let next = fib[i - 1] + fib[i - 2]
if isPrime(next) {
fib.append(next)
}
i += 1
}
return fib[n - 1]
}
```swift
// prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// primeFib(n: 1) == 2
// primeFib(n: 2) == 3
// primeFib(n: 3) == 5
// primeFib(n: 4) == 13
// primeFib(n: 5) == 89
func primeFib(n: Int) -> Int {
var fib = [1, 2]
var i = 2
while fib.count < n {
let next = fib[i - 1] + fib[i - 2]
if isPrime(next) {
fib.append(next)
}
i += 1
}
return fib[n - 1]
}
```
if isPrime(next) { // cannot find 'isPrime' in scope
func primeFib(n: Int) -> Int {
var fib = [1, 2]
var i = 2
while fib.count < n {
let next = fib[i-1] + fib[i-2]
fib.append(next)
i += 1
}
return fib[n-1]
}
```swift
// prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// primeFib(n: 1) == 2
// primeFib(n: 2) == 3
// primeFib(n: 3) == 5
// primeFib(n: 4) == 13
// primeFib(n: 5) == 89
func primeFib(n: Int) -> Int {
var fib = [1, 2]
var i = 2
while fib.count < n {
let next = fib[i-1] + fib[i-2]
fib.append(next)
i += 1
}
return fib[n-1]
}
```
// XCTAssertTrue failed
func primeFib(n: Int) -> Int {
var a = 1
var b = 1
var c = 0
for _ in 1...n {
c = a + b
a = b
b = c
}
return c
}
```swift
// prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// primeFib(n: 1) == 2
// primeFib(n: 2) == 3
// primeFib(n: 3) == 5
// primeFib(n: 4) == 13
// primeFib(n: 5) == 89
func primeFib(n: Int) -> Int {
var a = 1
var b = 1
var c = 0
for _ in 1...n {
c = a + b
a = b
b = c
}
return c
}
```
// XCTAssertTrue failed
func primeFib(n: Int) -> Int {
var a = 1
var b = 1
var c = 0
var i = 1
while i < n {
c = a + b
a = b
b = c
i += 1
}
return c
}
```swift
// prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// primeFib(n: 1) == 2
// primeFib(n: 2) == 3
// primeFib(n: 3) == 5
// primeFib(n: 4) == 13
// primeFib(n: 5) == 89
func primeFib(n: Int) -> Int {
var a = 1
var b = 1
var c = 0
var i = 1
while i < n {
c = a + b
a = b
b = c
i += 1
}
return c
}
```
// XCTAssertTrue failed
func primeFib(n: Int) -> Int {
var a = 0
var b = 1
var c = 0
for _ in 0..<n {
c = a + b
a = b
b = c
}
return c
}
```swift
// prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// primeFib(n: 1) == 2
// primeFib(n: 2) == 3
// primeFib(n: 3) == 5
// primeFib(n: 4) == 13
// primeFib(n: 5) == 89
func primeFib(n: Int) -> Int {
var a = 0
var b = 1
var c = 0
for _ in 0..<n {
c = a + b
a = b
b = c
}
return c
}
```
// XCTAssertTrue failed
func primeFib(n: Int) -> Int {
var fib = [1, 2]
var i = 2
while fib.count < n {
let next = fib[i - 1] + fib[i - 2]
if isPrime(next) {
fib.append(next)
}
i += 1
}
return fib[n - 1]
}
```swift
// prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// primeFib(n: 1) == 2
// primeFib(n: 2) == 3
// primeFib(n: 3) == 5
// primeFib(n: 4) == 13
// primeFib(n: 5) == 89
func primeFib(n: Int) -> Int {
var fib = [1, 2]
var i = 2
while fib.count < n {
let next = fib[i - 1] + fib[i - 2]
if isPrime(next) {
fib.append(next)
}
i += 1
}
return fib[n - 1]
}
```
if isPrime(next) { // cannot find 'isPrime' in scope
func primeFib(n: Int) -> Int {
var a = 1, b = 1
for _ in 1..<n {
let c = a + b
if isPrime(c) {
a = b
b = c
}
}
return b
}
```swift
// prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// primeFib(n: 1) == 2
// primeFib(n: 2) == 3
// primeFib(n: 3) == 5
// primeFib(n: 4) == 13
// primeFib(n: 5) == 89
func primeFib(n: Int) -> Int {
var a = 1, b = 1
for _ in 1..<n {
let c = a + b
if isPrime(c) {
a = b
b = c
}
}
return b
}
```
if isPrime(c) { // cannot find 'isPrime' in scope
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: implement me
return false
}
```swift
// triples_sum_to_zero takes an array of integers as an input.
// it returns true if there are three distinct elements in the array that
// sum to zero, and false otherwise.
// triplesSumToZero(l: [1, 3, 5, 0]) == false
// triplesSumToZero(l: [1, 3, -2, 1]) == true
// triplesSumToZero(l: [1, 2, 3, 7]) == false
// triplesSumToZero(l: [2, 4, -5, 3, 9, 7]) == true
// triplesSumToZero(l: [1]) == false
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: implement me
return false
}
```
// XCTAssertTrue failed
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: Write your code here.
return false
}
```swift
// triples_sum_to_zero takes an array of integers as an input.
// it returns true if there are three distinct elements in the array that
// sum to zero, and false otherwise.
// triplesSumToZero(l: [1, 3, 5, 0]) == false
// triplesSumToZero(l: [1, 3, -2, 1]) == true
// triplesSumToZero(l: [1, 2, 3, 7]) == false
// triplesSumToZero(l: [2, 4, -5, 3, 9, 7]) == true
// triplesSumToZero(l: [1]) == false
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: Write your code here.
return false
}
```
// XCTAssertTrue failed
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: implement this function
}
```swift
// triples_sum_to_zero takes an array of integers as an input.
// it returns true if there are three distinct elements in the array that
// sum to zero, and false otherwise.
// triplesSumToZero(l: [1, 3, 5, 0]) == false
// triplesSumToZero(l: [1, 3, -2, 1]) == true
// triplesSumToZero(l: [1, 2, 3, 7]) == false
// triplesSumToZero(l: [2, 4, -5, 3, 9, 7]) == true
// triplesSumToZero(l: [1]) == false
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: implement this function
}
```
} // missing return in global function expected to return 'Bool'
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: implement this function
return false
}
```swift
// triples_sum_to_zero takes an array of integers as an input.
// it returns true if there are three distinct elements in the array that
// sum to zero, and false otherwise.
// triplesSumToZero(l: [1, 3, 5, 0]) == false
// triplesSumToZero(l: [1, 3, -2, 1]) == true
// triplesSumToZero(l: [1, 2, 3, 7]) == false
// triplesSumToZero(l: [2, 4, -5, 3, 9, 7]) == true
// triplesSumToZero(l: [1]) == false
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: implement this function
return false
}
```
// XCTAssertTrue failed
func triplesSumToZero(l: [Int]) -> Bool {
var set = Set<Int>()
for i in l {
if set.contains(-i) {
return true
}
set.insert(i)
}
return false
}
```swift
// triples_sum_to_zero takes an array of integers as an input.
// it returns true if there are three distinct elements in the array that
// sum to zero, and false otherwise.
// triplesSumToZero(l: [1, 3, 5, 0]) == false
// triplesSumToZero(l: [1, 3, -2, 1]) == true
// triplesSumToZero(l: [1, 2, 3, 7]) == false
// triplesSumToZero(l: [2, 4, -5, 3, 9, 7]) == true
// triplesSumToZero(l: [1]) == false
func triplesSumToZero(l: [Int]) -> Bool {
var set = Set<Int>()
for i in l {
if set.contains(-i) {
return true
}
set.insert(i)
}
return false
}
```
// XCTAssertTrue failed
func triplesSumToZero(l: [Int]) -> Bool {
var set = Set<Int>()
for i in l {
if set.contains(-i) {
return true
}
set.insert(i)
}
return false
}
```swift
// triples_sum_to_zero takes an array of integers as an input.
// it returns true if there are three distinct elements in the array that
// sum to zero, and false otherwise.
// triplesSumToZero(l: [1, 3, 5, 0]) == false
// triplesSumToZero(l: [1, 3, -2, 1]) == true
// triplesSumToZero(l: [1, 2, 3, 7]) == false
// triplesSumToZero(l: [2, 4, -5, 3, 9, 7]) == true
// triplesSumToZero(l: [1]) == false
func triplesSumToZero(l: [Int]) -> Bool {
var set = Set<Int>()
for i in l {
if set.contains(-i) {
return true
}
set.insert(i)
}
return false
}
```
// XCTAssertTrue failed
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: Implement this function.
return false
}
```swift
// triples_sum_to_zero takes an array of integers as an input.
// it returns true if there are three distinct elements in the array that
// sum to zero, and false otherwise.
// triplesSumToZero(l: [1, 3, 5, 0]) == false
// triplesSumToZero(l: [1, 3, -2, 1]) == true
// triplesSumToZero(l: [1, 2, 3, 7]) == false
// triplesSumToZero(l: [2, 4, -5, 3, 9, 7]) == true
// triplesSumToZero(l: [1]) == false
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: Implement this function.
return false
}
```
// XCTAssertTrue failed
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: implement me
return false
}
```swift
// triples_sum_to_zero takes an array of integers as an input.
// it returns true if there are three distinct elements in the array that
// sum to zero, and false otherwise.
// triplesSumToZero(l: [1, 3, 5, 0]) == false
// triplesSumToZero(l: [1, 3, -2, 1]) == true
// triplesSumToZero(l: [1, 2, 3, 7]) == false
// triplesSumToZero(l: [2, 4, -5, 3, 9, 7]) == true
// triplesSumToZero(l: [1]) == false
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: implement me
return false
}
```
// XCTAssertTrue failed
func triplesSumToZero(l: [Int]) -> Bool {
var seen = Set<Int>()
for i in l {
if seen.contains(-i) {
return true
}
seen.insert(i)
}
return false
}
```swift
// triples_sum_to_zero takes an array of integers as an input.
// it returns true if there are three distinct elements in the array that
// sum to zero, and false otherwise.
// triplesSumToZero(l: [1, 3, 5, 0]) == false
// triplesSumToZero(l: [1, 3, -2, 1]) == true
// triplesSumToZero(l: [1, 2, 3, 7]) == false
// triplesSumToZero(l: [2, 4, -5, 3, 9, 7]) == true
// triplesSumToZero(l: [1]) == false
func triplesSumToZero(l: [Int]) -> Bool {
var seen = Set<Int>()
for i in l {
if seen.contains(-i) {
return true
}
seen.insert(i)
}
return false
}
```
// XCTAssertTrue failed
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: Write your code here
return false
}
```swift
// triples_sum_to_zero takes an array of integers as an input.
// it returns true if there are three distinct elements in the array that
// sum to zero, and false otherwise.
// triplesSumToZero(l: [1, 3, 5, 0]) == false
// triplesSumToZero(l: [1, 3, -2, 1]) == true
// triplesSumToZero(l: [1, 2, 3, 7]) == false
// triplesSumToZero(l: [2, 4, -5, 3, 9, 7]) == true
// triplesSumToZero(l: [1]) == false
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: Write your code here
return false
}
```
// XCTAssertTrue failed
func carRaceCollision(n: Int) -> Int {
// TODO: implement this function
}
```swift
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
func carRaceCollision(n: Int) -> Int {
// TODO: implement this function
}
```
} // missing return in global function expected to return 'Int'
func carRaceCollision(n: Int) -> Int {
//...
}
```swift
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
func carRaceCollision(n: Int) -> Int {
//...
}
```
} // missing return in global function expected to return 'Int'
func carRaceCollision(n: Int) -> Int {
// TODO: implement this function
}
```swift
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
func carRaceCollision(n: Int) -> Int {
// TODO: implement this function
}
```
} // missing return in global function expected to return 'Int'
func carRaceCollision(n: Int) -> Int {
// TODO: Implement this function.
}
```swift
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
func carRaceCollision(n: Int) -> Int {
// TODO: Implement this function.
}
```
} // missing return in global function expected to return 'Int'
func carRaceCollision(n: Int) -> Int {
// TODO: implement this function
}
```swift
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
func carRaceCollision(n: Int) -> Int {
// TODO: implement this function
}
```
} // missing return in global function expected to return 'Int'
func carRaceCollision(n: Int) -> Int {
// TODO: implement this function
}
```swift
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
func carRaceCollision(n: Int) -> Int {
// TODO: implement this function
}
```
} // missing return in global function expected to return 'Int'
func carRaceCollision(n: Int) -> Int {
// TODO: implement this function
}
```swift
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
func carRaceCollision(n: Int) -> Int {
// TODO: implement this function
}
```
} // missing return in global function expected to return 'Int'
func carRaceCollision(n: Int) -> Int {
// TODO: implement this function
}
```swift
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
func carRaceCollision(n: Int) -> Int {
// TODO: implement this function
}
```
} // missing return in global function expected to return 'Int'
func carRaceCollision(n: Int) -> Int {
// TODO: implement this function
}
```swift
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
func carRaceCollision(n: Int) -> Int {
// TODO: implement this function
}
```
} // missing return in global function expected to return 'Int'
func carRaceCollision(n: Int) -> Int {
// TODO: implement this function
}
```swift
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
func carRaceCollision(n: Int) -> Int {
// TODO: implement this function
}
```
} // missing return in global function expected to return 'Int'
func incrList(l: [Int]) -> [Int] {
var result = [Int]()
for i in l {
result.append(i + 1)
}
return result
}
```swift
// Return array with elements incremented by 1.
// incrList(l: [1, 2, 3]) == [2, 3, 4]
// incrList(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [6, 4, 6, 3, 4, 4, 10, 1, 124]
func incrList(l: [Int]) -> [Int] {
var result = [Int]()
for i in l {
result.append(i + 1)
}
return result
}
```
func incrList(l: [Int]) -> [Int] {
var result = [Int]()
for i in l {
result.append(i + 1)
}
return result
}
```swift
// Return array with elements incremented by 1.
// incrList(l: [1, 2, 3]) == [2, 3, 4]
// incrList(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [6, 4, 6, 3, 4, 4, 10, 1, 124]
func incrList(l: [Int]) -> [Int] {
var result = [Int]()
for i in l {
result.append(i + 1)
}
return result
}
```
func incrList(l: [Int]) -> [Int] {
var result: [Int] = []
for i in l {
result.append(i + 1)
}
return result
}
```swift
// Return array with elements incremented by 1.
// incrList(l: [1, 2, 3]) == [2, 3, 4]
// incrList(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [6, 4, 6, 3, 4, 4, 10, 1, 124]
func incrList(l: [Int]) -> [Int] {
var result: [Int] = []
for i in l {
result.append(i + 1)
}
return result
}
```
func incrList(l: [Int]) -> [Int] {
return l.map { $0 + 1 }
}
```swift
// Return array with elements incremented by 1.
// incrList(l: [1, 2, 3]) == [2, 3, 4]
// incrList(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [6, 4, 6, 3, 4, 4, 10, 1, 124]
func incrList(l: [Int]) -> [Int] {
return l.map { $0 + 1 }
}
```
func incrList(l: [Int]) -> [Int] {
var result = [Int]()
for i in l {
result.append(i + 1)
}
return result
}
```swift
// Return array with elements incremented by 1.
// incrList(l: [1, 2, 3]) == [2, 3, 4]
// incrList(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [6, 4, 6, 3, 4, 4, 10, 1, 124]
func incrList(l: [Int]) -> [Int] {
var result = [Int]()
for i in l {
result.append(i + 1)
}
return result
}
```
func incrList(l: [Int]) -> [Int] {
var result: [Int] = []
for i in l {
result.append(i + 1)
}
return result
}
```swift
// Return array with elements incremented by 1.
// incrList(l: [1, 2, 3]) == [2, 3, 4]
// incrList(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [6, 4, 6, 3, 4, 4, 10, 1, 124]
func incrList(l: [Int]) -> [Int] {
var result: [Int] = []
for i in l {
result.append(i + 1)
}
return result
}
```
func incrList(l: [Int]) -> [Int] {
var result = [Int]()
for i in l {
result.append(i + 1)
}
return result
}
```swift
// Return array with elements incremented by 1.
// incrList(l: [1, 2, 3]) == [2, 3, 4]
// incrList(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [6, 4, 6, 3, 4, 4, 10, 1, 124]
func incrList(l: [Int]) -> [Int] {
var result = [Int]()
for i in l {
result.append(i + 1)
}
return result
}
```
func incrList(l: [Int]) -> [Int] {
var result: [Int] = []
for i in l {
result.append(i + 1)
}
return result
}
```swift
// Return array with elements incremented by 1.
// incrList(l: [1, 2, 3]) == [2, 3, 4]
// incrList(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [6, 4, 6, 3, 4, 4, 10, 1, 124]
func incrList(l: [Int]) -> [Int] {
var result: [Int] = []
for i in l {
result.append(i + 1)
}
return result
}
```
func incrList(l: [Int]) -> [Int] {
var newList = [Int]()
for i in l {
newList.append(i + 1)
}
return newList
}
```swift
// Return array with elements incremented by 1.
// incrList(l: [1, 2, 3]) == [2, 3, 4]
// incrList(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [6, 4, 6, 3, 4, 4, 10, 1, 124]
func incrList(l: [Int]) -> [Int] {
var newList = [Int]()
for i in l {
newList.append(i + 1)
}
return newList
}
```
func incrList(l: [Int]) -> [Int] {
var result: [Int] = []
for i in l {
result.append(i + 1)
}
return result
}
```swift
// Return array with elements incremented by 1.
// incrList(l: [1, 2, 3]) == [2, 3, 4]
// incrList(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [6, 4, 6, 3, 4, 4, 10, 1, 124]
func incrList(l: [Int]) -> [Int] {
var result: [Int] = []
for i in l {
result.append(i + 1)
}
return result
}
```
func pairsSumToZero(l: [Int]) -> Bool {
// TODO: implement this function
}
```swift
// pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// pairsSumToZero(l: [1, 3, 5, 0]) == false
// pairsSumToZero(l: [1, 3, -2, 1]) == false
// pairsSumToZero(l: [1, 2, 3, 7]) == false
// pairsSumToZero(l: [2, 4, -5, 3, 5, 7]) == true
// pairsSumToZero(l: [1]) == false
func pairsSumToZero(l: [Int]) -> Bool {
// TODO: implement this function
}
```
} // missing return in global function expected to return 'Bool'
func pairsSumToZero(l: [Int]) -> Bool {
var seen = Set<Int>()
for i in l {
if seen.contains(-i) {
return true
}
seen.insert(i)
}
return false
}
```swift
// pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// pairsSumToZero(l: [1, 3, 5, 0]) == false
// pairsSumToZero(l: [1, 3, -2, 1]) == false
// pairsSumToZero(l: [1, 2, 3, 7]) == false
// pairsSumToZero(l: [2, 4, -5, 3, 5, 7]) == true
// pairsSumToZero(l: [1]) == false
func pairsSumToZero(l: [Int]) -> Bool {
var seen = Set<Int>()
for i in l {
if seen.contains(-i) {
return true
}
seen.insert(i)
}
return false
}
```
func pairsSumToZero(l: [Int]) -> Bool {
var set = Set<Int>()
for i in l {
if set.contains(-i) {
return true
}
set.insert(i)
}
return false
}
```swift
// pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// pairsSumToZero(l: [1, 3, 5, 0]) == false
// pairsSumToZero(l: [1, 3, -2, 1]) == false
// pairsSumToZero(l: [1, 2, 3, 7]) == false
// pairsSumToZero(l: [2, 4, -5, 3, 5, 7]) == true
// pairsSumToZero(l: [1]) == false
func pairsSumToZero(l: [Int]) -> Bool {
var set = Set<Int>()
for i in l {
if set.contains(-i) {
return true
}
set.insert(i)
}
return false
}
```
func pairsSumToZero(l: [Int]) -> Bool {
var seen = Set<Int>()
for i in l {
if seen.contains(-i) {
return true
}
seen.insert(i)
}
return false
}
```swift
// pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// pairsSumToZero(l: [1, 3, 5, 0]) == false
// pairsSumToZero(l: [1, 3, -2, 1]) == false
// pairsSumToZero(l: [1, 2, 3, 7]) == false
// pairsSumToZero(l: [2, 4, -5, 3, 5, 7]) == true
// pairsSumToZero(l: [1]) == false
func pairsSumToZero(l: [Int]) -> Bool {
var seen = Set<Int>()
for i in l {
if seen.contains(-i) {
return true
}
seen.insert(i)
}
return false
}
```
func pairsSumToZero(l: [Int]) -> Bool {
var seen = Set<Int>()
for i in l {
if seen.contains(-i) {
return true
}
seen.insert(i)
}
return false
}
```swift
// pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// pairsSumToZero(l: [1, 3, 5, 0]) == false
// pairsSumToZero(l: [1, 3, -2, 1]) == false
// pairsSumToZero(l: [1, 2, 3, 7]) == false
// pairsSumToZero(l: [2, 4, -5, 3, 5, 7]) == true
// pairsSumToZero(l: [1]) == false
func pairsSumToZero(l: [Int]) -> Bool {
var seen = Set<Int>()
for i in l {
if seen.contains(-i) {
return true
}
seen.insert(i)
}
return false
}
```
func pairsSumToZero(l: [Int]) -> Bool {
var set = Set<Int>()
for i in l {
if set.contains(-i) {
return true
}
set.insert(i)
}
return false
}
```swift
// pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// pairsSumToZero(l: [1, 3, 5, 0]) == false
// pairsSumToZero(l: [1, 3, -2, 1]) == false
// pairsSumToZero(l: [1, 2, 3, 7]) == false
// pairsSumToZero(l: [2, 4, -5, 3, 5, 7]) == true
// pairsSumToZero(l: [1]) == false
func pairsSumToZero(l: [Int]) -> Bool {
var set = Set<Int>()
for i in l {
if set.contains(-i) {
return true
}
set.insert(i)
}
return false
}
```
func pairsSumToZero(l: [Int]) -> Bool {
var set = Set<Int>()
for i in l {
if set.contains(-i) {
return true
}
set.insert(i)
}
return false
}
```swift
// pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// pairsSumToZero(l: [1, 3, 5, 0]) == false
// pairsSumToZero(l: [1, 3, -2, 1]) == false
// pairsSumToZero(l: [1, 2, 3, 7]) == false
// pairsSumToZero(l: [2, 4, -5, 3, 5, 7]) == true
// pairsSumToZero(l: [1]) == false
func pairsSumToZero(l: [Int]) -> Bool {
var set = Set<Int>()
for i in l {
if set.contains(-i) {
return true
}
set.insert(i)
}
return false
}
```
func pairsSumToZero(l: [Int]) -> Bool {
var seen = Set<Int>()
for i in l {
if seen.contains(-i) {
return true
}
seen.insert(i)
}
return false
}
```swift
// pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// pairsSumToZero(l: [1, 3, 5, 0]) == false
// pairsSumToZero(l: [1, 3, -2, 1]) == false
// pairsSumToZero(l: [1, 2, 3, 7]) == false
// pairsSumToZero(l: [2, 4, -5, 3, 5, 7]) == true
// pairsSumToZero(l: [1]) == false
func pairsSumToZero(l: [Int]) -> Bool {
var seen = Set<Int>()
for i in l {
if seen.contains(-i) {
return true
}
seen.insert(i)
}
return false
}
```
func pairsSumToZero(l: [Int]) -> Bool {
var seen = Set<Int>()
for i in l {
if seen.contains(-i) {
return true
}
seen.insert(i)
}
return false
}
```swift
// pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// pairsSumToZero(l: [1, 3, 5, 0]) == false
// pairsSumToZero(l: [1, 3, -2, 1]) == false
// pairsSumToZero(l: [1, 2, 3, 7]) == false
// pairsSumToZero(l: [2, 4, -5, 3, 5, 7]) == true
// pairsSumToZero(l: [1]) == false
func pairsSumToZero(l: [Int]) -> Bool {
var seen = Set<Int>()
for i in l {
if seen.contains(-i) {
return true
}
seen.insert(i)
}
return false
}
```
func pairsSumToZero(l: [Int]) -> Bool {
var seen = Set<Int>()
for i in l {
if seen.contains(-i) {
return true
}
seen.insert(i)
}
return false
}
```swift
// pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// pairsSumToZero(l: [1, 3, 5, 0]) == false
// pairsSumToZero(l: [1, 3, -2, 1]) == false
// pairsSumToZero(l: [1, 2, 3, 7]) == false
// pairsSumToZero(l: [2, 4, -5, 3, 5, 7]) == true
// pairsSumToZero(l: [1]) == false
func pairsSumToZero(l: [Int]) -> Bool {
var seen = Set<Int>()
for i in l {
if seen.contains(-i) {
return true
}
seen.insert(i)
}
return false
}
```
func changeBase(x: Int, base: Int) -> String {
var result = ""
var num = x
while num > 0 {
let remainder = num % base
result = "\(remainder)" + result
num /= base
}
return result
}
```swift
// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// changeBase(x: 8, base: 3) == "22"
// changeBase(x: 8, base: 2) == "1000"
// changeBase(x: 7, base: 2) == "111"
func changeBase(x: Int, base: Int) -> String {
var result = ""
var num = x
while num > 0 {
let remainder = num % base
result = "\(remainder)" + result
num /= base
}
return result
}
```
func changeBase(x: Int, base: Int) -> String {
var result = ""
var x = x
while x > 0 {
result = String(x % base) + result
x /= base
}
return result
}
```swift
// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// changeBase(x: 8, base: 3) == "22"
// changeBase(x: 8, base: 2) == "1000"
// changeBase(x: 7, base: 2) == "111"
func changeBase(x: Int, base: Int) -> String {
var result = ""
var x = x
while x > 0 {
result = String(x % base) + result
x /= base
}
return result
}
```
func changeBase(x: Int, base: Int) -> String {
var result = ""
var remainder = x
while remainder > 0 {
result = String(remainder % base) + result
remainder /= base
}
return result
}
```swift
// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// changeBase(x: 8, base: 3) == "22"
// changeBase(x: 8, base: 2) == "1000"
// changeBase(x: 7, base: 2) == "111"
func changeBase(x: Int, base: Int) -> String {
var result = ""
var remainder = x
while remainder > 0 {
result = String(remainder % base) + result
remainder /= base
}
return result
}
```
func changeBase(x: Int, base: Int) -> String {
var result = ""
var num = x
while num > 0 {
result = "\(num % base)" + result
num /= base
}
return result
}
```swift
// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// changeBase(x: 8, base: 3) == "22"
// changeBase(x: 8, base: 2) == "1000"
// changeBase(x: 7, base: 2) == "111"
func changeBase(x: Int, base: Int) -> String {
var result = ""
var num = x
while num > 0 {
result = "\(num % base)" + result
num /= base
}
return result
}
```
func changeBase(x: Int, base: Int) -> String {
var result = ""
var x = x
while x > 0 {
result = "\(x % base)" + result
x /= base
}
return result
}
```swift
// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// changeBase(x: 8, base: 3) == "22"
// changeBase(x: 8, base: 2) == "1000"
// changeBase(x: 7, base: 2) == "111"
func changeBase(x: Int, base: Int) -> String {
var result = ""
var x = x
while x > 0 {
result = "\(x % base)" + result
x /= base
}
return result
}
```
func changeBase(x: Int, base: Int) -> String {
var result = ""
var num = x
while num > 0 {
result = String(num % base) + result
num /= base
}
return result
}
```swift
// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// changeBase(x: 8, base: 3) == "22"
// changeBase(x: 8, base: 2) == "1000"
// changeBase(x: 7, base: 2) == "111"
func changeBase(x: Int, base: Int) -> String {
var result = ""
var num = x
while num > 0 {
result = String(num % base) + result
num /= base
}
return result
}
```
func changeBase(x: Int, base: Int) -> String {
var result = ""
var num = x
while num > 0 {
result = String(num % base) + result
num /= base
}
return result
}
```swift
// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// changeBase(x: 8, base: 3) == "22"
// changeBase(x: 8, base: 2) == "1000"
// changeBase(x: 7, base: 2) == "111"
func changeBase(x: Int, base: Int) -> String {
var result = ""
var num = x
while num > 0 {
result = String(num % base) + result
num /= base
}
return result
}
```
func changeBase(x: Int, base: Int) -> String {
var result = ""
var remainder = x
while remainder > 0 {
result = String(remainder % base) + result
remainder = remainder / base
}
return result
}
```swift
// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// changeBase(x: 8, base: 3) == "22"
// changeBase(x: 8, base: 2) == "1000"
// changeBase(x: 7, base: 2) == "111"
func changeBase(x: Int, base: Int) -> String {
var result = ""
var remainder = x
while remainder > 0 {
result = String(remainder % base) + result
remainder = remainder / base
}
return result
}
```
func changeBase(x: Int, base: Int) -> String {
var result = ""
var remainder = x
while remainder > 0 {
result = String(remainder % base) + result
remainder /= base
}
return result
}
```swift
// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// changeBase(x: 8, base: 3) == "22"
// changeBase(x: 8, base: 2) == "1000"
// changeBase(x: 7, base: 2) == "111"
func changeBase(x: Int, base: Int) -> String {
var result = ""
var remainder = x
while remainder > 0 {
result = String(remainder % base) + result
remainder /= base
}
return result
}
```
func changeBase(x: Int, base: Int) -> String {
var result = ""
var remainder = x
while remainder > 0 {
result = "\(remainder % base)" + result
remainder /= base
}
return result
}
```swift
// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// changeBase(x: 8, base: 3) == "22"
// changeBase(x: 8, base: 2) == "1000"
// changeBase(x: 7, base: 2) == "111"
func changeBase(x: Int, base: Int) -> String {
var result = ""
var remainder = x
while remainder > 0 {
result = "\(remainder % base)" + result
remainder /= base
}
return result
}
```
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```swift
// Given length of a side and high return area for a triangle.
// triangleArea(a: 5, h: 3) == 7.5
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```swift
// Given length of a side and high return area for a triangle.
// triangleArea(a: 5, h: 3) == 7.5
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
func trapezoidArea(a: Int, b: Int, h: Int) -> Double {
return Double(a + b) * h / 2
}
func rectangleArea(a: Int, b: Int) -> Double {
return Double(a * b)
}
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let p = (a + b + c) / 2
return sqrt(Double(p * (p - a) * (p - b) * (p - c)))
}
```swift
// Given length of a side and high return area for a triangle.
// triangleArea(a: 5, h: 3) == 7.5
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
// Given length of two sides and return area for a trapezoid.
// trapezoidArea(a: 5, b: 3, h: 3) == 12
func trapezoidArea(a: Int, b: Int, h: Int) -> Double {
return Double(a + b) * h / 2
}
// Given length of two sides and return area for a rectangle.
// rectangleArea(a: 5, b: 3) == 15
func rectangleArea(a: Int, b: Int) -> Double {
return Double(a * b)
}
// Given length of three sides and return area for a triangle.
// triangleArea(a: 5, b: 3, c: 4) == 6
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let p = (a + b + c) / 2
return sqrt(Double(p * (p - a) * (p - b) * (p - c)))
}
// Given length of three sides and return area for a triangle.
// triangleArea(a: 5, b: 3, c: 4) == 6
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let p = (a + b + c) / 2
return sqrt(Double(p * (p - a) * (p - b) * (p - c)))
}
// Given length of three sides and return area for a triangle.
// triangleArea(a: 5, b: 3, c: 4) == 6
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let p = (a + b + c) / 2
return sqrt(Double(p * (p - a) * (p - b) * (p - c)))
}
// Given length of three sides and return area for a triangle.
// triangleArea(a: 5, b: 3, c: 4) == 6
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let p = (a + b + c) / 2
return sqrt(Double(p * (p - a) * (p - b) * (p - c)))
}
// Given length of three sides and return area for a triangle.
// triangleArea(a: 5, b: 3, c: 4) == 6
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let p = (a + b + c) / 2
return sqrt(Double(p * (p - a) * (p - b) * (p - c)))
}
// Given length of three sides and return area for a triangle.
// triangleArea(a: 5, b: 3, c: 4) == 6
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let p = (a + b + c) / 2
return sqrt(Double(p * (p - a) * (p - b) * (p - c)))
}
// Given length of three sides and return area for a triangle.
// triangleArea(a: 5, b: 3, c: 4) == 6
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let p = (a + b + c) / 2
return sqrt(Double(p * (p - a) * (p - b) * (p - c)))
}
// Given length of three sides and return area for a triangle.
// triangleArea(a: 5, b: 3, c: 4) == 6
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let p = (a + b + c) / 2
return sqrt(Double(p * (p - a) * (p - b) * (p - c)))
}
// Given length of three sides and return area for a triangle.
// triangleArea(a: 5, b: 3, c: 4) == 6
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let p = (a + b + c) / 2
return sqrt(
return Double(a + b) * h / 2 // cannot convert value of type 'Int' to expected argument type 'Double'
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
func squareArea(a: Int) -> Double {
return Double(a * a)
}
func rectangleArea(a: Int, h: Int) -> Double {
return Double(a * h)
}
func trapezoidArea(a: Int, b: Int, h: Int) -> Double {
return Double((a + b) * h) / 2
}
func parallelogramArea(a: Int, h: Int) -> Double {
return Double(a * h)
}
func rhombusArea(a: Int, h: Int) -> Double {
return Double(a * h)
}
```swift
// Given length of a side and high return area for a triangle.
// triangleArea(a: 5, h: 3) == 7.5
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
// Given length of a side and height return area for a square.
// squareArea(a: 5) == 25
func squareArea(a: Int) -> Double {
return Double(a * a)
}
// Given length of a side and height return area for a rectangle.
// rectangleArea(a: 5, h: 3) == 15
func rectangleArea(a: Int, h: Int) -> Double {
return Double(a * h)
}
// Given length of a side and height return area for a trapezoid.
// trapezoidArea(a: 5, b: 3, h: 3) == 15
func trapezoidArea(a: Int, b: Int, h: Int) -> Double {
return Double((a + b) * h) / 2
}
// Given length of a side and height return area for a parallelogram.
// parallelogramArea(a: 5, h: 3) == 15
func parallelogramArea(a: Int, h: Int) -> Double {
return Double(a * h)
}
// Given length of a side and height return area for a rhombus.
// rhombusArea(a: 5, h: 3) == 15
func rhombusArea(a: Int, h: Int) -> Double {
return Double(a * h)
}
```
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```swift
// Given length of a side and high return area for a triangle.
// triangleArea(a: 5, h: 3) == 7.5
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```swift
// Given length of a side and high return area for a triangle.
// triangleArea(a: 5, h: 3) == 7.5
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```swift
// Given length of a side and high return area for a triangle.
// triangleArea(a: 5, h: 3) == 7.5
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
func squareArea(a: Int) -> Double {
return Double(a * a)
}
func rectangleArea(a: Int, h: Int) -> Double {
return Double(a * h)
}
func trapezoidArea(a: Int, b: Int, h: Int) -> Double {
return Double((a + b) * h) / 2
}
func parallelogramArea(a: Int, h: Int) -> Double {
return Double(a * h)
}
func rhombusArea(a: Int, h: Int) -> Double {
return Double(a * h)
}
func kiteArea(a: Int, h: Int) -> Double {
return Double(a * h)
}
func circleArea(r: Int) -> Double {
return Double(Double.pi * Double(r * r))
}
func ellipseArea(a: Int, b: Int) -> Double {
return Double(Double.pi * Double(a * b))
}
func sphereArea(r: Int) -> Double {
return Double(4 * Double.pi * Double(r * r * r))
}
func coneArea(r: Int, h: Int) -> Double {
return Double(Double.pi * Double(r * r) * Double(h))
}
func cylinderArea(r: Int, h: Int) -> Double {
return Double(2 * Double.pi * Double(r * r) * Double(h))
}
func pyramidArea(r: Int, h: Int) -> Double {
return Double(Double.pi * Double(r * r) * Double(h))
}
func cubeArea(a: Int) -> Double {
return Double(a * a * a)
}
```swift
// Given length of a side and high return area for a triangle.
// triangleArea(a: 5, h: 3) == 7.5
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
// Given length of a side and high return area for a square.
// squareArea(a: 5) == 25
func squareArea(a: Int) -> Double {
return Double(a * a)
}
// Given length of a side and high return area for a rectangle.
// rectangleArea(a: 5, h: 3) == 15
func rectangleArea(a: Int, h: Int) -> Double {
return Double(a * h)
}
// Given length of a side and high return area for a trapezoid.
// trapezoidArea(a: 5, b: 3, h: 2) == 10
func trapezoidArea(a: Int, b: Int, h: Int) -> Double {
return Double((a + b) * h) / 2
}
// Given length of a side and high return area for a parallelogram.
// parallelogramArea(a: 5, h: 3) == 15
func parallelogramArea(a: Int, h: Int) -> Double {
return Double(a * h)
}
// Given length of a side and high return area for a rhombus.
// rhombusArea(a: 5, h: 3) == 15
func rhombusArea(a: Int, h: Int) -> Double {
return Double(a * h)
}
// Given length of a side and high return area for a kite.
// kiteArea(a: 5, h: 3) == 15
func kiteArea(a: Int, h: Int) -> Double {
return Double(a * h)
}
// Given length of a side and high return area for a circle.
// circleArea(r: 5) == 78.53981633974483
func circleArea(r: Int) -> Double {
return Double(Double.pi * Double(r * r))
}
// Given length of a side and high return area for a ellipse.
// ellipseArea(a: 5, b: 3) == 37.69908169872414
func ellipseArea(a: Int, b: Int) -> Double {
return Double(Double.pi * Double(a * b))
}
// Given length of a side and high return area for a sphere.
// sphereArea(r: 5) == 523.5987755982989
func sphereArea(r: Int) -> Double {
return Double(4 * Double.pi * Double(r * r * r))
}
// Given length of a side and high return area for a cone.
// coneArea(r: 5, h: 3) == 37.69908169872414
func coneArea(r: Int, h: Int) -> Double {
return Double(Double.pi * Double(r * r) * Double(h))
}
// Given length of a side and high return area for a cylinder.
// cylinderArea(r: 5, h: 3) == 37.69908169872414
func cylinderArea(r: Int, h: Int) -> Double {
return Double(2 * Double.pi * Double(r * r) * Double(h))
}
// Given length of a side and high return area for a pyramid.
// pyramidArea(r: 5, h: 3) == 37.69908169872414
func pyramidArea(r: Int, h: Int) -> Double {
return Double(Double.pi * Double(r * r) * Double(h))
}
// Given length of a side and high return area for a cube.
// cubeArea(a: 5) == 125
func cubeArea(a: Int) -> Double {
return Double(a * a * a)
}
// Given length of a side and high return area for a cuboid.
// cuboidArea(a: 5, b: 3, c: 2) == 30
func cuboidArea(a: Int, b
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```swift
// Given length of a side and high return area for a triangle.
// triangleArea(a: 5, h: 3) == 7.5
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```swift
// Given length of a side and high return area for a triangle.
// triangleArea(a: 5, h: 3) == 7.5
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```
func fib4(n: Int) -> Int {
var a = 0
var b = 0
var c = 2
var d = 0
for _ in 0..<n {
d = a + b + c
a = b
b = c
c = d
}
return d
}
```swift
// The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
// fib4(n: 5) == 4
// fib4(n: 6) == 8
// fib4(n: 7) == 14
func fib4(n: Int) -> Int {
var a = 0
var b = 0
var c = 2
var d = 0
for _ in 0..<n {
d = a + b + c
a = b
b = c
c = d
}
return d
}
```
// XCTAssertTrue failed
func fib4(n: Int) -> Int {
if n < 0 {
return 0
}
if n == 0 {
return 0
}
if n == 1 {
return 0
}
if n == 2 {
return 2
}
if n == 3 {
return 0
}
var a = 0
var b = 0
var c = 2
var d = 0
for _ in 0..<n-3 {
d = a + b + c
a = b
b = c
c = d
}
return d
}
```swift
// The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
// fib4(n: 5) == 4
// fib4(n: 6) == 8
// fib4(n: 7) == 14
func fib4(n: Int) -> Int {
if n < 0 {
return 0
}
if n == 0 {
return 0
}
if n == 1 {
return 0
}
if n == 2 {
return 2
}
if n == 3 {
return 0
}
var a = 0
var b = 0
var c = 2
var d = 0
for _ in 0..<n-3 {
d = a + b + c
a = b
b = c
c = d
}
return d
}
```
// XCTAssertTrue failed
func fib4(n: Int) -> Int {
var a = 0
var b = 0
var c = 2
var d = 0
for i in 0..<n {
d = a + b + c
a = b
b = c
c = d
}
return d
}
```swift
// The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
// fib4(n: 5) == 4
// fib4(n: 6) == 8
// fib4(n: 7) == 14
func fib4(n: Int) -> Int {
var a = 0
var b = 0
var c = 2
var d = 0
for i in 0..<n {
d = a + b + c
a = b
b = c
c = d
}
return d
}
```
for i in 0..<n { // immutable value 'i' was never used; consider replacing with '_' or removing it
// XCTAssertTrue failed
func fib4(n: Int) -> Int {
// Write your code here.
}
```swift
// The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
// fib4(n: 5) == 4
// fib4(n: 6) == 8
// fib4(n: 7) == 14
func fib4(n: Int) -> Int {
// Write your code here.
}
```
} // missing return in global function expected to return 'Int'
func fib4(n: Int) -> Int {
// TODO: Write your code here.
}
```swift
// The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
// fib4(n: 5) == 4
// fib4(n: 6) == 8
// fib4(n: 7) == 14
func fib4(n: Int) -> Int {
// TODO: Write your code here.
}
```
} // missing return in global function expected to return 'Int'
func fib4(n: Int) -> Int {
var a = 0
var b = 0
var c = 2
var d = 0
for i in 0..<n {
d = a + b + c
a = b
b = c
c = d
}
return d
}
```swift
// The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
// fib4(n: 5) == 4
// fib4(n: 6) == 8
// fib4(n: 7) == 14
func fib4(n: Int) -> Int {
var a = 0
var b = 0
var c = 2
var d = 0
for i in 0..<n {
d = a + b + c
a = b
b = c
c = d
}
return d
}
```
for i in 0..<n { // immutable value 'i' was never used; consider replacing with '_' or removing it
// XCTAssertTrue failed
func fib4(n: Int) -> Int {
if n == 0 {
return 0
} else if n == 1 {
return 0
} else if n == 2 {
return 2
} else if n == 3 {
return 0
} else {
return fib4(n: n - 1) + fib4(n: n - 2) + fib4(n: n - 3) + fib4(n: n - 4)
}
}
```swift
// The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
// fib4(n: 5) == 4
// fib4(n: 6) == 8
// fib4(n: 7) == 14
func fib4(n: Int) -> Int {
if n == 0 {
return 0
} else if n == 1 {
return 0
} else if n == 2 {
return 2
} else if n == 3 {
return 0
} else {
return fib4(n: n - 1) + fib4(n: n - 2) + fib4(n: n - 3) + fib4(n: n - 4)
}
}
```
func fib4(n: Int) -> Int {
var a = 0
var b = 0
var c = 0
var d = 0
var e = 0
for i in 1...n {
e = a + b + c + d
a = b
b = c
c = d
d = e
}
return e
}
```swift
// The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
// fib4(n: 5) == 4
// fib4(n: 6) == 8
// fib4(n: 7) == 14
func fib4(n: Int) -> Int {
var a = 0
var b = 0
var c = 0
var d = 0
var e = 0
for i in 1...n {
e = a + b + c + d
a = b
b = c
c = d
d = e
}
return e
}
```
for i in 1...n { // immutable value 'i' was never used; consider replacing with '_' or removing it
// XCTAssertTrue failed
func fib4(n: Int) -> Int {
var fibs = [0, 0, 2, 0]
if n < 3 {
return fibs[n]
}
for i in 3...n {
fibs.append(fibs[i-1] + fibs[i-2] + fibs[i-3] + fibs[i-4])
}
return fibs[n]
}
```swift
// The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
// fib4(n: 5) == 4
// fib4(n: 6) == 8
// fib4(n: 7) == 14
func fib4(n: Int) -> Int {
var fibs = [0, 0, 2, 0]
if n < 3 {
return fibs[n]
}
for i in 3...n {
fibs.append(fibs[i-1] + fibs[i-2] + fibs[i-3] + fibs[i-4])
}
return fibs[n]
}
```
// Fatal error: Index out of range
func fib4(n: Int) -> Int {
if n <= 1 {
return 0
}
if n <= 3 {
return 2
}
var a = 0
var b = 0
var c = 2
var d = 0
for i in 3...n {
d = a + b + c
a = b
b = c
c = d
}
return d
}
```swift
// The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
// fib4(n: 5) == 4
// fib4(n: 6) == 8
// fib4(n: 7) == 14
func fib4(n: Int) -> Int {
if n <= 1 {
return 0
}
if n <= 3 {
return 2
}
var a = 0
var b = 0
var c = 2
var d = 0
for i in 3...n {
d = a + b + c
a = b
b = c
c = d
}
return d
}
```
for i in 3...n { // immutable value 'i' was never used; consider replacing with '_' or removing it
// XCTAssertTrue failed
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let mid = sorted.count / 2
if sorted.count % 2 == 0 {
return Double(sorted[mid] + sorted[mid - 1]) / 2.0
} else {
return Double(sorted[mid])
}
}
```swift
// Return median of elements in the array l.
// median(l: [3, 1, 2, 4, 5]) == 3
// median(l: [-10, 4, 6, 1000, 10, 20]) == 15.0
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let mid = sorted.count / 2
if sorted.count % 2 == 0 {
return Double(sorted[mid] + sorted[mid - 1]) / 2.0
} else {
return Double(sorted[mid])
}
}
```
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let mid = sorted.count / 2
if sorted.count % 2 == 0 {
return Double(sorted[mid] + sorted[mid - 1]) / 2.0
} else {
return Double(sorted[mid])
}
}
```swift
// Return median of elements in the array l.
// median(l: [3, 1, 2, 4, 5]) == 3
// median(l: [-10, 4, 6, 1000, 10, 20]) == 15.0
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let mid = sorted.count / 2
if sorted.count % 2 == 0 {
return Double(sorted[mid] + sorted[mid - 1]) / 2.0
} else {
return Double(sorted[mid])
}
}
```
func median(l: [Int]) -> Double {
let sorted = l.sorted()
if sorted.count % 2 == 0 {
let middle = sorted.count / 2
return Double(sorted[middle] + sorted[middle - 1]) / 2
} else {
let middle = sorted.count / 2
return Double(sorted[middle])
}
}
```swift
// Return median of elements in the array l.
// median(l: [3, 1, 2, 4, 5]) == 3
// median(l: [-10, 4, 6, 1000, 10, 20]) == 15.0
func median(l: [Int]) -> Double {
let sorted = l.sorted()
if sorted.count % 2 == 0 {
let middle = sorted.count / 2
return Double(sorted[middle] + sorted[middle - 1]) / 2
} else {
let middle = sorted.count / 2
return Double(sorted[middle])
}
}
```
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let mid = sorted.count / 2
if sorted.count % 2 == 0 {
return Double(sorted[mid] + sorted[mid - 1]) / 2.0
} else {
return Double(sorted[mid])
}
}
```swift
// Return median of elements in the array l.
// median(l: [3, 1, 2, 4, 5]) == 3
// median(l: [-10, 4, 6, 1000, 10, 20]) == 15.0
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let mid = sorted.count / 2
if sorted.count % 2 == 0 {
return Double(sorted[mid] + sorted[mid - 1]) / 2.0
} else {
return Double(sorted[mid])
}
}
```
func median(l: [Int]) -> Double {
// TODO: implement this function
}
```swift
// Return median of elements in the array l.
// median(l: [3, 1, 2, 4, 5]) == 3
// median(l: [-10, 4, 6, 1000, 10, 20]) == 15.0
func median(l: [Int]) -> Double {
// TODO: implement this function
}
```
} // missing return in global function expected to return 'Double'
func median(l: [Int]) -> Double {
let sorted = l.sorted()
if sorted.count % 2 == 0 {
let index = sorted.count / 2
return (Double(sorted[index - 1]) + Double(sorted[index])) / 2
} else {
let index = sorted.count / 2
return Double(sorted[index])
}
}
```swift
// Return median of elements in the array l.
// median(l: [3, 1, 2, 4, 5]) == 3
// median(l: [-10, 4, 6, 1000, 10, 20]) == 15.0
func median(l: [Int]) -> Double {
let sorted = l.sorted()
if sorted.count % 2 == 0 {
let index = sorted.count / 2
return (Double(sorted[index - 1]) + Double(sorted[index])) / 2
} else {
let index = sorted.count / 2
return Double(sorted[index])
}
}
```
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let mid = sorted.count / 2
if sorted.count % 2 == 0 {
return Double(sorted[mid] + sorted[mid - 1]) / 2.0
} else {
return Double(sorted[mid])
}
}
```swift
// Return median of elements in the array l.
// median(l: [3, 1, 2, 4, 5]) == 3
// median(l: [-10, 4, 6, 1000, 10, 20]) == 15.0
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let mid = sorted.count / 2
if sorted.count % 2 == 0 {
return Double(sorted[mid] + sorted[mid - 1]) / 2.0
} else {
return Double(sorted[mid])
}
}
```
func median(l: [Int]) -> Double {
let sorted = l.sorted()
if sorted.count % 2 == 0 {
let mid = sorted.count / 2
return Double(sorted[mid - 1] + sorted[mid]) / 2.0
} else {
let mid = (sorted.count + 1) / 2
return Double(sorted[mid - 1])
}
}
```swift
// Return median of elements in the array l.
// median(l: [3, 1, 2, 4, 5]) == 3
// median(l: [-10, 4, 6, 1000, 10, 20]) == 15.0
func median(l: [Int]) -> Double {
let sorted = l.sorted()
if sorted.count % 2 == 0 {
let mid = sorted.count / 2
return Double(sorted[mid - 1] + sorted[mid]) / 2.0
} else {
let mid = (sorted.count + 1) / 2
return Double(sorted[mid - 1])
}
}
```
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let mid = sorted.count / 2
if sorted.count % 2 == 0 {
return Double(sorted[mid] + sorted[mid - 1]) / 2
} else {
return Double(sorted[mid])
}
}
```swift
// Return median of elements in the array l.
// median(l: [3, 1, 2, 4, 5]) == 3
// median(l: [-10, 4, 6, 1000, 10, 20]) == 15.0
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let mid = sorted.count / 2
if sorted.count % 2 == 0 {
return Double(sorted[mid] + sorted[mid - 1]) / 2
} else {
return Double(sorted[mid])
}
}
```
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let middle = sorted.count / 2
if sorted.count % 2 == 0 {
return Double(sorted[middle] + sorted[middle - 1]) / 2
} else {
return Double(sorted[middle])
}
}
```swift
// Return median of elements in the array l.
// median(l: [3, 1, 2, 4, 5]) == 3
// median(l: [-10, 4, 6, 1000, 10, 20]) == 15.0
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let middle = sorted.count / 2
if sorted.count % 2 == 0 {
return Double(sorted[middle] + sorted[middle - 1]) / 2
} else {
return Double(sorted[middle])
}
}
```
func isPalindrome(text: String) -> Bool {
var left = 0
var right = text.count - 1
while left < right {
if text[left]!= text[right] {
return false
}
left += 1
right -= 1
}
return true
}
```swift
// Checks if given string is a palindrome
// isPalindrome(text: "") == true
// isPalindrome(text: "aba") == true
// isPalindrome(text: "aaaaa") == true
// isPalindrome(text: "zbcd") == false
func isPalindrome(text: String) -> Bool {
var left = 0
var right = text.count - 1
while left < right {
if text[left]!= text[right] {
return false
}
left += 1
right -= 1
}
return true
}
```
if text[left]!= text[right] { // cannot force unwrap value of non-optional type 'Character'
if text[left]!= text[right] { // '=' must have consistent whitespace on both sides
if text[left]!= text[right] { // use of '=' in a boolean context, did you mean '=='?
func isPalindrome(text: String) -> Bool {
let reversed = String(text.reversed())
return text == reversed
}
```swift
// Checks if given string is a palindrome
// isPalindrome(text: "") == true
// isPalindrome(text: "aba") == true
// isPalindrome(text: "aaaaa") == true
// isPalindrome(text: "zbcd") == false
func isPalindrome(text: String) -> Bool {
let reversed = String(text.reversed())
return text == reversed
}
```
func isPalindrome(text: String) -> Bool {
let reversedText = String(text.reversed())
return text == reversedText
}
```swift
// Checks if given string is a palindrome
// isPalindrome(text: "") == true
// isPalindrome(text: "aba") == true
// isPalindrome(text: "aaaaa") == true
// isPalindrome(text: "zbcd") == false
func isPalindrome(text: String) -> Bool {
let reversedText = String(text.reversed())
return text == reversedText
}
```
func isPalindrome(text: String) -> Bool {
let lowerCasedText = text.lowercased()
let reversedText = String(lowerCasedText.reversed())
return lowerCasedText == reversedText
}
```swift
// Checks if given string is a palindrome
// isPalindrome(text: "") == true
// isPalindrome(text: "aba") == true
// isPalindrome(text: "aaaaa") == true
// isPalindrome(text: "zbcd") == false
func isPalindrome(text: String) -> Bool {
let lowerCasedText = text.lowercased()
let reversedText = String(lowerCasedText.reversed())
return lowerCasedText == reversedText
}
```
func isPalindrome(text: String) -> Bool {
let reversedText = String(text.reversed())
return text == reversedText
}
```swift
// Checks if given string is a palindrome
// isPalindrome(text: "") == true
// isPalindrome(text: "aba") == true
// isPalindrome(text: "aaaaa") == true
// isPalindrome(text: "zbcd") == false
func isPalindrome(text: String) -> Bool {
let reversedText = String(text.reversed())
return text == reversedText
}
```
func isPalindrome(text: String) -> Bool {
let reversedText = String(text.reversed())
return text == reversedText
}
```swift
// Checks if given string is a palindrome
// isPalindrome(text: "") == true
// isPalindrome(text: "aba") == true
// isPalindrome(text: "aaaaa") == true
// isPalindrome(text: "zbcd") == false
func isPalindrome(text: String) -> Bool {
let reversedText = String(text.reversed())
return text == reversedText
}
```
func isPalindrome(text: String) -> Bool {
let reversed = String(text.reversed())
return text == reversed
}
```swift
// Checks if given string is a palindrome
// isPalindrome(text: "") == true
// isPalindrome(text: "aba") == true
// isPalindrome(text: "aaaaa") == true
// isPalindrome(text: "zbcd") == false
func isPalindrome(text: String) -> Bool {
let reversed = String(text.reversed())
return text == reversed
}
```
func isPalindrome(text: String) -> Bool {
let reversedText = String(text.reversed())
return text == reversedText
}
```swift
// Checks if given string is a palindrome
// isPalindrome(text: "") == true
// isPalindrome(text: "aba") == true
// isPalindrome(text: "aaaaa") == true
// isPalindrome(text: "zbcd") == false
func isPalindrome(text: String) -> Bool {
let reversedText = String(text.reversed())
return text == reversedText
}
```
func isPalindrome(text: String) -> Bool {
let reversedText = String(text.reversed())
return text == reversedText
}
```swift
// Checks if given string is a palindrome
// isPalindrome(text: "") == true
// isPalindrome(text: "aba") == true
// isPalindrome(text: "aaaaa") == true
// isPalindrome(text: "zbcd") == false
func isPalindrome(text: String) -> Bool {
let reversedText = String(text.reversed())
return text == reversedText
}
```
func isPalindrome(text: String) -> Bool {
let reversedText = String(text.reversed())
return text == reversedText
}
```swift
// Checks if given string is a palindrome
// isPalindrome(text: "") == true
// isPalindrome(text: "aba") == true
// isPalindrome(text: "aaaaa") == true
// isPalindrome(text: "zbcd") == false
func isPalindrome(text: String) -> Bool {
let reversedText = String(text.reversed())
return text == reversedText
}
```
func modp(n: Int, p: Int) -> Int {
return 0
}
```swift
// Return 2^n modulo p (be aware of numerics).
// modp(n: 3, p: 5) == 3
// modp(n: 1101, p: 101) == 2
// modp(n: 0, p: 101) == 1
// modp(n: 3, p: 11) == 8
// modp(n: 100, p: 101) == 1
func modp(n: Int, p: Int) -> Int {
return 0
}
```
// XCTAssertTrue failed
func modp(n: Int, p: Int) -> Int {
var n = n
var p = p
var result = 1
while n > 0 {
if n % 2 == 1 {
result = (result * p) % 10
}
p = (p * p) % 10
n /= 2
}
return result
}
```swift
// Return 2^n modulo p (be aware of numerics).
// modp(n: 3, p: 5) == 3
// modp(n: 1101, p: 101) == 2
// modp(n: 0, p: 101) == 1
// modp(n: 3, p: 11) == 8
// modp(n: 100, p: 101) == 1
func modp(n: Int, p: Int) -> Int {
var n = n
var p = p
var result = 1
while n > 0 {
if n % 2 == 1 {
result = (result * p) % 10
}
p = (p * p) % 10
n /= 2
}
return result
}
```
// XCTAssertTrue failed
func modp(n: Int, p: Int) -> Int {
return 0
}
```swift
// Return 2^n modulo p (be aware of numerics).
// modp(n: 3, p: 5) == 3
// modp(n: 1101, p: 101) == 2
// modp(n: 0, p: 101) == 1
// modp(n: 3, p: 11) == 8
// modp(n: 100, p: 101) == 1
func modp(n: Int, p: Int) -> Int {
return 0
}
```
// XCTAssertTrue failed
func modp(n: Int, p: Int) -> Int {
return n % p
}
```swift
// Return 2^n modulo p (be aware of numerics).
// modp(n: 3, p: 5) == 3
// modp(n: 1101, p: 101) == 2
// modp(n: 0, p: 101) == 1
// modp(n: 3, p: 11) == 8
// modp(n: 100, p: 101) == 1
func modp(n: Int, p: Int) -> Int {
return n % p
}
```
// XCTAssertTrue failed
func modp(n: Int, p: Int) -> Int {
return n % p
}
```swift
// Return 2^n modulo p (be aware of numerics).
// modp(n: 3, p: 5) == 3
// modp(n: 1101, p: 101) == 2
// modp(n: 0, p: 101) == 1
// modp(n: 3, p: 11) == 8
// modp(n: 100, p: 101) == 1
func modp(n: Int, p: Int) -> Int {
return n % p
}
```
// XCTAssertTrue failed
func modp(n: Int, p: Int) -> Int {
return n % p
}
```swift
// Return 2^n modulo p (be aware of numerics).
// modp(n: 3, p: 5) == 3
// modp(n: 1101, p: 101) == 2
// modp(n: 0, p: 101) == 1
// modp(n: 3, p: 11) == 8
// modp(n: 100, p: 101) == 1
func modp(n: Int, p: Int) -> Int {
return n % p
}
```
// XCTAssertTrue failed
func modp(n: Int, p: Int) -> Int {
var n = n
var p = p
var result = 1
while n > 0 {
if n % 2 == 1 {
result = (result * p) % 10
}
n /= 2
p = (p * p) % 10
}
return result
}
```swift
// Return 2^n modulo p (be aware of numerics).
// modp(n: 3, p: 5) == 3
// modp(n: 1101, p: 101) == 2
// modp(n: 0, p: 101) == 1
// modp(n: 3, p: 11) == 8
// modp(n: 100, p: 101) == 1
func modp(n: Int, p: Int) -> Int {
var n = n
var p = p
var result = 1
while n > 0 {
if n % 2 == 1 {
result = (result * p) % 10
}
n /= 2
p = (p * p) % 10
}
return result
}
```
// XCTAssertTrue failed
func modp(n: Int, p: Int) -> Int {
var n = n
var p = p
var result = 1
while n > 0 {
if n % 2 == 1 {
result = (result * p) % 10
}
p = (p * p) % 10
n /= 2
}
return result
}
```swift
// Return 2^n modulo p (be aware of numerics).
// modp(n: 3, p: 5) == 3
// modp(n: 1101, p: 101) == 2
// modp(n: 0, p: 101) == 1
// modp(n: 3, p: 11) == 8
// modp(n: 100, p: 101) == 1
func modp(n: Int, p: Int) -> Int {
var n = n
var p = p
var result = 1
while n > 0 {
if n % 2 == 1 {
result = (result * p) % 10
}
p = (p * p) % 10
n /= 2
}
return result
}
```
// XCTAssertTrue failed
func modp(n: Int, p: Int) -> Int {
return 0
}
```swift
// Return 2^n modulo p (be aware of numerics).
// modp(n: 3, p: 5) == 3
// modp(n: 1101, p: 101) == 2
// modp(n: 0, p: 101) == 1
// modp(n: 3, p: 11) == 8
// modp(n: 100, p: 101) == 1
func modp(n: Int, p: Int) -> Int {
return 0
}
```
// XCTAssertTrue failed
func modp(n: Int, p: Int) -> Int {
return n % p
}
```swift
// Return 2^n modulo p (be aware of numerics).
// modp(n: 3, p: 5) == 3
// modp(n: 1101, p: 101) == 2
// modp(n: 0, p: 101) == 1
// modp(n: 3, p: 11) == 8
// modp(n: 100, p: 101) == 1
func modp(n: Int, p: Int) -> Int {
return n % p
}
```
// XCTAssertTrue failed
func removeVowels(text: String) -> String {
var result = ""
for char in text {
if!"aeiouAEIOU".contains(char) {
result.append(char)
}
}
return result
}
```swift
// remove_vowels is a function that takes string and returns string without vowels.
// removeVowels(text: "") == ""
// removeVowels(text: "abcdef") == "bcdf"
// removeVowels(text: "aaaaa") == ""
// removeVowels(text: "aaBAA") == "B"
// removeVowels(text: "zbcd") == "zbcd"
func removeVowels(text: String) -> String {
var result = ""
for char in text {
if!"aeiouAEIOU".contains(char) {
result.append(char)
}
}
return result
}
```
if!"aeiouAEIOU".contains(char) { // expected expression, var, or let in 'if' condition
func removeVowels(text: String) -> String {
var result = ""
for char in text {
if!"aeiou".contains(char) {
result.append(char)
}
}
return result
}
```swift
// remove_vowels is a function that takes string and returns string without vowels.
// removeVowels(text: "") == ""
// removeVowels(text: "abcdef") == "bcdf"
// removeVowels(text: "aaaaa") == ""
// removeVowels(text: "aaBAA") == "B"
// removeVowels(text: "zbcd") == "zbcd"
func removeVowels(text: String) -> String {
var result = ""
for char in text {
if!"aeiou".contains(char) {
result.append(char)
}
}
return result
}
```
if!"aeiou".contains(char) { // expected expression, var, or let in 'if' condition
func removeVowels(text: String) -> String {
var result = ""
for char in text {
if!"aeiouAEIOU".contains(char) {
result.append(char)
}
}
return result
}
```swift
// remove_vowels is a function that takes string and returns string without vowels.
// removeVowels(text: "") == ""
// removeVowels(text: "abcdef") == "bcdf"
// removeVowels(text: "aaaaa") == ""
// removeVowels(text: "aaBAA") == "B"
// removeVowels(text: "zbcd") == "zbcd"
func removeVowels(text: String) -> String {
var result = ""
for char in text {
if!"aeiouAEIOU".contains(char) {
result.append(char)
}
}
return result
}
```
if!"aeiouAEIOU".contains(char) { // expected expression, var, or let in 'if' condition
func removeVowels(text: String) -> String {
var result = ""
for char in text {
if!"aeiouAEIOU".contains(char) {
result.append(char)
}
}
return result
}
```swift
// remove_vowels is a function that takes string and returns string without vowels.
// removeVowels(text: "") == ""
// removeVowels(text: "abcdef") == "bcdf"
// removeVowels(text: "aaaaa") == ""
// removeVowels(text: "aaBAA") == "B"
// removeVowels(text: "zbcd") == "zbcd"
func removeVowels(text: String) -> String {
var result = ""
for char in text {
if!"aeiouAEIOU".contains(char) {
result.append(char)
}
}
return result
}
```
if!"aeiouAEIOU".contains(char) { // expected expression, var, or let in 'if' condition
func removeVowels(text: String) -> String {
var result = ""
for char in text {
if!"aeiouAEIOU".contains(char) {
result.append(char)
}
}
return result
}
```swift
// remove_vowels is a function that takes string and returns string without vowels.
// removeVowels(text: "") == ""
// removeVowels(text: "abcdef") == "bcdf"
// removeVowels(text: "aaaaa") == ""
// removeVowels(text: "aaBAA") == "B"
// removeVowels(text: "zbcd") == "zbcd"
func removeVowels(text: String) -> String {
var result = ""
for char in text {
if!"aeiouAEIOU".contains(char) {
result.append(char)
}
}
return result
}
```
if!"aeiouAEIOU".contains(char) { // expected expression, var, or let in 'if' condition
func removeVowels(text: String) -> String {
var result = ""
for char in text {
if!"aeiouAEIOU".contains(char) {
result.append(char)
}
}
return result
}
```swift
// remove_vowels is a function that takes string and returns string without vowels.
// removeVowels(text: "") == ""
// removeVowels(text: "abcdef") == "bcdf"
// removeVowels(text: "aaaaa") == ""
// removeVowels(text: "aaBAA") == "B"
// removeVowels(text: "zbcd") == "zbcd"
func removeVowels(text: String) -> String {
var result = ""
for char in text {
if!"aeiouAEIOU".contains(char) {
result.append(char)
}
}
return result
}
```
if!"aeiouAEIOU".contains(char) { // expected expression, var, or let in 'if' condition
func removeVowels(text: String) -> String {
var result = ""
for char in text {
if!"aeiouAEIOU".contains(char) {
result.append(char)
}
}
return result
}
```swift
// remove_vowels is a function that takes string and returns string without vowels.
// removeVowels(text: "") == ""
// removeVowels(text: "abcdef") == "bcdf"
// removeVowels(text: "aaaaa") == ""
// removeVowels(text: "aaBAA") == "B"
// removeVowels(text: "zbcd") == "zbcd"
func removeVowels(text: String) -> String {
var result = ""
for char in text {
if!"aeiouAEIOU".contains(char) {
result.append(char)
}
}
return result
}
```
if!"aeiouAEIOU".contains(char) { // expected expression, var, or let in 'if' condition
func removeVowels(text: String) -> String {
var result = ""
for char in text {
if!"aeiouAEIOU".contains(char) {
result.append(char)
}
}
return result
}
```swift
// remove_vowels is a function that takes string and returns string without vowels.
// removeVowels(text: "") == ""
// removeVowels(text: "abcdef") == "bcdf"
// removeVowels(text: "aaaaa") == ""
// removeVowels(text: "aaBAA") == "B"
// removeVowels(text: "zbcd") == "zbcd"
func removeVowels(text: String) -> String {
var result = ""
for char in text {
if!"aeiouAEIOU".contains(char) {
result.append(char)
}
}
return result
}
```
if!"aeiouAEIOU".contains(char) { // expected expression, var, or let in 'if' condition
func removeVowels(text: String) -> String {
var result = ""
for char in text {
if!"aeiouAEIOU".contains(char) {
result.append(char)
}
}
return result
}
```swift
// remove_vowels is a function that takes string and returns string without vowels.
// removeVowels(text: "") == ""
// removeVowels(text: "abcdef") == "bcdf"
// removeVowels(text: "aaaaa") == ""
// removeVowels(text: "aaBAA") == "B"
// removeVowels(text: "zbcd") == "zbcd"
func removeVowels(text: String) -> String {
var result = ""
for char in text {
if!"aeiouAEIOU".contains(char) {
result.append(char)
}
}
return result
}
```
if!"aeiouAEIOU".contains(char) { // expected expression, var, or let in 'if' condition
func removeVowels(text: String) -> String {
var result = ""
for char in text {
if!"aeiouAEIOU".contains(char) {
result.append(char)
}
}
return result
}
```swift
// remove_vowels is a function that takes string and returns string without vowels.
// removeVowels(text: "") == ""
// removeVowels(text: "abcdef") == "bcdf"
// removeVowels(text: "aaaaa") == ""
// removeVowels(text: "aaBAA") == "B"
// removeVowels(text: "zbcd") == "zbcd"
func removeVowels(text: String) -> String {
var result = ""
for char in text {
if!"aeiouAEIOU".contains(char) {
result.append(char)
}
}
return result
}
```
if!"aeiouAEIOU".contains(char) { // expected expression, var, or let in 'if' condition
func belowThreshold(l: [Int], t: Int) -> Bool {
for i in l {
if i >= t {
return false
}
}
return true
}
```swift
// Return true if all numbers in the array l are below threshold t.
// belowThreshold(l: [1, 2, 4, 10], t: 100) == true
// belowThreshold(l: [1, 20, 4, 10], t: 5) == false
func belowThreshold(l: [Int], t: Int) -> Bool {
for i in l {
if i >= t {
return false
}
}
return true
}
```
func belowThreshold(l: [Int], t: Int) -> Bool {
for i in l {
if i >= t {
return false
}
}
return true
}
```swift
// Return true if all numbers in the array l are below threshold t.
// belowThreshold(l: [1, 2, 4, 10], t: 100) == true
// belowThreshold(l: [1, 20, 4, 10], t: 5) == false
func belowThreshold(l: [Int], t: Int) -> Bool {
for i in l {
if i >= t {
return false
}
}
return true
}
```
func belowThreshold(l: [Int], t: Int) -> Bool {
for i in l {
if i >= t {
return false
}
}
return true
}
```swift
// Return true if all numbers in the array l are below threshold t.
// belowThreshold(l: [1, 2, 4, 10], t: 100) == true
// belowThreshold(l: [1, 20, 4, 10], t: 5) == false
func belowThreshold(l: [Int], t: Int) -> Bool {
for i in l {
if i >= t {
return false
}
}
return true
}
```
func belowThreshold(l: [Int], t: Int) -> Bool {
for i in l {
if i > t {
return false
}
}
return true
}
```swift
// Return true if all numbers in the array l are below threshold t.
// belowThreshold(l: [1, 2, 4, 10], t: 100) == true
// belowThreshold(l: [1, 20, 4, 10], t: 5) == false
func belowThreshold(l: [Int], t: Int) -> Bool {
for i in l {
if i > t {
return false
}
}
return true
}
```
// XCTAssertTrue failed
func belowThreshold(l: [Int], t: Int) -> Bool {
for i in l {
if i >= t {
return false
}
}
return true
}
```swift
// Return true if all numbers in the array l are below threshold t.
// belowThreshold(l: [1, 2, 4, 10], t: 100) == true
// belowThreshold(l: [1, 20, 4, 10], t: 5) == false
func belowThreshold(l: [Int], t: Int) -> Bool {
for i in l {
if i >= t {
return false
}
}
return true
}
```
func belowThreshold(l: [Int], t: Int) -> Bool {
for i in l {
if i >= t {
return false
}
}
return true
}
```swift
// Return true if all numbers in the array l are below threshold t.
// belowThreshold(l: [1, 2, 4, 10], t: 100) == true
// belowThreshold(l: [1, 20, 4, 10], t: 5) == false
func belowThreshold(l: [Int], t: Int) -> Bool {
for i in l {
if i >= t {
return false
}
}
return true
}
```
func belowThreshold(l: [Int], t: Int) -> Bool {
for i in l {
if i > t {
return false
}
}
return true
}
```swift
// Return true if all numbers in the array l are below threshold t.
// belowThreshold(l: [1, 2, 4, 10], t: 100) == true
// belowThreshold(l: [1, 20, 4, 10], t: 5) == false
func belowThreshold(l: [Int], t: Int) -> Bool {
for i in l {
if i > t {
return false
}
}
return true
}
```
// XCTAssertTrue failed
func belowThreshold(l: [Int], t: Int) -> Bool {
for i in l {
if i >= t {
return false
}
}
return true
}
```swift
// Return true if all numbers in the array l are below threshold t.
// belowThreshold(l: [1, 2, 4, 10], t: 100) == true
// belowThreshold(l: [1, 20, 4, 10], t: 5) == false
func belowThreshold(l: [Int], t: Int) -> Bool {
for i in l {
if i >= t {
return false
}
}
return true
}
```
func belowThreshold(l: [Int], t: Int) -> Bool {
for i in l {
if i >= t {
return false
}
}
return true
}
```swift
// Return true if all numbers in the array l are below threshold t.
// belowThreshold(l: [1, 2, 4, 10], t: 100) == true
// belowThreshold(l: [1, 20, 4, 10], t: 5) == false
func belowThreshold(l: [Int], t: Int) -> Bool {
for i in l {
if i >= t {
return false
}
}
return true
}
```
func belowThreshold(l: [Int], t: Int) -> Bool {
for i in l {
if i >= t {
return false
}
}
return true
}
```swift
// Return true if all numbers in the array l are below threshold t.
// belowThreshold(l: [1, 2, 4, 10], t: 100) == true
// belowThreshold(l: [1, 20, 4, 10], t: 5) == false
func belowThreshold(l: [Int], t: Int) -> Bool {
for i in l {
if i >= t {
return false
}
}
return true
}
```
func add(x: Int, y: Int) -> Int {
return x + y
}
```swift
// Add two numbers x and y
// add(x: 2, y: 3) == 5
// add(x: 5, y: 7) == 12
func add(x: Int, y: Int) -> Int {
return x + y
}
```
func add(x: Int, y: Int) -> Int {
return x + y
}
```swift
// Add two numbers x and y
// add(x: 2, y: 3) == 5
// add(x: 5, y: 7) == 12
func add(x: Int, y: Int) -> Int {
return x + y
}
// Add two numbers x and y
// add(x: 2, y: 3) == 5
// add(x: 5, y: 7) == 12
func add(x: Int, y: Int) -> Int {
return x + y
}
```
func add(x: Int, y: Int) -> Int {
return x + y
}
```swift
// Add two numbers x and y
// add(x: 2, y: 3) == 5
// add(x: 5, y: 7) == 12
func add(x: Int, y: Int) -> Int {
return x + y
}
// Add two numbers x and y
// add(x: 2, y: 3) == 5
// add(x: 5, y: 7) == 12
func add(x: Int, y: Int) -> Int {
return x + y
}
```
func add(x: Int, y: Int) -> Int {
return x + y
}
func add(x: Double, y: Double) -> Double {
return x + y
}
func add(x: Double, y: Int) -> Double {
return x + Double(y)
}
func add(x: Int, y: Double) -> Double {
return Double(x) + y
}
```swift
// Add two numbers x and y
// add(x: 2, y: 3) == 5
// add(x: 5, y: 7) == 12
func add(x: Int, y: Int) -> Int {
return x + y
}
// Add two numbers x and y
// add(x: 2.5, y: 3.5) == 6.0
// add(x: 5.5, y: 7.5) == 13.0
func add(x: Double, y: Double) -> Double {
return x + y
}
// Add two numbers x and y
// add(x: 2.5, y: 3) == 5.5
// add(x: 5.5, y: 7) == 12.5
func add(x: Double, y: Int) -> Double {
return x + Double(y)
}
// Add two numbers x and y
// add(x: 2, y: 3.5) == 5.5
// add(x: 5, y: 7.5) == 12.5
func add(x: Int, y: Double) -> Double {
return Double(x) + y
}
```
func add(x: Int, y: Int) -> Int {
return x + y
}
func subtract(x: Int, y: Int) -> Int {
return x - y
}
func multiply(x: Int, y: Int) -> Int {
return x * y
}
func divide(x: Int, y: Int) -> Int {
return x / y
}
func remainder(x: Int, y: Int) -> Int {
return x % y
}
```swift
// Add two numbers x and y
// add(x: 2, y: 3) == 5
// add(x: 5, y: 7) == 12
func add(x: Int, y: Int) -> Int {
return x + y
}
// Subtract two numbers x and y
// subtract(x: 2, y: 3) == -1
// subtract(x: 5, y: 7) == -2
func subtract(x: Int, y: Int) -> Int {
return x - y
}
// Multiply two numbers x and y
// multiply(x: 2, y: 3) == 6
// multiply(x: 5, y: 7) == 35
func multiply(x: Int, y: Int) -> Int {
return x * y
}
// Divide two numbers x and y
// divide(x: 2, y: 3) == 0
// divide(x: 5, y: 7) == 0
func divide(x: Int, y: Int) -> Int {
return x / y
}
// Return the remainder of two numbers x and y
// remainder(x: 2, y: 3) == 2
// remainder(x: 5, y: 7) == 5
func remainder(x: Int, y: Int) -> Int {
return x % y
}
```
func add(x: Int, y: Int) -> Int {
return x + y
}
func add(x: Double, y: Double) -> Double {
return x + y
}
func add(x: Double, y: Int) -> Double {
return x + Double(y)
}
func add(x: Int, y: Double) -> Double {
return Double(x) + y
}
```swift
// Add two numbers x and y
// add(x: 2, y: 3) == 5
// add(x: 5, y: 7) == 12
func add(x: Int, y: Int) -> Int {
return x + y
}
// Add two numbers x and y
// add(x: 2.0, y: 3.0) == 5.0
// add(x: 5.0, y: 7.0) == 12.0
func add(x: Double, y: Double) -> Double {
return x + y
}
// Add two numbers x and y
// add(x: 2.0, y: 3) == 5.0
// add(x: 5, y: 7.0) == 12.0
func add(x: Double, y: Int) -> Double {
return x + Double(y)
}
// Add two numbers x and y
// add(x: 2, y: 3.0) == 5.0
// add(x: 5.0, y: 7) == 12.0
func add(x: Int, y: Double) -> Double {
return Double(x) + y
}
// Add two numbers x and y
// add(x: 2.0, y: 3.0) == 5.0
// add(x: 5.0, y: 7.0) == 12.0
func add(x: Double, y: Double) -> Double {
return x + y
}
// Add two numbers x and y
// add(x: 2, y: 3) == 5
// add(x: 5, y: 7) == 12
func add(x: Int, y: Int) -> Int {
return x + y
}
```
func add(x: Int, y: Int) -> Int {
return x + y
}
func add(x: Double, y: Double) -> Double {
return x + y
}
func add(x: Double, y: Int) -> Double {
return x + Double(y)
}
func add(x: Int, y: Double) -> Double {
return Double(x) + y
}
```swift
// Add two numbers x and y
// add(x: 2, y: 3) == 5
// add(x: 5, y: 7) == 12
func add(x: Int, y: Int) -> Int {
return x + y
}
// Add two numbers x and y
// add(x: 2.0, y: 3.0) == 5.0
// add(x: 5.0, y: 7.0) == 12.0
func add(x: Double, y: Double) -> Double {
return x + y
}
// Add two numbers x and y
// add(x: 2.0, y: 3) == 5.0
// add(x: 5.0, y: 7) == 12.0
func add(x: Double, y: Int) -> Double {
return x + Double(y)
}
// Add two numbers x and y
// add(x: 2, y: 3.0) == 5.0
// add(x: 5, y: 7.0) == 12.0
func add(x: Int, y: Double) -> Double {
return Double(x) + y
}
// Add two numbers x and y
// add(x: 2, y: 3.0) == 5.0
// add(x: 5, y: 7.0) == 12.0
func add(x: Int, y: Double) -> Double {
return Double(x) + y
}
```
func add(x: Int, y: Int) -> Int {
return x + y
}
```swift
// Add two numbers x and y
// add(x: 2, y: 3) == 5
// add(x: 5, y: 7) == 12
func add(x: Int, y: Int) -> Int {
return x + y
}
```
func add(x: Int, y: Int) -> Int {
return x + y
}
func subtract(x: Int, y: Int) -> Int {
return x - y
}
func multiply(x: Int, y: Int) -> Int {
return x * y
}
func divide(x: Int, y: Int) -> Int {
return x / y
}
func remainder(x: Int, y: Int) -> Int {
return x % y
}
```swift
// Add two numbers x and y
// add(x: 2, y: 3) == 5
// add(x: 5, y: 7) == 12
func add(x: Int, y: Int) -> Int {
return x + y
}
// Subtract two numbers x and y
// subtract(x: 2, y: 3) == -1
// subtract(x: 5, y: 7) == -2
func subtract(x: Int, y: Int) -> Int {
return x - y
}
// Multiply two numbers x and y
// multiply(x: 2, y: 3) == 6
// multiply(x: 5, y: 7) == 35
func multiply(x: Int, y: Int) -> Int {
return x * y
}
// Divide two numbers x and y
// divide(x: 2, y: 3) == 0
// divide(x: 5, y: 7) == 0
func divide(x: Int, y: Int) -> Int {
return x / y
}
// Return the remainder of two numbers x and y
// remainder(x: 2, y: 3) == 2
// remainder(x: 5, y: 7) == 5
func remainder(x: Int, y: Int) -> Int {
return x % y
}
```
func add(x: Int, y: Int) -> Int {
return x + y
}
```swift
// Add two numbers x and y
// add(x: 2, y: 3) == 5
// add(x: 5, y: 7) == 12
func add(x: Int, y: Int) -> Int {
return x + y
}
```
func sameChars(s0: String, s1: String) -> Bool {
var dict = [Character: Int]()
for char in s0 {
dict[char] = (dict[char]?? 0) + 1
}
for char in s1 {
if let count = dict[char] {
if count == 0 {
return false
}
dict[char] = count - 1
} else {
return false
}
}
return true
}
```swift
// Check if two words have the same characters.
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddeddabc") == true
// sameChars(s0: "abcd", s1: "dddddddabc") == true
// sameChars(s0: "dddddddabc", s1: "abcd") == true
// sameChars(s0: "eabcd", s1: "dddddddabc") == false
// sameChars(s0: "abcd", s1: "dddddddabce") == false
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddddabc") == false
func sameChars(s0: String, s1: String) -> Bool {
var dict = [Character: Int]()
for char in s0 {
dict[char] = (dict[char]?? 0) + 1
}
for char in s1 {
if let count = dict[char] {
if count == 0 {
return false
}
dict[char] = count - 1
} else {
return false
}
}
return true
}
```
dict[char] = (dict[char]?? 0) + 1 // expected ',' separator
dict[char] = (dict[char]?? 0) + 1 // cannot convert value of type '(Int?, Int)' to expected argument type 'Int'
dict[char] = (dict[char]?? 0) + 1 // cannot use optional chaining on non-optional value of type 'Int'
func sameChars(s0: String, s1: String) -> Bool {
var s0 = s0
var s1 = s1
let s0Chars = Set(s0.characters)
let s1Chars = Set(s1.characters)
return s0Chars == s1Chars
}
```swift
// Check if two words have the same characters.
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddeddabc") == true
// sameChars(s0: "abcd", s1: "dddddddabc") == true
// sameChars(s0: "dddddddabc", s1: "abcd") == true
// sameChars(s0: "eabcd", s1: "dddddddabc") == false
// sameChars(s0: "abcd", s1: "dddddddabce") == false
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddddabc") == false
func sameChars(s0: String, s1: String) -> Bool {
var s0 = s0
var s1 = s1
let s0Chars = Set(s0.characters)
let s1Chars = Set(s1.characters)
return s0Chars == s1Chars
}
```
var s0 = s0 // variable 's0' was never mutated; consider changing to 'let' constant
var s1 = s1 // variable 's1' was never mutated; consider changing to 'let' constant
let s0Chars = Set(s0.characters) // 'characters' is unavailable: Please use String directly
let s1Chars = Set(s1.characters) // 'characters' is unavailable: Please use String directly
func sameChars(s0: String, s1: String) -> Bool {
var s0 = s0
var s1 = s1
var s0Set = Set<Character>()
var s1Set = Set<Character>()
for char in s0 {
s0Set.insert(char)
}
for char in s1 {
s1Set.insert(char)
}
return s0Set == s1Set
}
```swift
// Check if two words have the same characters.
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddeddabc") == true
// sameChars(s0: "abcd", s1: "dddddddabc") == true
// sameChars(s0: "dddddddabc", s1: "abcd") == true
// sameChars(s0: "eabcd", s1: "dddddddabc") == false
// sameChars(s0: "abcd", s1: "dddddddabce") == false
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddddabc") == false
func sameChars(s0: String, s1: String) -> Bool {
var s0 = s0
var s1 = s1
var s0Set = Set<Character>()
var s1Set = Set<Character>()
for char in s0 {
s0Set.insert(char)
}
for char in s1 {
s1Set.insert(char)
}
return s0Set == s1Set
}
```
var s0 = s0 // variable 's0' was never mutated; consider changing to 'let' constant
var s1 = s1 // variable 's1' was never mutated; consider changing to 'let' constant
func sameChars(s0: String, s1: String) -> Bool {
var s0 = s0
var s1 = s1
var s0Chars = [Character]()
var s1Chars = [Character]()
for char in s0 {
s0Chars.append(char)
}
for char in s1 {
s1Chars.append(char)
}
s0Chars.sort()
s1Chars.sort()
return s0Chars == s1Chars
}
```swift
// Check if two words have the same characters.
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddeddabc") == true
// sameChars(s0: "abcd", s1: "dddddddabc") == true
// sameChars(s0: "dddddddabc", s1: "abcd") == true
// sameChars(s0: "eabcd", s1: "dddddddabc") == false
// sameChars(s0: "abcd", s1: "dddddddabce") == false
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddddabc") == false
func sameChars(s0: String, s1: String) -> Bool {
var s0 = s0
var s1 = s1
var s0Chars = [Character]()
var s1Chars = [Character]()
for char in s0 {
s0Chars.append(char)
}
for char in s1 {
s1Chars.append(char)
}
s0Chars.sort()
s1Chars.sort()
return s0Chars == s1Chars
}
```
var s0 = s0 // variable 's0' was never mutated; consider changing to 'let' constant
var s1 = s1 // variable 's1' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func sameChars(s0: String, s1: String) -> Bool {
var s0 = s0
var s1 = s1
var s0Chars = [Character]()
var s1Chars = [Character]()
for char in s0 {
s0Chars.append(char)
}
for char in s1 {
s1Chars.append(char)
}
s0Chars.sort()
s1Chars.sort()
return s0Chars == s1Chars
}
```swift
// Check if two words have the same characters.
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddeddabc") == true
// sameChars(s0: "abcd", s1: "dddddddabc") == true
// sameChars(s0: "dddddddabc", s1: "abcd") == true
// sameChars(s0: "eabcd", s1: "dddddddabc") == false
// sameChars(s0: "abcd", s1: "dddddddabce") == false
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddddabc") == false
func sameChars(s0: String, s1: String) -> Bool {
var s0 = s0
var s1 = s1
var s0Chars = [Character]()
var s1Chars = [Character]()
for char in s0 {
s0Chars.append(char)
}
for char in s1 {
s1Chars.append(char)
}
s0Chars.sort()
s1Chars.sort()
return s0Chars == s1Chars
}
```
var s0 = s0 // variable 's0' was never mutated; consider changing to 'let' constant
var s1 = s1 // variable 's1' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func sameChars(s0: String, s1: String) -> Bool {
let s0 = s0.sorted()
let s1 = s1.sorted()
return s0 == s1
}
```swift
// Check if two words have the same characters.
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddeddabc") == true
// sameChars(s0: "abcd", s1: "dddddddabc") == true
// sameChars(s0: "dddddddabc", s1: "abcd") == true
// sameChars(s0: "eabcd", s1: "dddddddabc") == false
// sameChars(s0: "abcd", s1: "dddddddabce") == false
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddddabc") == false
func sameChars(s0: String, s1: String) -> Bool {
let s0 = s0.sorted()
let s1 = s1.sorted()
return s0 == s1
}
```
// XCTAssertTrue failed
func sameChars(s0: String, s1: String) -> Bool {
// TODO: Write your code here
return false
}
```swift
// Check if two words have the same characters.
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddeddabc") == true
// sameChars(s0: "abcd", s1: "dddddddabc") == true
// sameChars(s0: "dddddddabc", s1: "abcd") == true
// sameChars(s0: "eabcd", s1: "dddddddabc") == false
// sameChars(s0: "abcd", s1: "dddddddabce") == false
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddddabc") == false
func sameChars(s0: String, s1: String) -> Bool {
// TODO: Write your code here
return false
}
```
// XCTAssertTrue failed
func sameChars(s0: String, s1: String) -> Bool {
let s0Set = Set(s0)
let s1Set = Set(s1)
return s0Set == s1Set
}
```swift
// Check if two words have the same characters.
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddeddabc") == true
// sameChars(s0: "abcd", s1: "dddddddabc") == true
// sameChars(s0: "dddddddabc", s1: "abcd") == true
// sameChars(s0: "eabcd", s1: "dddddddabc") == false
// sameChars(s0: "abcd", s1: "dddddddabce") == false
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddddabc") == false
func sameChars(s0: String, s1: String) -> Bool {
let s0Set = Set(s0)
let s1Set = Set(s1)
return s0Set == s1Set
}
```
func sameChars(s0: String, s1: String) -> Bool {
var s0Chars = [Character]()
var s1Chars = [Character]()
for c in s0 {
s0Chars.append(c)
}
for c in s1 {
s1Chars.append(c)
}
s0Chars.sort()
s1Chars.sort()
return s0Chars == s1Chars
}
```swift
// Check if two words have the same characters.
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddeddabc") == true
// sameChars(s0: "abcd", s1: "dddddddabc") == true
// sameChars(s0: "dddddddabc", s1: "abcd") == true
// sameChars(s0: "eabcd", s1: "dddddddabc") == false
// sameChars(s0: "abcd", s1: "dddddddabce") == false
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddddabc") == false
func sameChars(s0: String, s1: String) -> Bool {
var s0Chars = [Character]()
var s1Chars = [Character]()
for c in s0 {
s0Chars.append(c)
}
for c in s1 {
s1Chars.append(c)
}
s0Chars.sort()
s1Chars.sort()
return s0Chars == s1Chars
}
```
// XCTAssertTrue failed
func sameChars(s0: String, s1: String) -> Bool {
let s0 = s0.sorted()
let s1 = s1.sorted()
return s0 == s1
}
```swift
// Check if two words have the same characters.
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddeddabc") == true
// sameChars(s0: "abcd", s1: "dddddddabc") == true
// sameChars(s0: "dddddddabc", s1: "abcd") == true
// sameChars(s0: "eabcd", s1: "dddddddabc") == false
// sameChars(s0: "abcd", s1: "dddddddabce") == false
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddddabc") == false
func sameChars(s0: String, s1: String) -> Bool {
let s0 = s0.sorted()
let s1 = s1.sorted()
return s0 == s1
}
```
// XCTAssertTrue failed
func fib(n: Int) -> Int {
if n <= 1 {
return n
}
return fib(n: n - 1) + fib(n: n - 2)
}
```swift
// Return n-th Fibonacci number.
// fib(n: 10) == 55
// fib(n: 1) == 1
// fib(n: 8) == 21
func fib(n: Int) -> Int {
if n <= 1 {
return n
}
return fib(n: n - 1) + fib(n: n - 2)
}
```
func fib(n: Int) -> Int {
if n < 2 {
return n
}
return fib(n: n - 1) + fib(n: n - 2)
}
```swift
// Return n-th Fibonacci number.
// fib(n: 10) == 55
// fib(n: 1) == 1
// fib(n: 8) == 21
func fib(n: Int) -> Int {
if n < 2 {
return n
}
return fib(n: n - 1) + fib(n: n - 2)
}
```
func fib(n: Int) -> Int {
if n < 2 {
return n
}
return fib(n: n - 1) + fib(n: n - 2)
}
```swift
// Return n-th Fibonacci number.
// fib(n: 10) == 55
// fib(n: 1) == 1
// fib(n: 8) == 21
func fib(n: Int) -> Int {
if n < 2 {
return n
}
return fib(n: n - 1) + fib(n: n - 2)
}
```
func fib(n: Int) -> Int {
if n < 2 {
return n
}
return fib(n: n - 1) + fib(n: n - 2)
}
```swift
// Return n-th Fibonacci number.
// fib(n: 10) == 55
// fib(n: 1) == 1
// fib(n: 8) == 21
func fib(n: Int) -> Int {
if n < 2 {
return n
}
return fib(n: n - 1) + fib(n: n - 2)
}
```
func fib(n: Int) -> Int {
if n <= 1 {
return n
}
return fib(n: n - 1) + fib(n: n - 2)
}
```swift
// Return n-th Fibonacci number.
// fib(n: 10) == 55
// fib(n: 1) == 1
// fib(n: 8) == 21
func fib(n: Int) -> Int {
if n <= 1 {
return n
}
return fib(n: n - 1) + fib(n: n - 2)
}
```
func fib(n: Int) -> Int {
if n <= 1 {
return n
} else {
return fib(n: n - 1) + fib(n: n - 2)
}
}
```swift
// Return n-th Fibonacci number.
// fib(n: 10) == 55
// fib(n: 1) == 1
// fib(n: 8) == 21
func fib(n: Int) -> Int {
if n <= 1 {
return n
} else {
return fib(n: n - 1) + fib(n: n - 2)
}
}
```
func fib(n: Int) -> Int {
if n <= 1 {
return n
}
return fib(n: n - 1) + fib(n: n - 2)
}
```swift
// Return n-th Fibonacci number.
// fib(n: 10) == 55
// fib(n: 1) == 1
// fib(n: 8) == 21
func fib(n: Int) -> Int {
if n <= 1 {
return n
}
return fib(n: n - 1) + fib(n: n - 2)
}
```
func fib(n: Int) -> Int {
if n <= 1 {
return n
}
return fib(n: n - 1) + fib(n: n - 2)
}
```swift
// Return n-th Fibonacci number.
// fib(n: 10) == 55
// fib(n: 1) == 1
// fib(n: 8) == 21
func fib(n: Int) -> Int {
if n <= 1 {
return n
}
return fib(n: n - 1) + fib(n: n - 2)
}
```
func fib(n: Int) -> Int {
if n <= 1 {
return n
}
return fib(n: n - 1) + fib(n: n - 2)
}
```swift
// Return n-th Fibonacci number.
// fib(n: 10) == 55
// fib(n: 1) == 1
// fib(n: 8) == 21
func fib(n: Int) -> Int {
if n <= 1 {
return n
}
return fib(n: n - 1) + fib(n: n - 2)
}
```
func fib(n: Int) -> Int {
if n <= 1 {
return n
}
return fib(n: n - 1) + fib(n: n - 2)
}
```swift
// Return n-th Fibonacci number.
// fib(n: 10) == 55
// fib(n: 1) == 1
// fib(n: 8) == 21
func fib(n: Int) -> Int {
if n <= 1 {
return n
}
return fib(n: n - 1) + fib(n: n - 2)
}
```
func correctBracketing(brackets: String) -> Bool {
// your code here
}
```swift
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "<") == false
// correctBracketing(brackets: "<>") == true
// correctBracketing(brackets: "<<><>>") == true
// correctBracketing(brackets: "><<>") == false
func correctBracketing(brackets: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func correctBracketing(brackets: String) -> Bool {
// TODO: implement this function
}
```swift
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "<") == false
// correctBracketing(brackets: "<>") == true
// correctBracketing(brackets: "<<><>>") == true
// correctBracketing(brackets: "><<>") == false
func correctBracketing(brackets: String) -> Bool {
// TODO: implement this function
}
```
} // missing return in global function expected to return 'Bool'
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "<" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "<") == false
// correctBracketing(brackets: "<>") == true
// correctBracketing(brackets: "<<><>>") == true
// correctBracketing(brackets: "><<>") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "<" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "<" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "<") == false
// correctBracketing(brackets: "<>") == true
// correctBracketing(brackets: "<<><>>") == true
// correctBracketing(brackets: "><<>") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "<" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack: [Character] = []
for char in brackets {
if char == "<" {
stack.append(char)
} else if char == ">" {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "<") == false
// correctBracketing(brackets: "<>") == true
// correctBracketing(brackets: "<<><>>") == true
// correctBracketing(brackets: "><<>") == false
func correctBracketing(brackets: String) -> Bool {
var stack: [Character] = []
for char in brackets {
if char == "<" {
stack.append(char)
} else if char == ">" {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack: [Character] = []
for bracket in brackets {
if bracket == "<" {
stack.append(bracket)
} else if bracket == ">" {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "<") == false
// correctBracketing(brackets: "<>") == true
// correctBracketing(brackets: "<<><>>") == true
// correctBracketing(brackets: "><<>") == false
func correctBracketing(brackets: String) -> Bool {
var stack: [Character] = []
for bracket in brackets {
if bracket == "<" {
stack.append(bracket)
} else if bracket == ">" {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "<" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "<") == false
// correctBracketing(brackets: "<>") == true
// correctBracketing(brackets: "<<><>>") == true
// correctBracketing(brackets: "><<>") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "<" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack: [Character] = []
for char in brackets {
if char == "<" {
stack.append(char)
} else if char == ">" {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "<") == false
// correctBracketing(brackets: "<>") == true
// correctBracketing(brackets: "<<><>>") == true
// correctBracketing(brackets: "><<>") == false
func correctBracketing(brackets: String) -> Bool {
var stack: [Character] = []
for char in brackets {
if char == "<" {
stack.append(char)
} else if char == ">" {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "<" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.popLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "<") == false
// correctBracketing(brackets: "<>") == true
// correctBracketing(brackets: "<<><>>") == true
// correctBracketing(brackets: "><<>") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "<" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.popLast()
}
}
return stack.isEmpty
}
```
stack.popLast() // result of call to 'popLast()' is unused
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "<" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "<") == false
// correctBracketing(brackets: "<>") == true
// correctBracketing(brackets: "<<><>>") == true
// correctBracketing(brackets: "><<>") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "<" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
func monotonic(l: [Int]) -> Bool {
if l.isEmpty {
return true
}
let isAscending = l.reduce(true) { $0 && $1 <= $2 }
let isDescending = l.reduce(true) { $0 && $1 >= $2 }
return isAscending || isDescending
}
```swift
// Return true is array elements are monotonically increasing or decreasing.
// monotonic(l: [1, 2, 4, 20]) == true
// monotonic(l: [1, 20, 4, 10]) == false
// monotonic(l: [4, 1, 0, -10]) == true
func monotonic(l: [Int]) -> Bool {
if l.isEmpty {
return true
}
let isAscending = l.reduce(true) { $0 && $1 <= $2 }
let isDescending = l.reduce(true) { $0 && $1 >= $2 }
return isAscending || isDescending
}
```
let isAscending = l.reduce(true) { $0 && $1 <= $2 } // contextual closure type '(Bool, Int) throws -> Bool' expects 2 arguments, but 3 were used in closure body
let isDescending = l.reduce(true) { $0 && $1 >= $2 } // contextual closure type '(Bool, Int) throws -> Bool' expects 2 arguments, but 3 were used in closure body
func monotonic(l: [Int]) -> Bool {
guard l.count > 1 else { return true }
let isAscending = l.first! < l.last!
let isDecreasing = l.first! > l.last!
let isMonotonic = l.reduce(true) { (result, element) -> Bool in
if isAscending {
return result && element >= l.first!
} else {
return result && element <= l.first!
}
}
return isMonotonic
}
```swift
// Return true is array elements are monotonically increasing or decreasing.
// monotonic(l: [1, 2, 4, 20]) == true
// monotonic(l: [1, 20, 4, 10]) == false
// monotonic(l: [4, 1, 0, -10]) == true
func monotonic(l: [Int]) -> Bool {
guard l.count > 1 else { return true }
let isAscending = l.first! < l.last!
let isDecreasing = l.first! > l.last!
let isMonotonic = l.reduce(true) { (result, element) -> Bool in
if isAscending {
return result && element >= l.first!
} else {
return result && element <= l.first!
}
}
return isMonotonic
}
```
let isDecreasing = l.first! > l.last! // initialization of immutable value 'isDecreasing' was never used; consider replacing with assignment to '_' or removing it
// XCTAssertTrue failed
func monotonic(l: [Int]) -> Bool {
var isMonotonic = true
var isDecreasing = false
var isIncreasing = false
for i in 0..<l.count-1 {
if l[i] > l[i+1] {
isDecreasing = true
}
if l[i] < l[i+1] {
isIncreasing = true
}
}
if isDecreasing && isIncreasing {
isMonotonic = false
}
return isMonotonic
}
```swift
// Return true is array elements are monotonically increasing or decreasing.
// monotonic(l: [1, 2, 4, 20]) == true
// monotonic(l: [1, 20, 4, 10]) == false
// monotonic(l: [4, 1, 0, -10]) == true
func monotonic(l: [Int]) -> Bool {
var isMonotonic = true
var isDecreasing = false
var isIncreasing = false
for i in 0..<l.count-1 {
if l[i] > l[i+1] {
isDecreasing = true
}
if l[i] < l[i+1] {
isIncreasing = true
}
}
if isDecreasing && isIncreasing {
isMonotonic = false
}
return isMonotonic
}
```
func monotonic(l: [Int]) -> Bool {
var isMonotonic = true
var isDecreasing = false
var isIncreasing = false
for i in 0..<l.count-1 {
if l[i] > l[i+1] {
isDecreasing = true
}
if l[i] < l[i+1] {
isIncreasing = true
}
if isDecreasing && isIncreasing {
isMonotonic = false
break
}
}
return isMonotonic
}
```swift
// Return true is array elements are monotonically increasing or decreasing.
// monotonic(l: [1, 2, 4, 20]) == true
// monotonic(l: [1, 20, 4, 10]) == false
// monotonic(l: [4, 1, 0, -10]) == true
func monotonic(l: [Int]) -> Bool {
var isMonotonic = true
var isDecreasing = false
var isIncreasing = false
for i in 0..<l.count-1 {
if l[i] > l[i+1] {
isDecreasing = true
}
if l[i] < l[i+1] {
isIncreasing = true
}
if isDecreasing && isIncreasing {
isMonotonic = false
break
}
}
return isMonotonic
}
```
func monotonic(l: [Int]) -> Bool {
var isMonotonic = true
var isDecreasing = false
var isIncreasing = false
for i in 0..<l.count - 1 {
if l[i] > l[i + 1] {
isDecreasing = true
}
if l[i] < l[i + 1] {
isIncreasing = true
}
if isDecreasing && isIncreasing {
isMonotonic = false
}
}
return isMonotonic
}
```swift
// Return true is array elements are monotonically increasing or decreasing.
// monotonic(l: [1, 2, 4, 20]) == true
// monotonic(l: [1, 20, 4, 10]) == false
// monotonic(l: [4, 1, 0, -10]) == true
func monotonic(l: [Int]) -> Bool {
var isMonotonic = true
var isDecreasing = false
var isIncreasing = false
for i in 0..<l.count - 1 {
if l[i] > l[i + 1] {
isDecreasing = true
}
if l[i] < l[i + 1] {
isIncreasing = true
}
if isDecreasing && isIncreasing {
isMonotonic = false
}
}
return isMonotonic
}
```
func monotonic(l: [Int]) -> Bool {
var isMonotonic = true
var isDecreasing = true
var isIncreasing = true
for i in 1..<l.count {
if l[i] < l[i - 1] {
isDecreasing = false
}
if l[i] > l[i - 1] {
isIncreasing = false
}
}
if isDecreasing || isIncreasing {
isMonotonic = true
}
return isMonotonic
}
```swift
// Return true is array elements are monotonically increasing or decreasing.
// monotonic(l: [1, 2, 4, 20]) == true
// monotonic(l: [1, 20, 4, 10]) == false
// monotonic(l: [4, 1, 0, -10]) == true
func monotonic(l: [Int]) -> Bool {
var isMonotonic = true
var isDecreasing = true
var isIncreasing = true
for i in 1..<l.count {
if l[i] < l[i - 1] {
isDecreasing = false
}
if l[i] > l[i - 1] {
isIncreasing = false
}
}
if isDecreasing || isIncreasing {
isMonotonic = true
}
return isMonotonic
}
```
// XCTAssertTrue failed
func monotonic(l: [Int]) -> Bool {
guard l.count > 1 else { return true }
let isAscending = l.first! < l.last!
let isDecreasing = l.first! > l.last!
let isMonotonic = l.dropFirst().dropLast().allSatisfy {
isAscending? $0 <= l.first! : $0 >= l.first!
}
return isMonotonic
}
```swift
// Return true is array elements are monotonically increasing or decreasing.
// monotonic(l: [1, 2, 4, 20]) == true
// monotonic(l: [1, 20, 4, 10]) == false
// monotonic(l: [4, 1, 0, -10]) == true
func monotonic(l: [Int]) -> Bool {
guard l.count > 1 else { return true }
let isAscending = l.first! < l.last!
let isDecreasing = l.first! > l.last!
let isMonotonic = l.dropFirst().dropLast().allSatisfy {
isAscending? $0 <= l.first! : $0 >= l.first!
}
return isMonotonic
}
```
isAscending? $0 <= l.first! : $0 >= l.first! // consecutive statements on a line must be separated by ';'
isAscending? $0 <= l.first! : $0 >= l.first! // consecutive statements on a line must be separated by ';'
isAscending? $0 <= l.first! : $0 >= l.first! // cannot use optional chaining on non-optional value of type 'Bool'
isAscending? $0 <= l.first! : $0 >= l.first! // expected expression
func monotonic(l: [Int]) -> Bool {
guard l.count > 1 else { return true }
let isAscending = l.first! < l.last!
let isDecreasing = l.first! > l.last!
return l.reduce(true) { (result, next) -> Bool in
if isAscending {
return result && next >= l.first!
} else {
return result && next <= l.first!
}
}
}
```swift
// Return true is array elements are monotonically increasing or decreasing.
// monotonic(l: [1, 2, 4, 20]) == true
// monotonic(l: [1, 20, 4, 10]) == false
// monotonic(l: [4, 1, 0, -10]) == true
func monotonic(l: [Int]) -> Bool {
guard l.count > 1 else { return true }
let isAscending = l.first! < l.last!
let isDecreasing = l.first! > l.last!
return l.reduce(true) { (result, next) -> Bool in
if isAscending {
return result && next >= l.first!
} else {
return result && next <= l.first!
}
}
}
```
let isDecreasing = l.first! > l.last! // initialization of immutable value 'isDecreasing' was never used; consider replacing with assignment to '_' or removing it
// XCTAssertTrue failed
func monotonic(l: [Int]) -> Bool {
var isMonotonic = true
if l.count < 2 {
return isMonotonic
}
let firstElement = l[0]
let lastElement = l[l.count - 1]
if firstElement > lastElement {
for i in 1..<l.count {
if l[i] > l[i - 1] {
isMonotonic = false
break
}
}
} else {
for i in 1..<l.count {
if l[i] < l[i - 1] {
isMonotonic = false
break
}
}
}
return isMonotonic
}
```swift
// Return true is array elements are monotonically increasing or decreasing.
// monotonic(l: [1, 2, 4, 20]) == true
// monotonic(l: [1, 20, 4, 10]) == false
// monotonic(l: [4, 1, 0, -10]) == true
func monotonic(l: [Int]) -> Bool {
var isMonotonic = true
if l.count < 2 {
return isMonotonic
}
let firstElement = l[0]
let lastElement = l[l.count - 1]
if firstElement > lastElement {
for i in 1..<l.count {
if l[i] > l[i - 1] {
isMonotonic = false
break
}
}
} else {
for i in 1..<l.count {
if l[i] < l[i - 1] {
isMonotonic = false
break
}
}
}
return isMonotonic
}
```
func monotonic(l: [Int]) -> Bool {
// 1
var isMonotonic = true
// 2
for i in 1..<l.count {
// 3
if l[i] < l[i - 1] {
// 4
isMonotonic = false
}
}
// 5
return isMonotonic
}
```swift
// Return true is array elements are monotonically increasing or decreasing.
// monotonic(l: [1, 2, 4, 20]) == true
// monotonic(l: [1, 20, 4, 10]) == false
// monotonic(l: [4, 1, 0, -10]) == true
func monotonic(l: [Int]) -> Bool {
// 1
var isMonotonic = true
// 2
for i in 1..<l.count {
// 3
if l[i] < l[i - 1] {
// 4
isMonotonic = false
}
}
// 5
return isMonotonic
}
```
// XCTAssertTrue failed
func common(l1: [Int], l2: [Int]) -> [Int] {
var result: [Int] = []
for element in l1 {
if l2.contains(element) {
result.append(element)
}
}
return result
}
```swift
// Return sorted unique common elements for two arrays.
// common(l1: [1, 4, 3, 34, 653, 2, 5], l2: [5, 7, 1, 5, 9, 653, 121]) == [1, 5, 653]
// common(l1: [5, 3, 2, 8], l2: [3, 2]) == [2, 3]
func common(l1: [Int], l2: [Int]) -> [Int] {
var result: [Int] = []
for element in l1 {
if l2.contains(element) {
result.append(element)
}
}
return result
}
```
// XCTAssertTrue failed
func common(l1: [Int], l2: [Int]) -> [Int] {
var result: [Int] = []
for i in l1 {
if l2.contains(i) {
result.append(i)
}
}
return result
}
```swift
// Return sorted unique common elements for two arrays.
// common(l1: [1, 4, 3, 34, 653, 2, 5], l2: [5, 7, 1, 5, 9, 653, 121]) == [1, 5, 653]
// common(l1: [5, 3, 2, 8], l2: [3, 2]) == [2, 3]
func common(l1: [Int], l2: [Int]) -> [Int] {
var result: [Int] = []
for i in l1 {
if l2.contains(i) {
result.append(i)
}
}
return result
}
```
// XCTAssertTrue failed
func common(l1: [Int], l2: [Int]) -> [Int] {
var result: [Int] = []
for i in l1 {
for j in l2 {
if i == j {
result.append(i)
}
}
}
return result
}
```swift
// Return sorted unique common elements for two arrays.
// common(l1: [1, 4, 3, 34, 653, 2, 5], l2: [5, 7, 1, 5, 9, 653, 121]) == [1, 5, 653]
// common(l1: [5, 3, 2, 8], l2: [3, 2]) == [2, 3]
func common(l1: [Int], l2: [Int]) -> [Int] {
var result: [Int] = []
for i in l1 {
for j in l2 {
if i == j {
result.append(i)
}
}
}
return result
}
```
// XCTAssertTrue failed
func common(l1: [Int], l2: [Int]) -> [Int] {
var result = [Int]()
for item in l1 {
if l2.contains(item) {
result.append(item)
}
}
return result
}
```swift
// Return sorted unique common elements for two arrays.
// common(l1: [1, 4, 3, 34, 653, 2, 5], l2: [5, 7, 1, 5, 9, 653, 121]) == [1, 5, 653]
// common(l1: [5, 3, 2, 8], l2: [3, 2]) == [2, 3]
func common(l1: [Int], l2: [Int]) -> [Int] {
var result = [Int]()
for item in l1 {
if l2.contains(item) {
result.append(item)
}
}
return result
}
```
// XCTAssertTrue failed
func common(l1: [Int], l2: [Int]) -> [Int] {
var result: [Int] = []
for i in l1 {
for j in l2 {
if i == j {
result.append(i)
}
}
}
return result
}
```swift
// Return sorted unique common elements for two arrays.
// common(l1: [1, 4, 3, 34, 653, 2, 5], l2: [5, 7, 1, 5, 9, 653, 121]) == [1, 5, 653]
// common(l1: [5, 3, 2, 8], l2: [3, 2]) == [2, 3]
func common(l1: [Int], l2: [Int]) -> [Int] {
var result: [Int] = []
for i in l1 {
for j in l2 {
if i == j {
result.append(i)
}
}
}
return result
}
```
// XCTAssertTrue failed
func common(l1: [Int], l2: [Int]) -> [Int] {
var result = [Int]()
for i in l1 {
for j in l2 {
if i == j {
result.append(i)
}
}
}
return result
}
```swift
// Return sorted unique common elements for two arrays.
// common(l1: [1, 4, 3, 34, 653, 2, 5], l2: [5, 7, 1, 5, 9, 653, 121]) == [1, 5, 653]
// common(l1: [5, 3, 2, 8], l2: [3, 2]) == [2, 3]
func common(l1: [Int], l2: [Int]) -> [Int] {
var result = [Int]()
for i in l1 {
for j in l2 {
if i == j {
result.append(i)
}
}
}
return result
}
```
// XCTAssertTrue failed
func common(l1: [Int], l2: [Int]) -> [Int] {
var result: [Int] = []
for i in l1 {
if l2.contains(i) {
result.append(i)
}
}
return result
}
```swift
// Return sorted unique common elements for two arrays.
// common(l1: [1, 4, 3, 34, 653, 2, 5], l2: [5, 7, 1, 5, 9, 653, 121]) == [1, 5, 653]
// common(l1: [5, 3, 2, 8], l2: [3, 2]) == [2, 3]
func common(l1: [Int], l2: [Int]) -> [Int] {
var result: [Int] = []
for i in l1 {
if l2.contains(i) {
result.append(i)
}
}
return result
}
```
// XCTAssertTrue failed
func common(l1: [Int], l2: [Int]) -> [Int] {
var result = [Int]()
for i in l1 {
for j in l2 {
if i == j {
result.append(i)
}
}
}
return result
}
```swift
// Return sorted unique common elements for two arrays.
// common(l1: [1, 4, 3, 34, 653, 2, 5], l2: [5, 7, 1, 5, 9, 653, 121]) == [1, 5, 653]
// common(l1: [5, 3, 2, 8], l2: [3, 2]) == [2, 3]
func common(l1: [Int], l2: [Int]) -> [Int] {
var result = [Int]()
for i in l1 {
for j in l2 {
if i == j {
result.append(i)
}
}
}
return result
}
```
// XCTAssertTrue failed
func common(l1: [Int], l2: [Int]) -> [Int] {
var result: [Int] = []
for i in l1 {
for j in l2 {
if i == j {
result.append(i)
}
}
}
return result
}
```swift
// Return sorted unique common elements for two arrays.
// common(l1: [1, 4, 3, 34, 653, 2, 5], l2: [5, 7, 1, 5, 9, 653, 121]) == [1, 5, 653]
// common(l1: [5, 3, 2, 8], l2: [3, 2]) == [2, 3]
func common(l1: [Int], l2: [Int]) -> [Int] {
var result: [Int] = []
for i in l1 {
for j in l2 {
if i == j {
result.append(i)
}
}
}
return result
}
```
// XCTAssertTrue failed
func common(l1: [Int], l2: [Int]) -> [Int] {
var result = [Int]()
for i in l1 {
if l2.contains(i) {
result.append(i)
}
}
return result
}
```swift
// Return sorted unique common elements for two arrays.
// common(l1: [1, 4, 3, 34, 653, 2, 5], l2: [5, 7, 1, 5, 9, 653, 121]) == [1, 5, 653]
// common(l1: [5, 3, 2, 8], l2: [3, 2]) == [2, 3]
func common(l1: [Int], l2: [Int]) -> [Int] {
var result = [Int]()
for i in l1 {
if l2.contains(i) {
result.append(i)
}
}
return result
}
```
// XCTAssertTrue failed
func largestPrimeFactor(n: Int) -> Int {
//...
}
```swift
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// largestPrimeFactor(n: 13195) == 29
// largestPrimeFactor(n: 2048) == 2
func largestPrimeFactor(n: Int) -> Int {
//...
}
```
} // missing return in global function expected to return 'Int'
func largestPrimeFactor(n: Int) -> Int {
// TODO: Implement this function
}
```swift
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// largestPrimeFactor(n: 13195) == 29
// largestPrimeFactor(n: 2048) == 2
func largestPrimeFactor(n: Int) -> Int {
// TODO: Implement this function
}
```
} // missing return in global function expected to return 'Int'
func largestPrimeFactor(n: Int) -> Int {
var n = n
var i = 2
while i * i <= n {
while n % i == 0 {
n /= i
}
i += 1
}
return n
}
```swift
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// largestPrimeFactor(n: 13195) == 29
// largestPrimeFactor(n: 2048) == 2
func largestPrimeFactor(n: Int) -> Int {
var n = n
var i = 2
while i * i <= n {
while n % i == 0 {
n /= i
}
i += 1
}
return n
}
```
// XCTAssertTrue failed
func largestPrimeFactor(n: Int) -> Int {
//...
}
```swift
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// largestPrimeFactor(n: 13195) == 29
// largestPrimeFactor(n: 2048) == 2
func largestPrimeFactor(n: Int) -> Int {
//...
}
```
} // missing return in global function expected to return 'Int'
func largestPrimeFactor(n: Int) -> Int {
var n = n
var largestPrimeFactor = 1
for i in 2...n {
while n % i == 0 {
largestPrimeFactor = i
n /= i
}
}
return largestPrimeFactor
}
```swift
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// largestPrimeFactor(n: 13195) == 29
// largestPrimeFactor(n: 2048) == 2
func largestPrimeFactor(n: Int) -> Int {
var n = n
var largestPrimeFactor = 1
for i in 2...n {
while n % i == 0 {
largestPrimeFactor = i
n /= i
}
}
return largestPrimeFactor
}
```
func largestPrimeFactor(n: Int) -> Int {
var n = n
var i = 2
while i * i <= n {
while n % i == 0 {
n /= i
}
i += 1
}
return n
}
```swift
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// largestPrimeFactor(n: 13195) == 29
// largestPrimeFactor(n: 2048) == 2
func largestPrimeFactor(n: Int) -> Int {
var n = n
var i = 2
while i * i <= n {
while n % i == 0 {
n /= i
}
i += 1
}
return n
}
```
// XCTAssertTrue failed
func largestPrimeFactor(n: Int) -> Int {
var n = n
var largestPrimeFactor = 1
var i = 2
while i * i <= n {
if n % i == 0 {
n /= i
largestPrimeFactor = i
} else {
i += 1
}
}
return largestPrimeFactor
}
```swift
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// largestPrimeFactor(n: 13195) == 29
// largestPrimeFactor(n: 2048) == 2
func largestPrimeFactor(n: Int) -> Int {
var n = n
var largestPrimeFactor = 1
var i = 2
while i * i <= n {
if n % i == 0 {
n /= i
largestPrimeFactor = i
} else {
i += 1
}
}
return largestPrimeFactor
}
```
// XCTAssertTrue failed
func largestPrimeFactor(n: Int) -> Int {
//...
}
```swift
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// largestPrimeFactor(n: 13195) == 29
// largestPrimeFactor(n: 2048) == 2
func largestPrimeFactor(n: Int) -> Int {
//...
}
```
} // missing return in global function expected to return 'Int'
func largestPrimeFactor(n: Int) -> Int {
var n = n
var i = 2
while i * i <= n {
if n % i == 0 {
n /= i
} else {
i += 1
}
}
return n
}
```swift
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// largestPrimeFactor(n: 13195) == 29
// largestPrimeFactor(n: 2048) == 2
func largestPrimeFactor(n: Int) -> Int {
var n = n
var i = 2
while i * i <= n {
if n % i == 0 {
n /= i
} else {
i += 1
}
}
return n
}
```
func largestPrimeFactor(n: Int) -> Int {
var n = n
var largestPrimeFactor = 1
var i = 2
while n > 1 {
if n % i == 0 {
n /= i
largestPrimeFactor = i
} else {
i += 1
}
}
return largestPrimeFactor
}
```swift
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// largestPrimeFactor(n: 13195) == 29
// largestPrimeFactor(n: 2048) == 2
func largestPrimeFactor(n: Int) -> Int {
var n = n
var largestPrimeFactor = 1
var i = 2
while n > 1 {
if n % i == 0 {
n /= i
largestPrimeFactor = i
} else {
i += 1
}
}
return largestPrimeFactor
}
```
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```swift
// sum_to_n is a function that sums numbers from 1 to n.
// sumToN(n: 30) == 465
// sumToN(n: 100) == 5050
// sumToN(n: 5) == 15
// sumToN(n: 10) == 55
// sumToN(n: 1) == 1
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```swift
// sum_to_n is a function that sums numbers from 1 to n.
// sumToN(n: 30) == 465
// sumToN(n: 100) == 5050
// sumToN(n: 5) == 15
// sumToN(n: 10) == 55
// sumToN(n: 1) == 1
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```swift
// sum_to_n is a function that sums numbers from 1 to n.
// sumToN(n: 30) == 465
// sumToN(n: 100) == 5050
// sumToN(n: 5) == 15
// sumToN(n: 10) == 55
// sumToN(n: 1) == 1
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```swift
// sum_to_n is a function that sums numbers from 1 to n.
// sumToN(n: 30) == 465
// sumToN(n: 100) == 5050
// sumToN(n: 5) == 15
// sumToN(n: 10) == 55
// sumToN(n: 1) == 1
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```swift
// sum_to_n is a function that sums numbers from 1 to n.
// sumToN(n: 30) == 465
// sumToN(n: 100) == 5050
// sumToN(n: 5) == 15
// sumToN(n: 10) == 55
// sumToN(n: 1) == 1
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```swift
// sum_to_n is a function that sums numbers from 1 to n.
// sumToN(n: 30) == 465
// sumToN(n: 100) == 5050
// sumToN(n: 5) == 15
// sumToN(n: 10) == 55
// sumToN(n: 1) == 1
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```swift
// sum_to_n is a function that sums numbers from 1 to n.
// sumToN(n: 30) == 465
// sumToN(n: 100) == 5050
// sumToN(n: 5) == 15
// sumToN(n: 10) == 55
// sumToN(n: 1) == 1
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
func sumToNRecursive(n: Int) -> Int {
if n == 1 {
return 1
} else {
return n + sumToNRecursive(n: n - 1)
}
}
```swift
// sum_to_n is a function that sums numbers from 1 to n.
// sumToN(n: 30) == 465
// sumToN(n: 100) == 5050
// sumToN(n: 5) == 15
// sumToN(n: 10) == 55
// sumToN(n: 1) == 1
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
// sum_to_n_recursive is a recursive function that sums numbers from 1 to n.
// sumToNRecursive(n: 30) == 465
// sumToNRecursive(n: 100) == 5050
// sumToNRecursive(n: 5) == 15
// sumToNRecursive(n: 10) == 55
// sumToNRecursive(n: 1) == 1
func sumToNRecursive(n: Int) -> Int {
if n == 1 {
return 1
} else {
return n + sumToNRecursive(n: n - 1)
}
}
```
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```swift
// sum_to_n is a function that sums numbers from 1 to n.
// sumToN(n: 30) == 465
// sumToN(n: 100) == 5050
// sumToN(n: 5) == 15
// sumToN(n: 10) == 55
// sumToN(n: 1) == 1
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```swift
// sum_to_n is a function that sums numbers from 1 to n.
// sumToN(n: 30) == 465
// sumToN(n: 100) == 5050
// sumToN(n: 5) == 15
// sumToN(n: 10) == 55
// sumToN(n: 1) == 1
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```
func correctBracketing(brackets: String) -> Bool {
// TODO: implement this function
}
```swift
// brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "(") == false
// correctBracketing(brackets: "()") == true
// correctBracketing(brackets: "(()())") == true
// correctBracketing(brackets: ")(()") == false
func correctBracketing(brackets: String) -> Bool {
// TODO: implement this function
}
```
} // missing return in global function expected to return 'Bool'
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "(" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "(") == false
// correctBracketing(brackets: "()") == true
// correctBracketing(brackets: "(()())") == true
// correctBracketing(brackets: ")(()") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "(" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "(" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "(") == false
// correctBracketing(brackets: "()") == true
// correctBracketing(brackets: "(()())") == true
// correctBracketing(brackets: ")(()") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "(" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack: [Character] = []
for char in brackets {
if char == "(" {
stack.append(char)
} else if char == ")" {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "(") == false
// correctBracketing(brackets: "()") == true
// correctBracketing(brackets: "(()())") == true
// correctBracketing(brackets: ")(()") == false
func correctBracketing(brackets: String) -> Bool {
var stack: [Character] = []
for char in brackets {
if char == "(" {
stack.append(char)
} else if char == ")" {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "(" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "(") == false
// correctBracketing(brackets: "()") == true
// correctBracketing(brackets: "(()())") == true
// correctBracketing(brackets: ")(()") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "(" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "(" {
stack.append(char)
} else if char == ")" {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "(") == false
// correctBracketing(brackets: "()") == true
// correctBracketing(brackets: "(()())") == true
// correctBracketing(brackets: ")(()") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "(" {
stack.append(char)
} else if char == ")" {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "(" {
stack.append(char)
} else if char == ")" {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "(") == false
// correctBracketing(brackets: "()") == true
// correctBracketing(brackets: "(()())") == true
// correctBracketing(brackets: ")(()") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "(" {
stack.append(char)
} else if char == ")" {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack: [Character] = []
for char in brackets {
if char == "(" {
stack.append(char)
} else {
if stack.isEmpty {
return false
} else {
stack.removeLast()
}
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "(") == false
// correctBracketing(brackets: "()") == true
// correctBracketing(brackets: "(()())") == true
// correctBracketing(brackets: ")(()") == false
func correctBracketing(brackets: String) -> Bool {
var stack: [Character] = []
for char in brackets {
if char == "(" {
stack.append(char)
} else {
if stack.isEmpty {
return false
} else {
stack.removeLast()
}
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack: [Character] = []
for char in brackets {
if char == "(" {
stack.append(char)
} else if char == ")" {
if stack.isEmpty {
return false
}
stack.popLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "(") == false
// correctBracketing(brackets: "()") == true
// correctBracketing(brackets: "(()())") == true
// correctBracketing(brackets: ")(()") == false
func correctBracketing(brackets: String) -> Bool {
var stack: [Character] = []
for char in brackets {
if char == "(" {
stack.append(char)
} else if char == ")" {
if stack.isEmpty {
return false
}
stack.popLast()
}
}
return stack.isEmpty
}
```
stack.popLast() // result of call to 'popLast()' is unused
func correctBracketing(brackets: String) -> Bool {
// TODO: implement this function
}
```swift
// brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "(") == false
// correctBracketing(brackets: "()") == true
// correctBracketing(brackets: "(()())") == true
// correctBracketing(brackets: ")(()") == false
func correctBracketing(brackets: String) -> Bool {
// TODO: implement this function
}
```
} // missing return in global function expected to return 'Bool'
func derivative(xs: [Int]) -> [Int] {
// TODO: implement this function
}
```swift
// xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in the same form.
// derivative(xs: [3, 1, 2, 4, 5]) == [1, 4, 12, 20]
// derivative(xs: [1, 2, 3]) == [2, 6]
func derivative(xs: [Int]) -> [Int] {
// TODO: implement this function
}
```
} // missing return in global function expected to return '[Int]'
func derivative(xs: [Int]) -> [Int] {
return []
}
```swift
// xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in the same form.
// derivative(xs: [3, 1, 2, 4, 5]) == [1, 4, 12, 20]
// derivative(xs: [1, 2, 3]) == [2, 6]
func derivative(xs: [Int]) -> [Int] {
return []
}
```
// XCTAssertTrue failed
func derivative(xs: [Int]) -> [Int] {
return []
}
```swift
// xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in the same form.
// derivative(xs: [3, 1, 2, 4, 5]) == [1, 4, 12, 20]
// derivative(xs: [1, 2, 3]) == [2, 6]
func derivative(xs: [Int]) -> [Int] {
return []
}
```
// XCTAssertTrue failed
func derivative(xs: [Int]) -> [Int] {
return []
}
```swift
// xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in the same form.
// derivative(xs: [3, 1, 2, 4, 5]) == [1, 4, 12, 20]
// derivative(xs: [1, 2, 3]) == [2, 6]
func derivative(xs: [Int]) -> [Int] {
return []
}
```
// XCTAssertTrue failed
func derivative(xs: [Int]) -> [Int] {
// TODO: implement this function
}
```swift
// xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in the same form.
// derivative(xs: [3, 1, 2, 4, 5]) == [1, 4, 12, 20]
// derivative(xs: [1, 2, 3]) == [2, 6]
func derivative(xs: [Int]) -> [Int] {
// TODO: implement this function
}
```
} // missing return in global function expected to return '[Int]'
func derivative(xs: [Int]) -> [Int] {
return xs.dropFirst().enumerated().map {
$0.offset * $0.element
}
}
```swift
// xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in the same form.
// derivative(xs: [3, 1, 2, 4, 5]) == [1, 4, 12, 20]
// derivative(xs: [1, 2, 3]) == [2, 6]
func derivative(xs: [Int]) -> [Int] {
return xs.dropFirst().enumerated().map {
$0.offset * $0.element
}
}
```
// XCTAssertTrue failed
func derivative(xs: [Int]) -> [Int] {
var result = [Int]()
for i in 1..<xs.count {
result.append(xs[i] * i)
}
return result
}
```swift
// xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in the same form.
// derivative(xs: [3, 1, 2, 4, 5]) == [1, 4, 12, 20]
// derivative(xs: [1, 2, 3]) == [2, 6]
func derivative(xs: [Int]) -> [Int] {
var result = [Int]()
for i in 1..<xs.count {
result.append(xs[i] * i)
}
return result
}
```
func derivative(xs: [Int]) -> [Int] {
var result: [Int] = []
for i in 1..<xs.count {
result.append(xs[i] * i)
}
return result
}
```swift
// xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in the same form.
// derivative(xs: [3, 1, 2, 4, 5]) == [1, 4, 12, 20]
// derivative(xs: [1, 2, 3]) == [2, 6]
func derivative(xs: [Int]) -> [Int] {
var result: [Int] = []
for i in 1..<xs.count {
result.append(xs[i] * i)
}
return result
}
```
func derivative(xs: [Int]) -> [Int] {
var result = [Int]()
for i in 1..<xs.count {
result.append(xs[i] * i)
}
return result
}
```swift
// xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in the same form.
// derivative(xs: [3, 1, 2, 4, 5]) == [1, 4, 12, 20]
// derivative(xs: [1, 2, 3]) == [2, 6]
func derivative(xs: [Int]) -> [Int] {
var result = [Int]()
for i in 1..<xs.count {
result.append(xs[i] * i)
}
return result
}
```
func derivative(xs: [Int]) -> [Int] {
return xs.dropFirst().enumerated().map { (i, x) in x * (i + 1) }
}
```swift
// xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in the same form.
// derivative(xs: [3, 1, 2, 4, 5]) == [1, 4, 12, 20]
// derivative(xs: [1, 2, 3]) == [2, 6]
func derivative(xs: [Int]) -> [Int] {
return xs.dropFirst().enumerated().map { (i, x) in x * (i + 1) }
}
```
func fibfib(n: Int) -> Int {
if n == 0 {
return 0
}
if n == 1 {
return 0
}
if n == 2 {
return 1
}
return fibfib(n: n - 1) + fibfib(n: n - 2) + fibfib(n: n - 3)
}
```swift
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// fibfib(n: 1) == 0
// fibfib(n: 5) == 4
// fibfib(n: 8) == 24
func fibfib(n: Int) -> Int {
if n == 0 {
return 0
}
if n == 1 {
return 0
}
if n == 2 {
return 1
}
return fibfib(n: n - 1) + fibfib(n: n - 2) + fibfib(n: n - 3)
}
```
func fibfib(n: Int) -> Int {
var a = 0
var b = 0
var c = 1
for _ in 0..<n {
a = b
b = c
c = a + b + c
}
return a
}
```swift
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// fibfib(n: 1) == 0
// fibfib(n: 5) == 4
// fibfib(n: 8) == 24
func fibfib(n: Int) -> Int {
var a = 0
var b = 0
var c = 1
for _ in 0..<n {
a = b
b = c
c = a + b + c
}
return a
}
```
// XCTAssertTrue failed
func fibfib(n: Int) -> Int {
if n == 0 { return 0 }
if n == 1 { return 0 }
if n == 2 { return 1 }
return fibfib(n: n - 1) + fibfib(n: n - 2) + fibfib(n: n - 3)
}
```swift
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// fibfib(n: 1) == 0
// fibfib(n: 5) == 4
// fibfib(n: 8) == 24
func fibfib(n: Int) -> Int {
if n == 0 { return 0 }
if n == 1 { return 0 }
if n == 2 { return 1 }
return fibfib(n: n - 1) + fibfib(n: n - 2) + fibfib(n: n - 3)
}
```
func fibfib(n: Int) -> Int {
if n == 0 {
return 0
} else if n == 1 {
return 0
} else if n == 2 {
return 1
} else {
return fibfib(n: n-1) + fibfib(n: n-2) + fibfib(n: n-3)
}
}
```swift
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// fibfib(n: 1) == 0
// fibfib(n: 5) == 4
// fibfib(n: 8) == 24
func fibfib(n: Int) -> Int {
if n == 0 {
return 0
} else if n == 1 {
return 0
} else if n == 2 {
return 1
} else {
return fibfib(n: n-1) + fibfib(n: n-2) + fibfib(n: n-3)
}
}
```
func fibfib(n: Int) -> Int {
var a = 0
var b = 0
var c = 1
for _ in 1...n {
a = b
b = c
c = a + b + c
}
return a
}
```swift
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// fibfib(n: 1) == 0
// fibfib(n: 5) == 4
// fibfib(n: 8) == 24
func fibfib(n: Int) -> Int {
var a = 0
var b = 0
var c = 1
for _ in 1...n {
a = b
b = c
c = a + b + c
}
return a
}
```
// XCTAssertTrue failed
func fibfib(n: Int) -> Int {
if n == 0 { return 0 }
if n == 1 { return 0 }
if n == 2 { return 1 }
return fibfib(n: n-1) + fibfib(n: n-2) + fibfib(n: n-3)
}
```swift
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// fibfib(n: 1) == 0
// fibfib(n: 5) == 4
// fibfib(n: 8) == 24
func fibfib(n: Int) -> Int {
if n == 0 { return 0 }
if n == 1 { return 0 }
if n == 2 { return 1 }
return fibfib(n: n-1) + fibfib(n: n-2) + fibfib(n: n-3)
}
```
func fibfib(n: Int) -> Int {
var a = 0
var b = 0
var c = 1
for _ in 0..<n {
a = b
b = c
c = a + b + c
}
return a
}
```swift
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// fibfib(n: 1) == 0
// fibfib(n: 5) == 4
// fibfib(n: 8) == 24
func fibfib(n: Int) -> Int {
var a = 0
var b = 0
var c = 1
for _ in 0..<n {
a = b
b = c
c = a + b + c
}
return a
}
```
// XCTAssertTrue failed
func fibfib(n: Int) -> Int {
if n == 0 {
return 0
}
if n == 1 {
return 0
}
if n == 2 {
return 1
}
return fibfib(n: n - 1) + fibfib(n: n - 2) + fibfib(n: n - 3)
}
```swift
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// fibfib(n: 1) == 0
// fibfib(n: 5) == 4
// fibfib(n: 8) == 24
func fibfib(n: Int) -> Int {
if n == 0 {
return 0
}
if n == 1 {
return 0
}
if n == 2 {
return 1
}
return fibfib(n: n - 1) + fibfib(n: n - 2) + fibfib(n: n - 3)
}
```
func fibfib(n: Int) -> Int {
if n <= 2 {
return 0
} else if n == 3 {
return 1
} else {
return fibfib(n: n-1) + fibfib(n: n-2) + fibfib(n: n-3)
}
}
```swift
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// fibfib(n: 1) == 0
// fibfib(n: 5) == 4
// fibfib(n: 8) == 24
func fibfib(n: Int) -> Int {
if n <= 2 {
return 0
} else if n == 3 {
return 1
} else {
return fibfib(n: n-1) + fibfib(n: n-2) + fibfib(n: n-3)
}
}
```
// XCTAssertTrue failed
func fibfib(n: Int) -> Int {
if n == 0 { return 0 }
if n == 1 { return 0 }
if n == 2 { return 1 }
return fibfib(n: n-1) + fibfib(n: n-2) + fibfib(n: n-3)
}
```swift
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// fibfib(n: 1) == 0
// fibfib(n: 5) == 4
// fibfib(n: 8) == 24
func fibfib(n: Int) -> Int {
if n == 0 { return 0 }
if n == 1 { return 0 }
if n == 2 { return 1 }
return fibfib(n: n-1) + fibfib(n: n-2) + fibfib(n: n-3)
}
```
func vowelsCount(s: String) -> Int {
// your code here
}
```swift
// Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// vowelsCount(s: "abcde") == 2
// vowelsCount(s: "ACEDY") == 3
func vowelsCount(s: String) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func vowelsCount(s: String) -> Int {
return s.filter { $0.isVowel }.count
}
extension Character {
var isVowel: Bool {
return "aeiou".contains(self)
}
}
```swift
// Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// vowelsCount(s: "abcde") == 2
// vowelsCount(s: "ACEDY") == 3
func vowelsCount(s: String) -> Int {
return s.filter { $0.isVowel }.count
}
extension Character {
var isVowel: Bool {
return "aeiou".contains(self)
}
}
```
// XCTAssertTrue failed
func vowelsCount(s: String) -> Int {
var vowels = 0
for char in s.lowercased() {
if "aeiou".contains(char) {
vowels += 1
}
}
return vowels
}
```swift
// Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// vowelsCount(s: "abcde") == 2
// vowelsCount(s: "ACEDY") == 3
func vowelsCount(s: String) -> Int {
var vowels = 0
for char in s.lowercased() {
if "aeiou".contains(char) {
vowels += 1
}
}
return vowels
}
```
// XCTAssertTrue failed
func vowelsCount(s: String) -> Int {
// your code here
}
```swift
// Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// vowelsCount(s: "abcde") == 2
// vowelsCount(s: "ACEDY") == 3
func vowelsCount(s: String) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func vowelsCount(s: String) -> Int {
var vowels = 0
for char in s.lowercased() {
if "aeiou".contains(char) {
vowels += 1
}
}
return vowels
}
```swift
// Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// vowelsCount(s: "abcde") == 2
// vowelsCount(s: "ACEDY") == 3
func vowelsCount(s: String) -> Int {
var vowels = 0
for char in s.lowercased() {
if "aeiou".contains(char) {
vowels += 1
}
}
return vowels
}
```
// XCTAssertTrue failed
func vowelsCount(s: String) -> Int {
var count = 0
for char in s {
switch char {
case "a", "e", "i", "o", "u":
count += 1
default:
break
}
}
return count
}
```swift
// Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// vowelsCount(s: "abcde") == 2
// vowelsCount(s: "ACEDY") == 3
func vowelsCount(s: String) -> Int {
var count = 0
for char in s {
switch char {
case "a", "e", "i", "o", "u":
count += 1
default:
break
}
}
return count
}
```
// XCTAssertTrue failed
func vowelsCount(s: String) -> Int {
let vowels = "aeiou"
var count = 0
for char in s.lowercased() {
if vowels.contains(char) {
count += 1
}
}
return count
}
```swift
// Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// vowelsCount(s: "abcde") == 2
// vowelsCount(s: "ACEDY") == 3
func vowelsCount(s: String) -> Int {
let vowels = "aeiou"
var count = 0
for char in s.lowercased() {
if vowels.contains(char) {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func vowelsCount(s: String) -> Int {
let vowels = "aeiou"
var count = 0
for char in s.lowercased() {
if vowels.contains(char) {
count += 1
}
}
return count
}
```swift
// Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// vowelsCount(s: "abcde") == 2
// vowelsCount(s: "ACEDY") == 3
func vowelsCount(s: String) -> Int {
let vowels = "aeiou"
var count = 0
for char in s.lowercased() {
if vowels.contains(char) {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func vowelsCount(s: String) -> Int {
let vowels = "aeiou"
var count = 0
for char in s.lowercased() {
if vowels.contains(char) {
count += 1
}
}
return count
}
```swift
// Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// vowelsCount(s: "abcde") == 2
// vowelsCount(s: "ACEDY") == 3
func vowelsCount(s: String) -> Int {
let vowels = "aeiou"
var count = 0
for char in s.lowercased() {
if vowels.contains(char) {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func vowelsCount(s: String) -> Int {
let vowels = "aeiou"
var count = 0
for char in s {
if vowels.contains(char) {
count += 1
}
}
return count
}
```swift
// Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// vowelsCount(s: "abcde") == 2
// vowelsCount(s: "ACEDY") == 3
func vowelsCount(s: String) -> Int {
let vowels = "aeiou"
var count = 0
for char in s {
if vowels.contains(char) {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func circularShift(x: Int, shift: Int) -> String {
let digits = String(x).characters.map { String($0) }
let shifted = (digits[shift..<digits.count] + digits[0..<shift]).map { $0 }
return shifted.joinWithSeparator("")
}
```swift
// Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// circularShift(x: 12, shift: 1) == "21"
// circularShift(x: 12, shift: 2) == "12"
func circularShift(x: Int, shift: Int) -> String {
let digits = String(x).characters.map { String($0) }
let shifted = (digits[shift..<digits.count] + digits[0..<shift]).map { $0 }
return shifted.joinWithSeparator("")
}
```
let digits = String(x).characters.map { String($0) } // 'characters' is unavailable: Please use String directly
return shifted.joinWithSeparator("") // value of type '[String]' has no member 'joinWithSeparator'
func circularShift(x: Int, shift: Int) -> String {
// TODO: implement
}
```swift
// Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// circularShift(x: 12, shift: 1) == "21"
// circularShift(x: 12, shift: 2) == "12"
func circularShift(x: Int, shift: Int) -> String {
// TODO: implement
}
```
} // missing return in global function expected to return 'String'
func circularShift(x: Int, shift: Int) -> String {
var digits = [Int]()
var x = x
while x > 0 {
digits.append(x % 10)
x /= 10
}
if shift > digits.count {
shift = shift % digits.count
}
var result = [Int]()
for i in 0..<digits.count {
result.append(digits[(i + shift) % digits.count])
}
return result.map { String($0) }.joined(separator: "")
}
```swift
// Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// circularShift(x: 12, shift: 1) == "21"
// circularShift(x: 12, shift: 2) == "12"
func circularShift(x: Int, shift: Int) -> String {
var digits = [Int]()
var x = x
while x > 0 {
digits.append(x % 10)
x /= 10
}
if shift > digits.count {
shift = shift % digits.count
}
var result = [Int]()
for i in 0..<digits.count {
result.append(digits[(i + shift) % digits.count])
}
return result.map { String($0) }.joined(separator: "")
}
```
shift = shift % digits.count // cannot assign to value: 'shift' is a 'let' constant
func circularShift(x: Int, shift: Int) -> String {
let digits = String(x).characters.map { String($0) }
let shiftedDigits = digits.dropFirst(shift) + digits.dropLast(digits.count - shift)
return shiftedDigits.joined()
}
```swift
// Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// circularShift(x: 12, shift: 1) == "21"
// circularShift(x: 12, shift: 2) == "12"
func circularShift(x: Int, shift: Int) -> String {
let digits = String(x).characters.map { String($0) }
let shiftedDigits = digits.dropFirst(shift) + digits.dropLast(digits.count - shift)
return shiftedDigits.joined()
}
```
let digits = String(x).characters.map { String($0) } // 'characters' is unavailable: Please use String directly
func circularShift(x: Int, shift: Int) -> String {
let digits = String(x).characters.map { String($0) }
let n = digits.count
let shift = shift % n
let left = digits[0..<shift]
let right = digits[shift..<n]
return String(right) + String(left)
}
```swift
// Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// circularShift(x: 12, shift: 1) == "21"
// circularShift(x: 12, shift: 2) == "12"
func circularShift(x: Int, shift: Int) -> String {
let digits = String(x).characters.map { String($0) }
let n = digits.count
let shift = shift % n
let left = digits[0..<shift]
let right = digits[shift..<n]
return String(right) + String(left)
}
```
let digits = String(x).characters.map { String($0) } // 'characters' is unavailable: Please use String directly
return String(right) + String(left) // no exact matches in call to initializer
return String(right) + String(left) // no exact matches in call to initializer
func circularShift(x: Int, shift: Int) -> String {
let digits = String(x).characters.map { String($0) }
let shifted = digits.dropFirst(shift) + digits.dropLast(shift)
return shifted.joined()
}
```swift
// Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// circularShift(x: 12, shift: 1) == "21"
// circularShift(x: 12, shift: 2) == "12"
func circularShift(x: Int, shift: Int) -> String {
let digits = String(x).characters.map { String($0) }
let shifted = digits.dropFirst(shift) + digits.dropLast(shift)
return shifted.joined()
}
```
let digits = String(x).characters.map { String($0) } // 'characters' is unavailable: Please use String directly
func circularShift(x: Int, shift: Int) -> String {
let digits = String(x).characters.map { String($0) }
let shifted = (digits + digits)[shift..<digits.count + shift]
return shifted.reduce("") { $0 + $1 }
}
```swift
// Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// circularShift(x: 12, shift: 1) == "21"
// circularShift(x: 12, shift: 2) == "12"
func circularShift(x: Int, shift: Int) -> String {
let digits = String(x).characters.map { String($0) }
let shifted = (digits + digits)[shift..<digits.count + shift]
return shifted.reduce("") { $0 + $1 }
}
```
let digits = String(x).characters.map { String($0) } // 'characters' is unavailable: Please use String directly
func circularShift(x: Int, shift: Int) -> String {
let digits = String(x).characters.map { String($0) }
let shifted = digits.dropFirst(shift) + digits.dropLast(shift)
return shifted.joined()
}
```swift
// Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// circularShift(x: 12, shift: 1) == "21"
// circularShift(x: 12, shift: 2) == "12"
func circularShift(x: Int, shift: Int) -> String {
let digits = String(x).characters.map { String($0) }
let shifted = digits.dropFirst(shift) + digits.dropLast(shift)
return shifted.joined()
}
```
let digits = String(x).characters.map { String($0) } // 'characters' is unavailable: Please use String directly
func circularShift(x: Int, shift: Int) -> String {
let digits = String(x).characters.map { String($0) }
let shifted = digits.dropFirst(shift) + digits.dropLast(shift)
return shifted.joined()
}
```swift
// Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// circularShift(x: 12, shift: 1) == "21"
// circularShift(x: 12, shift: 2) == "12"
func circularShift(x: Int, shift: Int) -> String {
let digits = String(x).characters.map { String($0) }
let shifted = digits.dropFirst(shift) + digits.dropLast(shift)
return shifted.joined()
}
```
let digits = String(x).characters.map { String($0) } // 'characters' is unavailable: Please use String directly
func circularShift(x: Int, shift: Int) -> String {
let digits = String(x).characters.map { String($0) }
let shifted = digits.dropFirst(shift) + digits.dropLast(shift)
return shifted.joined()
}
```swift
// Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// circularShift(x: 12, shift: 1) == "21"
// circularShift(x: 12, shift: 2) == "12"
func circularShift(x: Int, shift: Int) -> String {
let digits = String(x).characters.map { String($0) }
let shifted = digits.dropFirst(shift) + digits.dropLast(shift)
return shifted.joined()
}
```
let digits = String(x).characters.map { String($0) } // 'characters' is unavailable: Please use String directly
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if let ascii = char.asciiValue {
if ascii >= 65 && ascii <= 90 {
sum += Int(ascii)
}
}
}
return sum
}
func wordCount(s: String) -> Int {
var count = 0
for word in s.split(separator: " ") {
count += 1
}
return count
}
```swift
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if let ascii = char.asciiValue {
if ascii >= 65 && ascii <= 90 {
sum += Int(ascii)
}
}
}
return sum
}
// Task
// Write a function that takes a string as input and returns the number of words in the string.
// Examples:
// wordCount(s: "Hello, my name is") == 4
// wordCount(s: "No words") == 0
// wordCount(s: "a b c d") == 4
// wordCount(s: "goodbye cruel world") == 5
func wordCount(s: String) -> Int {
var count = 0
for word in s.split(separator: " ") {
count += 1
}
return count
}
// Task
// Write a function that takes a string as input and returns the number of words in the string.
// Examples:
// wordCount(s: "Hello, my name is") == 4
// wordCount(s: "No words") == 0
// wordCount(s: "a b c d") == 4
// wordCount(s: "goodbye cruel world") == 5
func wordCount(s: String) -> Int {
var count = 0
for word in s.split(separator: " ") {
count += 1
}
return count
}
// Task
// Write a function that takes a string as input and returns the number of words in the string.
// Examples:
// wordCount(s: "Hello, my name is") == 4
// wordCount(s: "No words") == 0
// wordCount(s: "a b c d") == 4
// wordCount(s: "goodbye cruel world") == 5
func wordCount(s: String) -> Int {
var count = 0
for word in s.split(separator: " ") {
count += 1
}
return count
}
// Task
// Write a function that takes a string as input and returns the number of words in the string.
// Examples:
// wordCount(s: "Hello, my name is") == 4
// wordCount(s: "No words") == 0
// wordCount(s: "a b c d") == 4
// wordCount(s: "goodbye cruel world") == 5
func wordCount(s: String) -> Int {
var count = 0
for word in s.split(separator: " ") {
count += 1
}
return count
}
// Task
// Write a function that takes a string as input and returns the number of words in the string.
// Examples:
// wordCount(s: "Hello, my name is") == 4
// wordCount(s: "No words") == 0
// wordCount(s: "a b c d") == 4
// wordCount(s: "goodbye cruel world") == 5
func wordCount(s: String) -> Int {
var count = 0
for word in s.split(separator: " ") {
count += 1
}
return count
}
// Task
// Write a function that takes a string as input and returns the number of words in the string.
// Examples:
// wordCount(s: "Hello, my name is") == 4
// wordCount(s: "No words") == 0
// wordCount(s: "a b c d") == 4
// wordCount(s: "goodbye cruel world") == 5
func wordCount(s: String) -> Int {
var count = 0
for word in s.split(separator: " ") {
count += 1
}
return count
}
// Task
// Write a function that takes a string as input and returns the number of words in the string.
// Examples:
// wordCount(s: "Hello, my name is") == 4
// wordCount(s: "No words") == 0
// wordCount(s: "a b c d") == 4
// wordCount(s: "goodbye cruel world") == 5
func wordCount(s: String) -> Int {
var count = 0
for word in s.split(separator: " ") {
count += 1
}
return count
}
// Task
// Write a function that takes a string as input and returns the
for word in s.split(separator: " ") { // immutable value 'word' was never used; consider replacing with '_' or removing it
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += Int(char.asciiValue!) - 64
}
}
return sum
}
```swift
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += Int(char.asciiValue!) - 64
}
}
return sum
}
```
// XCTAssertTrue failed
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if let ascii = char.asciiValue {
if ascii >= 65 && ascii <= 90 {
sum += Int(ascii)
}
}
}
return sum
}
```swift
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if let ascii = char.asciiValue {
if ascii >= 65 && ascii <= 90 {
sum += Int(ascii)
}
}
}
return sum
}
```
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += Int(char.asciiValue!)
}
}
return sum
}
```swift
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += Int(char.asciiValue!)
}
}
return sum
}
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += Int(char.asciiValue!)
}
}
return sum
}
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += Int(char.asciiValue!)
}
}
return sum
}
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += Int(char.asciiValue!)
}
}
return sum
}
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += Int(char.asciiValue!)
}
}
return sum
}
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += Int(char.asciiValue!)
}
}
return sum
}
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if let ascii = char.asciiValue {
if ascii >= 65 && ascii <= 90 {
sum += Int(ascii)
}
}
}
return sum
}
```swift
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if let ascii = char.asciiValue {
if ascii >= 65 && ascii <= 90 {
sum += Int(ascii)
}
}
}
return sum
}
```
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += Int(char.asciiValue!) - 64
}
}
return sum
}
func digitSum(arr: [Int]) -> Int {
var sum = 0
for num in arr {
var num = num
while num > 0 {
sum += num % 10
num /= 10
}
}
return sum
}
func isPalindrome(s: String) -> Bool {
var isPalindrome = true
for i in 0..<s.count / 2 {
if s[s.index(s.startIndex, offsetBy: i)]!= s[s.index(s.startIndex, offsetBy: s.count - 1 - i)] {
isPalindrome = false
break
}
}
return isPalindrome
}
func evenSum(arr: [Int]) -> Int {
var sum = 0
for num in arr {
if num % 2 == 0 {
sum += num
}
}
return sum
}
func oddSum(arr: [Int]) -> Int {
var sum = 0
for num in arr {
if num % 2!= 0 {
sum += num
}
}
return sum
}
func positiveSum(arr: [Int]) -> Int {
var sum = 0
for num in arr {
if num > 0 {
sum += num
}
}
return sum
}
func negativeSum(arr: [Int]) -> Int {
var sum = 0
for num in arr {
if num < 0 {
sum += num
}
}
return sum
}
```swift
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += Int(char.asciiValue!) - 64
}
}
return sum
}
// Task
// Write a function that takes an array of integers and returns the sum of the digits of each integer.
// Examples:
// digitSum([1, 2, 3]) == 6
// digitSum([10, 20, 30]) == 60
// digitSum([100, 200, 300]) == 600
func digitSum(arr: [Int]) -> Int {
var sum = 0
for num in arr {
var num = num
while num > 0 {
sum += num % 10
num /= 10
}
}
return sum
}
// Task
// Write a function that takes a string and returns true if it is a palindrome, false otherwise.
// A palindrome is a word, phrase, or sequence that reads the same backward as forward.
// Examples:
// isPalindrome("a") == true
// isPalindrome("ab") == false
// isPalindrome("abba") == true
// isPalindrome("abcdefg") == false
func isPalindrome(s: String) -> Bool {
var isPalindrome = true
for i in 0..<s.count / 2 {
if s[s.index(s.startIndex, offsetBy: i)]!= s[s.index(s.startIndex, offsetBy: s.count - 1 - i)] {
isPalindrome = false
break
}
}
return isPalindrome
}
// Task
// Write a function that takes an array of integers and returns the sum of the even numbers.
// Examples:
// evenSum([1, 2, 3]) == 2
// evenSum([10, 20, 30]) == 40
// evenSum([100, 200, 300]) == 400
func evenSum(arr: [Int]) -> Int {
var sum = 0
for num in arr {
if num % 2 == 0 {
sum += num
}
}
return sum
}
// Task
// Write a function that takes an array of integers and returns the sum of the odd numbers.
// Examples:
// oddSum([1, 2, 3]) == 4
// oddSum([10, 20, 30]) == 40
// oddSum([100, 200, 300]) == 400
func oddSum(arr: [Int]) -> Int {
var sum = 0
for num in arr {
if num % 2!= 0 {
sum += num
}
}
return sum
}
// Task
// Write a function that takes an array of integers and returns the sum of the positive numbers.
// Examples:
// positiveSum([1, 2, 3]) == 6
// positiveSum([10, 20, 30]) == 60
// positiveSum([100, 200, 300]) == 600
func positiveSum(arr: [Int]) -> Int {
var sum = 0
for num in arr {
if num > 0 {
sum += num
}
}
return sum
}
// Task
// Write a function that takes an array of integers and returns the sum of the negative numbers.
// Examples:
// negativeSum([1, 2, 3]) == 0
// negativeSum([10, 20, 30]) == -60
// negativeSum([100, 200, 300]) == -600
func negativeSum(arr: [Int]) -> Int {
var sum = 0
for num in arr {
if num < 0 {
sum += num
}
}
return sum
}
// Task
// Write a function that takes an array of integers and returns the sum of the numbers that are evenly divisible by 3.
// Examples:
// divisibleByThreeSum([1, 2, 3]) == 0
// divisibleByThreeSum([10, 20, 30]) == 60
// divisibleByThreeSum([100, 200, 300]) == 600
if s[s.index(s.startIndex, offsetBy: i)]!= s[s.index(s.startIndex, offsetBy: s.count - 1 - i)] { // use of '=' in a boolean context, did you mean '=='?
if s[s.index(s.startIndex, offsetBy: i)]!= s[s.index(s.startIndex, offsetBy: s.count - 1 - i)] { // '=' must have consistent whitespace on both sides
if s[s.index(s.startIndex, offsetBy: i)]!= s[s.index(s.startIndex, offsetBy: s.count - 1 - i)] { // cannot force unwrap value of non-optional type 'Character'
if num % 2!= 0 { // expression is not assignable: binary operator returns immutable value
if num % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if num % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if num % 2!= 0 { // '=' must have consistent whitespace on both sides
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += Int(char.asciiValue!)
}
}
return sum
}
```swift
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += Int(char.asciiValue!)
}
}
return sum
}
```
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char >= "A" && char <= "Z" {
sum += Int(char.unicodeScalars.first!.value)
}
}
return sum
}
```swift
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char >= "A" && char <= "Z" {
sum += Int(char.unicodeScalars.first!.value)
}
}
return sum
}
```
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += Int(char.asciiValue!)
}
}
return sum
}
func stringsLongerThan4(strings: [String]) -> [String] {
var result = [String]()
for string in strings {
if string.count > 4 {
result.append(string)
}
}
return result
}
```swift
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += Int(char.asciiValue!)
}
}
return sum
}
// Task
// Write a function that takes an array of strings and returns the strings that are longer than 4 characters.
// Examples:
// stringsLongerThan4(strings: ["a", "abc", "abcd", "abcde"]) == ["abcd", "abcde"]
// stringsLongerThan4(strings: ["a", "abc", "abcd"]) == ["abcd"]
// stringsLongerThan4(strings: ["abc", "abcd", "abcde"]) == ["abcd", "abcde"]
// stringsLongerThan4(strings: ["abc", "abcd"]) == ["abcd"]
// stringsLongerThan4(strings: ["abc", "abcd", "abcde"]) == ["abcd", "abcde"]
func stringsLongerThan4(strings: [String]) -> [String] {
var result = [String]()
for string in strings {
if string.count > 4 {
result.append(string)
}
}
return result
}
// Task
// Write a function that takes an array of strings and returns the strings that are longer than 4 characters.
// Examples:
// stringsLongerThan4(strings: ["a", "abc", "abcd", "abcde"]) == ["abcd", "abcde"]
// stringsLongerThan4(strings: ["a", "abc", "abcd"]) == ["abcd"]
// stringsLongerThan4(strings: ["abc", "abcd", "abcde"]) == ["abcd", "abcde"]
// stringsLongerThan4(strings: ["abc", "abcd"]) == ["abcd"]
// stringsLongerThan4(strings: ["abc", "abcd", "abcde"]) == ["abcd", "abcde"]
func stringsLongerThan4(strings: [String]) -> [String] {
var result = [String]()
for string in strings {
if string.count > 4 {
result.append(string)
}
}
return result
}
// Task
// Write a function that takes an array of strings and returns the strings that are longer than 4 characters.
// Examples:
// stringsLongerThan4(strings: ["a", "abc", "abcd", "abcde"]) == ["abcd", "abcde"]
// stringsLongerThan4(strings: ["a", "abc", "abcd"]) == ["abcd"]
// stringsLongerThan4(strings: ["abc", "abcd", "abcde"]) == ["abcd", "abcde"]
// stringsLongerThan4(strings: ["abc", "abcd"]) == ["abcd"]
// stringsLongerThan4(strings: ["abc", "abcd", "abcde"]) == ["abcd", "abcde"]
func stringsLongerThan4(strings: [String]) -> [String] {
var result = [String]()
for string in strings {
if string.count > 4 {
result.append(string)
}
}
return result
}
// Task
// Write a function that takes an array of strings and returns the strings that are longer than 4 characters.
// Examples:
// stringsLongerThan4(strings: ["a", "abc", "abcd", "abcde"]) == ["abcd", "abcde"]
// stringsLongerThan4(strings: ["a", "abc", "abcd"]) == ["abcd"]
// stringsLongerThan4(strings: ["abc", "abcd", "abcde"]) == ["abcd", "abcde"]
// stringsLongerThan4(strings: ["abc", "abcd"]) == ["abcd"]
// stringsLongerThan4(strings: ["abc", "abcd", "abcde"]) == ["abcd", "abcde"]
func stringsLongerThan4(strings: [String]) -> [String] {
var result = [String]()
for string in strings {
if string.count > 4 {
result.append(string)
}
}
return result
}
// Task
// Write a function that takes an array of strings and returns the strings that are longer than 4 characters.
// Examples:
// stringsLongerThan4(strings: ["a", "abc", "abcd", "abcde"]) == ["abcd", "abcde"]
// stringsLongerThan4(strings: ["a", "abc", "abcd"]) == ["abcd"]
// stringsLongerThan4(strings: ["abc", "abcd", "abcde"]) == ["abcd", "abcde"]
// stringsLong
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += Int(char.asciiValue!) - 64
}
}
return sum
}
```swift
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += Int(char.asciiValue!) - 64
}
}
return sum
}
```
// XCTAssertTrue failed
func fruitDistribution(s: String, n: Int) -> Int {
let apples = s.components(separatedBy: " ").filter { $0.contains("apple") }
let oranges = s.components(separatedBy: " ").filter { $0.contains("orange") }
let applesCount = Int(apples.first?? "0")?? 0
let orangesCount = Int(oranges.first?? "0")?? 0
return n - (applesCount + orangesCount)
}
```swift
// In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// fruitDistribution(s: "5 apples and 6 oranges", n: 19) == 8
// fruitDistribution(s: "0 apples and 1 oranges", n: 3) == 2
// fruitDistribution(s: "2 apples and 3 oranges", n: 100) == 95
// fruitDistribution(s: "100 apples and 1 oranges", n: 120) == 19
func fruitDistribution(s: String, n: Int) -> Int {
let apples = s.components(separatedBy: " ").filter { $0.contains("apple") }
let oranges = s.components(separatedBy: " ").filter { $0.contains("orange") }
let applesCount = Int(apples.first?? "0")?? 0
let orangesCount = Int(oranges.first?? "0")?? 0
return n - (applesCount + orangesCount)
}
```
let applesCount = Int(apples.first?? "0")?? 0 // consecutive statements on a line must be separated by ';'
let applesCount = Int(apples.first?? "0")?? 0 // expected ',' separator
let applesCount = Int(apples.first?? "0")?? 0 // integer literal is unused
let applesCount = Int(apples.first?? "0")?? 0 // cannot use optional chaining on non-optional value of type 'Int'
let applesCount = Int(apples.first?? "0")?? 0 // no exact matches in call to initializer
let applesCount = Int(apples.first?? "0")?? 0 // cannot use optional chaining on non-optional value of type 'String'
let applesCount = Int(apples.first?? "0")?? 0 // cannot use optional chaining on non-optional value of type 'Int'
let orangesCount = Int(oranges.first?? "0")?? 0 // cannot use optional chaining on non-optional value of type 'Int'
let orangesCount = Int(oranges.first?? "0")?? 0 // integer literal is unused
let orangesCount = Int(oranges.first?? "0")?? 0 // no exact matches in call to initializer
let orangesCount = Int(oranges.first?? "0")?? 0 // cannot use optional chaining on non-optional value of type 'Int'
let orangesCount = Int(oranges.first?? "0")?? 0 // cannot use optional chaining on non-optional value of type 'String'
let orangesCount = Int(oranges.first?? "0")?? 0 // consecutive statements on a line must be separated by ';'
let orangesCount = Int(oranges.first?? "0")?? 0 // expected ',' separator
return n - (applesCount + orangesCount) // cannot convert value of type 'String' to expected argument type 'Int'
func fruitDistribution(s: String, n: Int) -> Int {
var apples = 0
var oranges = 0
var mangoes = 0
var total = 0
let split = s.split(separator: " ")
for i in split {
if i.contains("apples") {
apples = Int(i.replacingOccurrences(of: "apples", with: ""))?? 0
} else if i.contains("oranges") {
oranges = Int(i.replacingOccurrences(of: "oranges", with: ""))?? 0
} else if i.contains("mangoes") {
mangoes = Int(i.replacingOccurrences(of: "mangoes", with: ""))?? 0
}
}
total = apples + oranges + mangoes
return n - total
}
```swift
// In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// fruitDistribution(s: "5 apples and 6 oranges", n: 19) == 8
// fruitDistribution(s: "0 apples and 1 oranges", n: 3) == 2
// fruitDistribution(s: "2 apples and 3 oranges", n: 100) == 95
// fruitDistribution(s: "100 apples and 1 oranges", n: 120) == 19
func fruitDistribution(s: String, n: Int) -> Int {
var apples = 0
var oranges = 0
var mangoes = 0
var total = 0
let split = s.split(separator: " ")
for i in split {
if i.contains("apples") {
apples = Int(i.replacingOccurrences(of: "apples", with: ""))?? 0
} else if i.contains("oranges") {
oranges = Int(i.replacingOccurrences(of: "oranges", with: ""))?? 0
} else if i.contains("mangoes") {
mangoes = Int(i.replacingOccurrences(of: "mangoes", with: ""))?? 0
}
}
total = apples + oranges + mangoes
return n - total
}
```
apples = Int(i.replacingOccurrences(of: "apples", with: ""))?? 0 // cannot use optional chaining on non-optional value of type 'Int'
apples = Int(i.replacingOccurrences(of: "apples", with: ""))?? 0 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
apples = Int(i.replacingOccurrences(of: "apples", with: ""))?? 0 // consecutive statements on a line must be separated by ';'
apples = Int(i.replacingOccurrences(of: "apples", with: ""))?? 0 // integer literal is unused
oranges = Int(i.replacingOccurrences(of: "oranges", with: ""))?? 0 // consecutive statements on a line must be separated by ';'
oranges = Int(i.replacingOccurrences(of: "oranges", with: ""))?? 0 // integer literal is unused
oranges = Int(i.replacingOccurrences(of: "oranges", with: ""))?? 0 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
oranges = Int(i.replacingOccurrences(of: "oranges", with: ""))?? 0 // cannot use optional chaining on non-optional value of type 'Int'
mangoes = Int(i.replacingOccurrences(of: "mangoes", with: ""))?? 0 // integer literal is unused
mangoes = Int(i.replacingOccurrences(of: "mangoes", with: ""))?? 0 // cannot use optional chaining on non-optional value of type 'Int'
mangoes = Int(i.replacingOccurrences(of: "mangoes", with: ""))?? 0 // consecutive statements on a line must be separated by ';'
mangoes = Int(i.replacingOccurrences(of: "mangoes", with: ""))?? 0 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
func fruitDistribution(s: String, n: Int) -> Int {
let numbers = s.components(separatedBy: " ")
let apples = Int(numbers[0])!
let oranges = Int(numbers[2])!
let total = apples + oranges
return n - total
}
```swift
// In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// fruitDistribution(s: "5 apples and 6 oranges", n: 19) == 8
// fruitDistribution(s: "0 apples and 1 oranges", n: 3) == 2
// fruitDistribution(s: "2 apples and 3 oranges", n: 100) == 95
// fruitDistribution(s: "100 apples and 1 oranges", n: 120) == 19
func fruitDistribution(s: String, n: Int) -> Int {
let numbers = s.components(separatedBy: " ")
let apples = Int(numbers[0])!
let oranges = Int(numbers[2])!
let total = apples + oranges
return n - total
}
```
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func fruitDistribution(s: String, n: Int) -> Int {
var apples = 0
var oranges = 0
var mangoes = 0
let arr = s.split(separator: " ")
for i in 0..<arr.count {
if arr[i] == "apples" {
apples = Int(arr[i-1])?? 0
}
if arr[i] == "oranges" {
oranges = Int(arr[i-1])?? 0
}
}
mangoes = n - (apples + oranges)
return mangoes
}
```swift
// In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// fruitDistribution(s: "5 apples and 6 oranges", n: 19) == 8
// fruitDistribution(s: "0 apples and 1 oranges", n: 3) == 2
// fruitDistribution(s: "2 apples and 3 oranges", n: 100) == 95
// fruitDistribution(s: "100 apples and 1 oranges", n: 120) == 19
func fruitDistribution(s: String, n: Int) -> Int {
var apples = 0
var oranges = 0
var mangoes = 0
let arr = s.split(separator: " ")
for i in 0..<arr.count {
if arr[i] == "apples" {
apples = Int(arr[i-1])?? 0
}
if arr[i] == "oranges" {
oranges = Int(arr[i-1])?? 0
}
}
mangoes = n - (apples + oranges)
return mangoes
}
```
apples = Int(arr[i-1])?? 0 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
apples = Int(arr[i-1])?? 0 // integer literal is unused
apples = Int(arr[i-1])?? 0 // consecutive statements on a line must be separated by ';'
apples = Int(arr[i-1])?? 0 // cannot use optional chaining on non-optional value of type 'Int'
oranges = Int(arr[i-1])?? 0 // consecutive statements on a line must be separated by ';'
oranges = Int(arr[i-1])?? 0 // cannot use optional chaining on non-optional value of type 'Int'
oranges = Int(arr[i-1])?? 0 // integer literal is unused
oranges = Int(arr[i-1])?? 0 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
func fruitDistribution(s: String, n: Int) -> Int {
var apples = 0
var oranges = 0
var mangoes = 0
var total = 0
for i in s {
if i == "a" {
apples += 1
} else if i == "o" {
oranges += 1
} else if i == "m" {
mangoes += 1
}
}
total = apples + oranges + mangoes
return n - total
}
```swift
// In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// fruitDistribution(s: "5 apples and 6 oranges", n: 19) == 8
// fruitDistribution(s: "0 apples and 1 oranges", n: 3) == 2
// fruitDistribution(s: "2 apples and 3 oranges", n: 100) == 95
// fruitDistribution(s: "100 apples and 1 oranges", n: 120) == 19
func fruitDistribution(s: String, n: Int) -> Int {
var apples = 0
var oranges = 0
var mangoes = 0
var total = 0
for i in s {
if i == "a" {
apples += 1
} else if i == "o" {
oranges += 1
} else if i == "m" {
mangoes += 1
}
}
total = apples + oranges + mangoes
return n - total
}
```
// XCTAssertTrue failed
func fruitDistribution(s: String, n: Int) -> Int {
var apples = 0
var oranges = 0
var mangoes = 0
let arr = s.split(separator: " ")
for i in arr {
if i.contains("apples") {
apples = Int(i.replacingOccurrences(of: "apples", with: ""))!
} else if i.contains("oranges") {
oranges = Int(i.replacingOccurrences(of: "oranges", with: ""))!
}
}
mangoes = n - (apples + oranges)
return mangoes
}
```swift
// In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// fruitDistribution(s: "5 apples and 6 oranges", n: 19) == 8
// fruitDistribution(s: "0 apples and 1 oranges", n: 3) == 2
// fruitDistribution(s: "2 apples and 3 oranges", n: 100) == 95
// fruitDistribution(s: "100 apples and 1 oranges", n: 120) == 19
func fruitDistribution(s: String, n: Int) -> Int {
var apples = 0
var oranges = 0
var mangoes = 0
let arr = s.split(separator: " ")
for i in arr {
if i.contains("apples") {
apples = Int(i.replacingOccurrences(of: "apples", with: ""))!
} else if i.contains("oranges") {
oranges = Int(i.replacingOccurrences(of: "oranges", with: ""))!
}
}
mangoes = n - (apples + oranges)
return mangoes
}
```
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func fruitDistribution(s: String, n: Int) -> Int {
var apples = 0
var oranges = 0
var mangoes = 0
for i in s {
if i == "a" {
apples += 1
} else if i == "o" {
oranges += 1
} else if i == "m" {
mangoes += 1
}
}
if n >= apples + oranges {
return mangoes
} else {
return mangoes - (n - (apples + oranges))
}
}
```swift
// In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// fruitDistribution(s: "5 apples and 6 oranges", n: 19) == 8
// fruitDistribution(s: "0 apples and 1 oranges", n: 3) == 2
// fruitDistribution(s: "2 apples and 3 oranges", n: 100) == 95
// fruitDistribution(s: "100 apples and 1 oranges", n: 120) == 19
func fruitDistribution(s: String, n: Int) -> Int {
var apples = 0
var oranges = 0
var mangoes = 0
for i in s {
if i == "a" {
apples += 1
} else if i == "o" {
oranges += 1
} else if i == "m" {
mangoes += 1
}
}
if n >= apples + oranges {
return mangoes
} else {
return mangoes - (n - (apples + oranges))
}
}
```
// XCTAssertTrue failed
func fruitDistribution(s: String, n: Int) -> Int {
var apples = 0
var oranges = 0
var mangoes = 0
var total = 0
var words = s.components(separatedBy: " ")
for word in words {
if word.contains("apples") {
apples = Int(word.replacingOccurrences(of: "apples", with: ""))!
} else if word.contains("oranges") {
oranges = Int(word.replacingOccurrences(of: "oranges", with: ""))!
}
}
total = apples + oranges
mangoes = n - total
return mangoes
}
```swift
// In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// fruitDistribution(s: "5 apples and 6 oranges", n: 19) == 8
// fruitDistribution(s: "0 apples and 1 oranges", n: 3) == 2
// fruitDistribution(s: "2 apples and 3 oranges", n: 100) == 95
// fruitDistribution(s: "100 apples and 1 oranges", n: 120) == 19
func fruitDistribution(s: String, n: Int) -> Int {
var apples = 0
var oranges = 0
var mangoes = 0
var total = 0
var words = s.components(separatedBy: " ")
for word in words {
if word.contains("apples") {
apples = Int(word.replacingOccurrences(of: "apples", with: ""))!
} else if word.contains("oranges") {
oranges = Int(word.replacingOccurrences(of: "oranges", with: ""))!
}
}
total = apples + oranges
mangoes = n - total
return mangoes
}
```
var words = s.components(separatedBy: " ") // variable 'words' was never mutated; consider changing to 'let' constant
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func fruitDistribution(s: String, n: Int) -> Int {
let arr = s.split(separator: " ").map { String($0) }
let apples = Int(arr[0])!
let oranges = Int(arr[2])!
let total = apples + oranges
return n - total
}
```swift
// In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// fruitDistribution(s: "5 apples and 6 oranges", n: 19) == 8
// fruitDistribution(s: "0 apples and 1 oranges", n: 3) == 2
// fruitDistribution(s: "2 apples and 3 oranges", n: 100) == 95
// fruitDistribution(s: "100 apples and 1 oranges", n: 120) == 19
func fruitDistribution(s: String, n: Int) -> Int {
let arr = s.split(separator: " ").map { String($0) }
let apples = Int(arr[0])!
let oranges = Int(arr[2])!
let total = apples + oranges
return n - total
}
```
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func fruitDistribution(s: String, n: Int) -> Int {
var apples = 0
var oranges = 0
var mangoes = 0
var total = 0
for i in s {
if i == "a" {
apples += 1
} else if i == "o" {
oranges += 1
} else if i == "m" {
mangoes += 1
}
}
total = n - (apples + oranges)
if total < 0 {
return 0
} else if total < mangoes {
return total
} else {
return mangoes
}
}
```swift
// In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// fruitDistribution(s: "5 apples and 6 oranges", n: 19) == 8
// fruitDistribution(s: "0 apples and 1 oranges", n: 3) == 2
// fruitDistribution(s: "2 apples and 3 oranges", n: 100) == 95
// fruitDistribution(s: "100 apples and 1 oranges", n: 120) == 19
func fruitDistribution(s: String, n: Int) -> Int {
var apples = 0
var oranges = 0
var mangoes = 0
var total = 0
for i in s {
if i == "a" {
apples += 1
} else if i == "o" {
oranges += 1
} else if i == "m" {
mangoes += 1
}
}
total = n - (apples + oranges)
if total < 0 {
return 0
} else if total < mangoes {
return total
} else {
return mangoes
}
}
```
// XCTAssertTrue failed
func pluck(arr: [Int]) -> [Int] {
var min = Int.max
var minIndex = 0
for (index, value) in arr.enumerated() {
if value % 2 == 0 && value < min {
min = value
minIndex = index
}
}
if min == Int.max {
return []
}
return [min, minIndex]
}
```swift
// "Given an array representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
// The plucked node should be returned in an array, [ smalest_value, its index ],
// If there are no even values or the given array is empty, return [].
// Example 1:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// Example 4:
// Explanation: 0 is the smallest value, but there are two zeros,
// so we will choose the first zero, which has the smallest index.
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
// pluck(arr: [4, 2, 3]) == [2, 1]
// pluck(arr: [1, 2, 3]) == [2, 1]
// pluck(arr: [] as [Int]) == [] as [Int]
// pluck(arr: [5, 0, 3, 0, 4, 2]) == [0, 1]
func pluck(arr: [Int]) -> [Int] {
var min = Int.max
var minIndex = 0
for (index, value) in arr.enumerated() {
if value % 2 == 0 && value < min {
min = value
minIndex = index
}
}
if min == Int.max {
return []
}
return [min, minIndex]
}
```
func pluck(arr: [Int]) -> [Int] {
var minValue = Int.max
var minIndex = -1
for (index, value) in arr.enumerated() {
if value % 2 == 0 && value < minValue {
minValue = value
minIndex = index
}
}
return [minValue, minIndex]
}
```swift
// "Given an array representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
// The plucked node should be returned in an array, [ smalest_value, its index ],
// If there are no even values or the given array is empty, return [].
// Example 1:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// Example 4:
// Explanation: 0 is the smallest value, but there are two zeros,
// so we will choose the first zero, which has the smallest index.
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
// pluck(arr: [4, 2, 3]) == [2, 1]
// pluck(arr: [1, 2, 3]) == [2, 1]
// pluck(arr: [] as [Int]) == [] as [Int]
// pluck(arr: [5, 0, 3, 0, 4, 2]) == [0, 1]
func pluck(arr: [Int]) -> [Int] {
var minValue = Int.max
var minIndex = -1
for (index, value) in arr.enumerated() {
if value % 2 == 0 && value < minValue {
minValue = value
minIndex = index
}
}
return [minValue, minIndex]
}
```
// XCTAssertTrue failed
func pluck(arr: [Int]) -> [Int] {
var smallest = [Int.max, -1]
for (index, value) in arr.enumerated() {
if value % 2 == 0 && value < smallest[0] {
smallest = [value, index]
}
}
return smallest
}
```swift
// "Given an array representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
// The plucked node should be returned in an array, [ smalest_value, its index ],
// If there are no even values or the given array is empty, return [].
// Example 1:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// Example 4:
// Explanation: 0 is the smallest value, but there are two zeros,
// so we will choose the first zero, which has the smallest index.
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
// pluck(arr: [4, 2, 3]) == [2, 1]
// pluck(arr: [1, 2, 3]) == [2, 1]
// pluck(arr: [] as [Int]) == [] as [Int]
// pluck(arr: [5, 0, 3, 0, 4, 2]) == [0, 1]
func pluck(arr: [Int]) -> [Int] {
var smallest = [Int.max, -1]
for (index, value) in arr.enumerated() {
if value % 2 == 0 && value < smallest[0] {
smallest = [value, index]
}
}
return smallest
}
```
// XCTAssertTrue failed
func pluck(arr: [Int]) -> [Int] {
var min = Int.max
var index = -1
for (i, v) in arr.enumerated() {
if v % 2 == 0 && v < min {
min = v
index = i
}
}
return index == -1? [] : [min, index]
}
```swift
// "Given an array representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
// The plucked node should be returned in an array, [ smalest_value, its index ],
// If there are no even values or the given array is empty, return [].
// Example 1:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// Example 4:
// Explanation: 0 is the smallest value, but there are two zeros,
// so we will choose the first zero, which has the smallest index.
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
// pluck(arr: [4, 2, 3]) == [2, 1]
// pluck(arr: [1, 2, 3]) == [2, 1]
// pluck(arr: [] as [Int]) == [] as [Int]
// pluck(arr: [5, 0, 3, 0, 4, 2]) == [0, 1]
func pluck(arr: [Int]) -> [Int] {
var min = Int.max
var index = -1
for (i, v) in arr.enumerated() {
if v % 2 == 0 && v < min {
min = v
index = i
}
}
return index == -1? [] : [min, index]
}
```
return index == -1? [] : [min, index] // expected expression
return index == -1? [] : [min, index] // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
return index == -1? [] : [min, index] // value of type 'Int' has no subscripts
return index == -1? [] : [min, index] // cannot convert return expression of type 'Bool' to return type '[Int]'
return index == -1? [] : [min, index] // cannot use optional chaining on non-optional value of type 'Int'
return index == -1? [] : [min, index] // consecutive statements on a line must be separated by ';'
func pluck(arr: [Int]) -> [Int] {
var result: [Int] = []
var minValue = Int.max
var minIndex = 0
for (index, value) in arr.enumerated() {
if value % 2 == 0 && value < minValue {
minValue = value
minIndex = index
}
}
if minValue == Int.max {
return []
}
result.append(minValue)
result.append(minIndex)
return result
}
```swift
// "Given an array representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
// The plucked node should be returned in an array, [ smalest_value, its index ],
// If there are no even values or the given array is empty, return [].
// Example 1:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// Example 4:
// Explanation: 0 is the smallest value, but there are two zeros,
// so we will choose the first zero, which has the smallest index.
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
// pluck(arr: [4, 2, 3]) == [2, 1]
// pluck(arr: [1, 2, 3]) == [2, 1]
// pluck(arr: [] as [Int]) == [] as [Int]
// pluck(arr: [5, 0, 3, 0, 4, 2]) == [0, 1]
func pluck(arr: [Int]) -> [Int] {
var result: [Int] = []
var minValue = Int.max
var minIndex = 0
for (index, value) in arr.enumerated() {
if value % 2 == 0 && value < minValue {
minValue = value
minIndex = index
}
}
if minValue == Int.max {
return []
}
result.append(minValue)
result.append(minIndex)
return result
}
```
func pluck(arr: [Int]) -> [Int] {
var result: [Int] = []
var minValue = Int.max
var minIndex = 0
for (index, value) in arr.enumerated() {
if value % 2 == 0 && value < minValue {
minValue = value
minIndex = index
}
}
if minValue!= Int.max {
result.append(minValue)
result.append(minIndex)
}
return result
}
```swift
// "Given an array representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
// The plucked node should be returned in an array, [ smalest_value, its index ],
// If there are no even values or the given array is empty, return [].
// Example 1:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// Example 4:
// Explanation: 0 is the smallest value, but there are two zeros,
// so we will choose the first zero, which has the smallest index.
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
// pluck(arr: [4, 2, 3]) == [2, 1]
// pluck(arr: [1, 2, 3]) == [2, 1]
// pluck(arr: [] as [Int]) == [] as [Int]
// pluck(arr: [5, 0, 3, 0, 4, 2]) == [0, 1]
func pluck(arr: [Int]) -> [Int] {
var result: [Int] = []
var minValue = Int.max
var minIndex = 0
for (index, value) in arr.enumerated() {
if value % 2 == 0 && value < minValue {
minValue = value
minIndex = index
}
}
if minValue!= Int.max {
result.append(minValue)
result.append(minIndex)
}
return result
}
```
if minValue!= Int.max { // cannot force unwrap value of non-optional type 'Int'
if minValue!= Int.max { // '=' must have consistent whitespace on both sides
if minValue!= Int.max { // use of '=' in a boolean context, did you mean '=='?
func pluck(arr: [Int]) -> [Int] {
var min = Int.max
var index = -1
for (i, v) in arr.enumerated() {
if v % 2 == 0 && v < min {
min = v
index = i
}
}
return index == -1? [] : [min, index]
}
```swift
// "Given an array representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
// The plucked node should be returned in an array, [ smalest_value, its index ],
// If there are no even values or the given array is empty, return [].
// Example 1:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// Example 4:
// Explanation: 0 is the smallest value, but there are two zeros,
// so we will choose the first zero, which has the smallest index.
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
// pluck(arr: [4, 2, 3]) == [2, 1]
// pluck(arr: [1, 2, 3]) == [2, 1]
// pluck(arr: [] as [Int]) == [] as [Int]
// pluck(arr: [5, 0, 3, 0, 4, 2]) == [0, 1]
func pluck(arr: [Int]) -> [Int] {
var min = Int.max
var index = -1
for (i, v) in arr.enumerated() {
if v % 2 == 0 && v < min {
min = v
index = i
}
}
return index == -1? [] : [min, index]
}
```
return index == -1? [] : [min, index] // expected expression
return index == -1? [] : [min, index] // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
return index == -1? [] : [min, index] // value of type 'Int' has no subscripts
return index == -1? [] : [min, index] // cannot convert return expression of type 'Bool' to return type '[Int]'
return index == -1? [] : [min, index] // cannot use optional chaining on non-optional value of type 'Int'
return index == -1? [] : [min, index] // consecutive statements on a line must be separated by ';'
func pluck(arr: [Int]) -> [Int] {
var minValue = Int.max
var minIndex = -1
for (index, value) in arr.enumerated() {
if value % 2 == 0 && value < minValue {
minValue = value
minIndex = index
}
}
return minIndex == -1? [] : [minValue, minIndex]
}
```swift
// "Given an array representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
// The plucked node should be returned in an array, [ smalest_value, its index ],
// If there are no even values or the given array is empty, return [].
// Example 1:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// Example 4:
// Explanation: 0 is the smallest value, but there are two zeros,
// so we will choose the first zero, which has the smallest index.
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
// pluck(arr: [4, 2, 3]) == [2, 1]
// pluck(arr: [1, 2, 3]) == [2, 1]
// pluck(arr: [] as [Int]) == [] as [Int]
// pluck(arr: [5, 0, 3, 0, 4, 2]) == [0, 1]
func pluck(arr: [Int]) -> [Int] {
var minValue = Int.max
var minIndex = -1
for (index, value) in arr.enumerated() {
if value % 2 == 0 && value < minValue {
minValue = value
minIndex = index
}
}
return minIndex == -1? [] : [minValue, minIndex]
}
```
return minIndex == -1? [] : [minValue, minIndex] // cannot use optional chaining on non-optional value of type 'Int'
return minIndex == -1? [] : [minValue, minIndex] // cannot convert return expression of type 'Bool' to return type '[Int]'
return minIndex == -1? [] : [minValue, minIndex] // consecutive statements on a line must be separated by ';'
return minIndex == -1? [] : [minValue, minIndex] // value of type 'Int' has no subscripts
return minIndex == -1? [] : [minValue, minIndex] // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
return minIndex == -1? [] : [minValue, minIndex] // expected expression
func pluck(arr: [Int]) -> [Int] {
var min = Int.max
var minIndex = -1
for (index, value) in arr.enumerated() {
if value % 2 == 0 && value < min {
min = value
minIndex = index
}
}
if minIndex == -1 {
return []
}
return [min, minIndex]
}
```swift
// "Given an array representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
// The plucked node should be returned in an array, [ smalest_value, its index ],
// If there are no even values or the given array is empty, return [].
// Example 1:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// Example 4:
// Explanation: 0 is the smallest value, but there are two zeros,
// so we will choose the first zero, which has the smallest index.
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
// pluck(arr: [4, 2, 3]) == [2, 1]
// pluck(arr: [1, 2, 3]) == [2, 1]
// pluck(arr: [] as [Int]) == [] as [Int]
// pluck(arr: [5, 0, 3, 0, 4, 2]) == [0, 1]
func pluck(arr: [Int]) -> [Int] {
var min = Int.max
var minIndex = -1
for (index, value) in arr.enumerated() {
if value % 2 == 0 && value < min {
min = value
minIndex = index
}
}
if minIndex == -1 {
return []
}
return [min, minIndex]
}
```
func pluck(arr: [Int]) -> [Int] {
var smallestValue = Int.max
var smallestIndex = -1
for (index, value) in arr.enumerated() {
if value % 2 == 0 && value < smallestValue {
smallestValue = value
smallestIndex = index
}
}
if smallestIndex == -1 {
return []
}
return [smallestValue, smallestIndex]
}
```swift
// "Given an array representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
// The plucked node should be returned in an array, [ smalest_value, its index ],
// If there are no even values or the given array is empty, return [].
// Example 1:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// Example 4:
// Explanation: 0 is the smallest value, but there are two zeros,
// so we will choose the first zero, which has the smallest index.
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
// pluck(arr: [4, 2, 3]) == [2, 1]
// pluck(arr: [1, 2, 3]) == [2, 1]
// pluck(arr: [] as [Int]) == [] as [Int]
// pluck(arr: [5, 0, 3, 0, 4, 2]) == [0, 1]
func pluck(arr: [Int]) -> [Int] {
var smallestValue = Int.max
var smallestIndex = -1
for (index, value) in arr.enumerated() {
if value % 2 == 0 && value < smallestValue {
smallestValue = value
smallestIndex = index
}
}
if smallestIndex == -1 {
return []
}
return [smallestValue, smallestIndex]
}
```
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
dict[i] = (dict[i]?? 0) + 1
}
for (key, value) in dict {
if value > key {
return key
}
}
return -1
}
```swift
// You are given a non-empty array of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array.
// If no such a value exist, return -1.
// Examples:
// search(lst: [4, 1, 2, 2, 3, 1]) == 2
// search(lst: [1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3
// search(lst: [5, 5, 4, 4, 4]) == -1
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
dict[i] = (dict[i]?? 0) + 1
}
for (key, value) in dict {
if value > key {
return key
}
}
return -1
}
```
dict[i] = (dict[i]?? 0) + 1 // expected ',' separator
dict[i] = (dict[i]?? 0) + 1 // cannot use optional chaining on non-optional value of type 'Int'
dict[i] = (dict[i]?? 0) + 1 // cannot convert value of type '(Int?, Int)' to expected argument type 'Int'
func search(lst: [Int]) -> Int {
var result = -1
var dict = [Int: Int]()
for i in lst {
dict[i] = (dict[i]?? 0) + 1
}
for (key, value) in dict {
if value > key {
result = key
}
}
return result
}
```swift
// You are given a non-empty array of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array.
// If no such a value exist, return -1.
// Examples:
// search(lst: [4, 1, 2, 2, 3, 1]) == 2
// search(lst: [1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3
// search(lst: [5, 5, 4, 4, 4]) == -1
func search(lst: [Int]) -> Int {
var result = -1
var dict = [Int: Int]()
for i in lst {
dict[i] = (dict[i]?? 0) + 1
}
for (key, value) in dict {
if value > key {
result = key
}
}
return result
}
```
dict[i] = (dict[i]?? 0) + 1 // cannot convert value of type '(Int?, Int)' to expected argument type 'Int'
dict[i] = (dict[i]?? 0) + 1 // cannot use optional chaining on non-optional value of type 'Int'
dict[i] = (dict[i]?? 0) + 1 // expected ',' separator
func search(lst: [Int]) -> Int {
var result = -1
var max = 0
var dict = [Int: Int]()
for i in lst {
if let count = dict[i] {
dict[i] = count + 1
} else {
dict[i] = 1
}
}
for (key, value) in dict {
if value > max {
max = value
result = key
}
}
return result
}
```swift
// You are given a non-empty array of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array.
// If no such a value exist, return -1.
// Examples:
// search(lst: [4, 1, 2, 2, 3, 1]) == 2
// search(lst: [1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3
// search(lst: [5, 5, 4, 4, 4]) == -1
func search(lst: [Int]) -> Int {
var result = -1
var max = 0
var dict = [Int: Int]()
for i in lst {
if let count = dict[i] {
dict[i] = count + 1
} else {
dict[i] = 1
}
}
for (key, value) in dict {
if value > max {
max = value
result = key
}
}
return result
}
```
// XCTAssertTrue failed
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
if let count = dict[i] {
dict[i] = count + 1
} else {
dict[i] = 1
}
}
var result = -1
for (key, value) in dict {
if value > key {
result = key
}
}
return result
}
```swift
// You are given a non-empty array of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array.
// If no such a value exist, return -1.
// Examples:
// search(lst: [4, 1, 2, 2, 3, 1]) == 2
// search(lst: [1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3
// search(lst: [5, 5, 4, 4, 4]) == -1
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
if let count = dict[i] {
dict[i] = count + 1
} else {
dict[i] = 1
}
}
var result = -1
for (key, value) in dict {
if value > key {
result = key
}
}
return result
}
```
// XCTAssertTrue failed
func search(lst: [Int]) -> Int {
var dict: [Int: Int] = [:]
for num in lst {
dict[num, default: 0] += 1
}
for (key, value) in dict {
if value > key {
return key
}
}
return -1
}
```swift
// You are given a non-empty array of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array.
// If no such a value exist, return -1.
// Examples:
// search(lst: [4, 1, 2, 2, 3, 1]) == 2
// search(lst: [1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3
// search(lst: [5, 5, 4, 4, 4]) == -1
func search(lst: [Int]) -> Int {
var dict: [Int: Int] = [:]
for num in lst {
dict[num, default: 0] += 1
}
for (key, value) in dict {
if value > key {
return key
}
}
return -1
}
```
// XCTAssertTrue failed
func search(lst: [Int]) -> Int {
var result = -1
var count = 0
var maxCount = 0
var maxNum = 0
for num in lst {
if num > result {
count = 1
result = num
} else if num == result {
count += 1
}
if count > maxCount {
maxCount = count
maxNum = result
}
}
return maxNum
}
```swift
// You are given a non-empty array of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array.
// If no such a value exist, return -1.
// Examples:
// search(lst: [4, 1, 2, 2, 3, 1]) == 2
// search(lst: [1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3
// search(lst: [5, 5, 4, 4, 4]) == -1
func search(lst: [Int]) -> Int {
var result = -1
var count = 0
var maxCount = 0
var maxNum = 0
for num in lst {
if num > result {
count = 1
result = num
} else if num == result {
count += 1
}
if count > maxCount {
maxCount = count
maxNum = result
}
}
return maxNum
}
```
// XCTAssertTrue failed
func search(lst: [Int]) -> Int {
var result = -1
var dict = [Int: Int]()
for i in lst {
dict[i] = (dict[i]?? 0) + 1
}
for (key, value) in dict {
if value > key && value >= key {
result = key
}
}
return result
}
```swift
// You are given a non-empty array of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array.
// If no such a value exist, return -1.
// Examples:
// search(lst: [4, 1, 2, 2, 3, 1]) == 2
// search(lst: [1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3
// search(lst: [5, 5, 4, 4, 4]) == -1
func search(lst: [Int]) -> Int {
var result = -1
var dict = [Int: Int]()
for i in lst {
dict[i] = (dict[i]?? 0) + 1
}
for (key, value) in dict {
if value > key && value >= key {
result = key
}
}
return result
}
```
dict[i] = (dict[i]?? 0) + 1 // cannot convert value of type '(Int?, Int)' to expected argument type 'Int'
dict[i] = (dict[i]?? 0) + 1 // cannot use optional chaining on non-optional value of type 'Int'
dict[i] = (dict[i]?? 0) + 1 // expected ',' separator
func search(lst: [Int]) -> Int {
var result = -1
var max = 0
var maxCount = 0
var count = 0
var current = 0
for i in lst {
if i == current {
count += 1
} else {
if count > maxCount {
maxCount = count
max = current
}
current = i
count = 1
}
}
if count > maxCount {
maxCount = count
max = current
}
if max > 0 {
result = max
}
return result
}
```swift
// You are given a non-empty array of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array.
// If no such a value exist, return -1.
// Examples:
// search(lst: [4, 1, 2, 2, 3, 1]) == 2
// search(lst: [1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3
// search(lst: [5, 5, 4, 4, 4]) == -1
func search(lst: [Int]) -> Int {
var result = -1
var max = 0
var maxCount = 0
var count = 0
var current = 0
for i in lst {
if i == current {
count += 1
} else {
if count > maxCount {
maxCount = count
max = current
}
current = i
count = 1
}
}
if count > maxCount {
maxCount = count
max = current
}
if max > 0 {
result = max
}
return result
}
```
// XCTAssertTrue failed
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for num in lst {
dict[num, default: 0] += 1
}
var result = -1
for (key, value) in dict {
if value > key && value >= key {
result = key
}
}
return result
}
```swift
// You are given a non-empty array of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array.
// If no such a value exist, return -1.
// Examples:
// search(lst: [4, 1, 2, 2, 3, 1]) == 2
// search(lst: [1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3
// search(lst: [5, 5, 4, 4, 4]) == -1
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for num in lst {
dict[num, default: 0] += 1
}
var result = -1
for (key, value) in dict {
if value > key && value >= key {
result = key
}
}
return result
}
```
// XCTAssertTrue failed
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
dict[i, default: 0] += 1
}
for (key, value) in dict {
if value > key {
return key
}
}
return -1
}
```swift
// You are given a non-empty array of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array.
// If no such a value exist, return -1.
// Examples:
// search(lst: [4, 1, 2, 2, 3, 1]) == 2
// search(lst: [1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3
// search(lst: [5, 5, 4, 4, 4]) == -1
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
dict[i, default: 0] += 1
}
for (key, value) in dict {
if value > key {
return key
}
}
return -1
}
```
// XCTAssertTrue failed
func strangeSortList(lst: [Int]) -> [Int] {
var list = lst
var min = list.min()
var max = list.max()
var result = [Int]()
while list.count > 0 {
if let min = min {
result.append(min)
list.remove(min)
min = list.min()
}
if let max = max {
result.append(max)
list.remove(max)
max = list.max()
}
}
return result
}
```swift
// Given array of integers, return array in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// strangeSortList(lst: [1, 2, 3, 4]) == [1, 4, 2, 3]
// strangeSortList(lst: [5, 5, 5, 5]) == [5, 5, 5, 5]
// strangeSortList(lst: [] as [Int]) == [] as [Int]
func strangeSortList(lst: [Int]) -> [Int] {
var list = lst
var min = list.min()
var max = list.max()
var result = [Int]()
while list.count > 0 {
if let min = min {
result.append(min)
list.remove(min)
min = list.min()
}
if let max = max {
result.append(max)
list.remove(max)
max = list.max()
}
}
return result
}
```
list.remove(min) // no exact matches in call to instance method 'remove'
min = list.min() // cannot assign to value: 'min' is a 'let' constant
min = list.min() // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
list.remove(max) // no exact matches in call to instance method 'remove'
max = list.max() // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
max = list.max() // cannot assign to value: 'max' is a 'let' constant
func strangeSortList(lst: [Int]) -> [Int] {
// TODO: implement me
return []
}
```swift
// Given array of integers, return array in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// strangeSortList(lst: [1, 2, 3, 4]) == [1, 4, 2, 3]
// strangeSortList(lst: [5, 5, 5, 5]) == [5, 5, 5, 5]
// strangeSortList(lst: [] as [Int]) == [] as [Int]
func strangeSortList(lst: [Int]) -> [Int] {
// TODO: implement me
return []
}
```
// XCTAssertTrue failed
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var min = lst[0]
var max = lst[0]
for i in 1..<lst.count {
if lst[i] < min {
min = lst[i]
}
if lst[i] > max {
max = lst[i]
}
}
var minIndex = 0
var maxIndex = 0
for i in 0..<lst.count {
if lst[i] == min {
minIndex = i
}
if lst[i] == max {
maxIndex = i
}
}
if minIndex > maxIndex {
for i in 0..<lst.count {
if i % 2 == 0 {
result.append(lst[maxIndex])
} else {
result.append(lst[minIndex])
}
}
} else {
for i in 0..<lst.count {
if i % 2 == 0 {
result.append(lst[minIndex])
} else {
result.append(lst[maxIndex])
}
}
}
return result
}
```swift
// Given array of integers, return array in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// strangeSortList(lst: [1, 2, 3, 4]) == [1, 4, 2, 3]
// strangeSortList(lst: [5, 5, 5, 5]) == [5, 5, 5, 5]
// strangeSortList(lst: [] as [Int]) == [] as [Int]
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var min = lst[0]
var max = lst[0]
for i in 1..<lst.count {
if lst[i] < min {
min = lst[i]
}
if lst[i] > max {
max = lst[i]
}
}
var minIndex = 0
var maxIndex = 0
for i in 0..<lst.count {
if lst[i] == min {
minIndex = i
}
if lst[i] == max {
maxIndex = i
}
}
if minIndex > maxIndex {
for i in 0..<lst.count {
if i % 2 == 0 {
result.append(lst[maxIndex])
} else {
result.append(lst[minIndex])
}
}
} else {
for i in 0..<lst.count {
if i % 2 == 0 {
result.append(lst[minIndex])
} else {
result.append(lst[maxIndex])
}
}
}
return result
}
```
// XCTAssertTrue failed
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var temp = lst
while temp.count > 0 {
let min = temp.min()!
result.append(min)
temp = temp.filter { $0!= min }
let max = temp.max()!
result.append(max)
temp = temp.filter { $0!= max }
}
return result
}
```swift
// Given array of integers, return array in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// strangeSortList(lst: [1, 2, 3, 4]) == [1, 4, 2, 3]
// strangeSortList(lst: [5, 5, 5, 5]) == [5, 5, 5, 5]
// strangeSortList(lst: [] as [Int]) == [] as [Int]
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var temp = lst
while temp.count > 0 {
let min = temp.min()!
result.append(min)
temp = temp.filter { $0!= min }
let max = temp.max()!
result.append(max)
temp = temp.filter { $0!= max }
}
return result
}
```
temp = temp.filter { $0!= min } // cannot force unwrap value of non-optional type 'Int'
temp = temp.filter { $0!= min } // '=' must have consistent whitespace on both sides
temp = temp.filter { $0!= max } // cannot force unwrap value of non-optional type 'Int'
temp = temp.filter { $0!= max } // '=' must have consistent whitespace on both sides
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var min = lst[0]
var max = lst[0]
for i in 1..<lst.count {
if lst[i] < min {
min = lst[i]
}
if lst[i] > max {
max = lst[i]
}
}
var minIndex = 0
var maxIndex = 0
for i in 0..<lst.count {
if lst[i] == min {
minIndex = i
}
if lst[i] == max {
maxIndex = i
}
}
var minCount = 0
var maxCount = 0
for i in 0..<lst.count {
if i == minIndex {
minCount += 1
}
if i == maxIndex {
maxCount += 1
}
}
for _ in 0..<minCount {
result.append(min)
}
for _ in 0..<maxCount {
result.append(max)
}
return result
}
```swift
// Given array of integers, return array in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// strangeSortList(lst: [1, 2, 3, 4]) == [1, 4, 2, 3]
// strangeSortList(lst: [5, 5, 5, 5]) == [5, 5, 5, 5]
// strangeSortList(lst: [] as [Int]) == [] as [Int]
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var min = lst[0]
var max = lst[0]
for i in 1..<lst.count {
if lst[i] < min {
min = lst[i]
}
if lst[i] > max {
max = lst[i]
}
}
var minIndex = 0
var maxIndex = 0
for i in 0..<lst.count {
if lst[i] == min {
minIndex = i
}
if lst[i] == max {
maxIndex = i
}
}
var minCount = 0
var maxCount = 0
for i in 0..<lst.count {
if i == minIndex {
minCount += 1
}
if i == maxIndex {
maxCount += 1
}
}
for _ in 0..<minCount {
result.append(min)
}
for _ in 0..<maxCount {
result.append(max)
}
return result
}
```
// XCTAssertTrue failed
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var temp = lst
while temp.count > 0 {
let min = temp.min()!
let max = temp.max()!
result.append(min)
result.append(max)
temp.remove(at: temp.index(of: min)!)
temp.remove(at: temp.index(of: max)!)
}
return result
}
```swift
// Given array of integers, return array in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// strangeSortList(lst: [1, 2, 3, 4]) == [1, 4, 2, 3]
// strangeSortList(lst: [5, 5, 5, 5]) == [5, 5, 5, 5]
// strangeSortList(lst: [] as [Int]) == [] as [Int]
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var temp = lst
while temp.count > 0 {
let min = temp.min()!
let max = temp.max()!
result.append(min)
result.append(max)
temp.remove(at: temp.index(of: min)!)
temp.remove(at: temp.index(of: max)!)
}
return result
}
```
temp.remove(at: temp.index(of: min)!) // 'index(of:)' is deprecated: renamed to 'firstIndex(of:)'
temp.remove(at: temp.index(of: max)!) // 'index(of:)' is deprecated: renamed to 'firstIndex(of:)'
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func strangeSortList(lst: [Int]) -> [Int] {
// TODO: implement this function
}
```swift
// Given array of integers, return array in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// strangeSortList(lst: [1, 2, 3, 4]) == [1, 4, 2, 3]
// strangeSortList(lst: [5, 5, 5, 5]) == [5, 5, 5, 5]
// strangeSortList(lst: [] as [Int]) == [] as [Int]
func strangeSortList(lst: [Int]) -> [Int] {
// TODO: implement this function
}
```
} // missing return in global function expected to return '[Int]'
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var min = lst[0]
var max = lst[0]
for i in 1..<lst.count {
if lst[i] < min {
min = lst[i]
}
if lst[i] > max {
max = lst[i]
}
}
for i in 0..<lst.count {
if i % 2 == 0 {
result.append(min)
} else {
result.append(max)
}
}
return result
}
```swift
// Given array of integers, return array in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// strangeSortList(lst: [1, 2, 3, 4]) == [1, 4, 2, 3]
// strangeSortList(lst: [5, 5, 5, 5]) == [5, 5, 5, 5]
// strangeSortList(lst: [] as [Int]) == [] as [Int]
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var min = lst[0]
var max = lst[0]
for i in 1..<lst.count {
if lst[i] < min {
min = lst[i]
}
if lst[i] > max {
max = lst[i]
}
}
for i in 0..<lst.count {
if i % 2 == 0 {
result.append(min)
} else {
result.append(max)
}
}
return result
}
```
// XCTAssertTrue failed
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var sorted = lst.sorted()
while sorted.count > 0 {
result.append(sorted.min()!)
sorted.remove(at: sorted.firstIndex(of: sorted.min()!)!)
result.append(sorted.max()!)
sorted.remove(at: sorted.firstIndex(of: sorted.max()!)!)
}
return result
}
```swift
// Given array of integers, return array in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// strangeSortList(lst: [1, 2, 3, 4]) == [1, 4, 2, 3]
// strangeSortList(lst: [5, 5, 5, 5]) == [5, 5, 5, 5]
// strangeSortList(lst: [] as [Int]) == [] as [Int]
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var sorted = lst.sorted()
while sorted.count > 0 {
result.append(sorted.min()!)
sorted.remove(at: sorted.firstIndex(of: sorted.min()!)!)
result.append(sorted.max()!)
sorted.remove(at: sorted.firstIndex(of: sorted.max()!)!)
}
return result
}
```
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var min = lst[0]
var max = lst[0]
for i in 1..<lst.count {
if lst[i] < min {
min = lst[i]
}
if lst[i] > max {
max = lst[i]
}
}
for _ in 0..<lst.count {
if min == max {
result.append(min)
break
}
if min < max {
result.append(min)
min += 1
} else {
result.append(max)
max -= 1
}
}
return result
}
```swift
// Given array of integers, return array in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// strangeSortList(lst: [1, 2, 3, 4]) == [1, 4, 2, 3]
// strangeSortList(lst: [5, 5, 5, 5]) == [5, 5, 5, 5]
// strangeSortList(lst: [] as [Int]) == [] as [Int]
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var min = lst[0]
var max = lst[0]
for i in 1..<lst.count {
if lst[i] < min {
min = lst[i]
}
if lst[i] > max {
max = lst[i]
}
}
for _ in 0..<lst.count {
if min == max {
result.append(min)
break
}
if min < max {
result.append(min)
min += 1
} else {
result.append(max)
max -= 1
}
}
return result
}
```
// XCTAssertTrue failed
func triangleArea(a: Int, b: Int, c: Int) -> Double {
// your code here
}
```swift
// Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// triangleArea(a: 3, b: 4, c: 5) == 6.0
// triangleArea(a: 1, b: 2, c: 10) == -1
func triangleArea(a: Int, b: Int, c: Int) -> Double {
// your code here
}
```
} // missing return in global function expected to return 'Double'
func triangleArea(a: Int, b: Int, c: Int) -> Double {
// Your code here
}
```swift
// Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// triangleArea(a: 3, b: 4, c: 5) == 6.0
// triangleArea(a: 1, b: 2, c: 10) == -1
func triangleArea(a: Int, b: Int, c: Int) -> Double {
// Your code here
}
```
} // missing return in global function expected to return 'Double'
func triangleArea(a: Int, b: Int, c: Int) -> Double {
// Your code goes here
}
```swift
// Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// triangleArea(a: 3, b: 4, c: 5) == 6.0
// triangleArea(a: 1, b: 2, c: 10) == -1
func triangleArea(a: Int, b: Int, c: Int) -> Double {
// Your code goes here
}
```
} // missing return in global function expected to return 'Double'
func triangleArea(a: Int, b: Int, c: Int) -> Double {
// your code here
}
```swift
// Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// triangleArea(a: 3, b: 4, c: 5) == 6.0
// triangleArea(a: 1, b: 2, c: 10) == -1
func triangleArea(a: Int, b: Int, c: Int) -> Double {
// your code here
}
```
} // missing return in global function expected to return 'Double'
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let sides = [a, b, c]
let sorted = sides.sorted()
if sorted[0] + sorted[1] > sorted[2] {
let s = (Double(sorted[0]) + Double(sorted[1]) + Double(sorted[2])) / 2
let area = sqrt(s * (s - Double(sorted[0])) * (s - Double(sorted[1])) * (s - Double(sorted[2])))
return area
} else {
return -1
}
}
```swift
// Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// triangleArea(a: 3, b: 4, c: 5) == 6.0
// triangleArea(a: 1, b: 2, c: 10) == -1
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let sides = [a, b, c]
let sorted = sides.sorted()
if sorted[0] + sorted[1] > sorted[2] {
let s = (Double(sorted[0]) + Double(sorted[1]) + Double(sorted[2])) / 2
let area = sqrt(s * (s - Double(sorted[0])) * (s - Double(sorted[1])) * (s - Double(sorted[2])))
return area
} else {
return -1
}
}
```
// XCTAssertTrue failed
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let sides = [a, b, c]
let sorted = sides.sorted()
let sum = sorted[0] + sorted[1]
if sum > sorted[2] {
return Double(sorted[0] * sorted[1]) / 2
} else {
return -1
}
}
```swift
// Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// triangleArea(a: 3, b: 4, c: 5) == 6.0
// triangleArea(a: 1, b: 2, c: 10) == -1
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let sides = [a, b, c]
let sorted = sides.sorted()
let sum = sorted[0] + sorted[1]
if sum > sorted[2] {
return Double(sorted[0] * sorted[1]) / 2
} else {
return -1
}
}
```
// XCTAssertTrue failed
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let sides = [a, b, c]
let sortedSides = sides.sorted()
let sum = sortedSides[0] + sortedSides[1]
if sum > sortedSides[2] {
let p = (sortedSides[0] + sortedSides[1] + sortedSides[2]) / 2
let area = sqrt(p * (p - sortedSides[0]) * (p - sortedSides[1]) * (p - sortedSides[2]))
return area
} else {
return -1
}
}
```swift
// Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// triangleArea(a: 3, b: 4, c: 5) == 6.0
// triangleArea(a: 1, b: 2, c: 10) == -1
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let sides = [a, b, c]
let sortedSides = sides.sorted()
let sum = sortedSides[0] + sortedSides[1]
if sum > sortedSides[2] {
let p = (sortedSides[0] + sortedSides[1] + sortedSides[2]) / 2
let area = sqrt(p * (p - sortedSides[0]) * (p - sortedSides[1]) * (p - sortedSides[2]))
return area
} else {
return -1
}
}
```
let area = sqrt(p * (p - sortedSides[0]) * (p - sortedSides[1]) * (p - sortedSides[2])) // cannot convert value of type 'Int' to expected argument type 'Double'
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let sides = [a, b, c]
let sorted = sides.sorted()
let sum = sorted[0] + sorted[1]
if sum > sorted[2] {
let p = (sorted[0] + sorted[1] + sorted[2]) / 2.0
let area = sqrt(p * (p - Double(sorted[0])) * (p - Double(sorted[1])) * (p - Double(sorted[2])))
return area
}
return -1
}
```swift
// Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// triangleArea(a: 3, b: 4, c: 5) == 6.0
// triangleArea(a: 1, b: 2, c: 10) == -1
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let sides = [a, b, c]
let sorted = sides.sorted()
let sum = sorted[0] + sorted[1]
if sum > sorted[2] {
let p = (sorted[0] + sorted[1] + sorted[2]) / 2.0
let area = sqrt(p * (p - Double(sorted[0])) * (p - Double(sorted[1])) * (p - Double(sorted[2])))
return area
}
return -1
}
```
let p = (sorted[0] + sorted[1] + sorted[2]) / 2.0 // binary operator '/' cannot be applied to operands of type 'Int' and 'Double'
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let sides = [a, b, c]
let sorted = sides.sorted()
if sorted[0] + sorted[1] > sorted[2] {
let p = (sorted[0] + sorted[1] + sorted[2]) / 2
let area = sqrt(p * (p - Double(sorted[0])) * (p - Double(sorted[1])) * (p - Double(sorted[2])))
return area
} else {
return -1
}
}
```swift
// Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// triangleArea(a: 3, b: 4, c: 5) == 6.0
// triangleArea(a: 1, b: 2, c: 10) == -1
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let sides = [a, b, c]
let sorted = sides.sorted()
if sorted[0] + sorted[1] > sorted[2] {
let p = (sorted[0] + sorted[1] + sorted[2]) / 2
let area = sqrt(p * (p - Double(sorted[0])) * (p - Double(sorted[1])) * (p - Double(sorted[2])))
return area
} else {
return -1
}
}
```
let area = sqrt(p * (p - Double(sorted[0])) * (p - Double(sorted[1])) * (p - Double(sorted[2]))) // the compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let sides = [a, b, c]
let sorted = sides.sorted()
let sum = sorted[0] + sorted[1]
if sum > sorted[2] {
let p = (sorted[0] + sorted[1] + sorted[2]) / 2
let area = sqrt(p * (p - Double(sorted[0])) * (p - Double(sorted[1])) * (p - Double(sorted[2])))
return area
} else {
return -1
}
}
```swift
// Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// triangleArea(a: 3, b: 4, c: 5) == 6.0
// triangleArea(a: 1, b: 2, c: 10) == -1
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let sides = [a, b, c]
let sorted = sides.sorted()
let sum = sorted[0] + sorted[1]
if sum > sorted[2] {
let p = (sorted[0] + sorted[1] + sorted[2]) / 2
let area = sqrt(p * (p - Double(sorted[0])) * (p - Double(sorted[1])) * (p - Double(sorted[2])))
return area
} else {
return -1
}
}
```
let area = sqrt(p * (p - Double(sorted[0])) * (p - Double(sorted[1])) * (p - Double(sorted[2]))) // the compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
func willItFly(q: [Int], w: Int) -> Bool {
if q.count == 1 {
return q[0] <= w
}
let sum = q.reduce(0, +)
if sum > w {
return false
}
let middle = q.count / 2
let left = q[0..<middle]
let right = q[middle..<q.count]
let leftSum = left.reduce(0, +)
let rightSum = right.reduce(0, +)
return willItFly(q: Array(left), w: leftSum) && willItFly(q: Array(right), w: rightSum)
}
```swift
// Write a function that returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is a palindromic array) and the sum of its elements is less than or equal the maximum possible weight w.
// Example:
// # 1+2 is less than the maximum possible weight, but it's unbalanced.
// # it's balanced, but 3+2+3 is more than the maximum possible weight.
// # 3+2+3 is less than the maximum possible weight, and it's balanced.
// # 3 is less than the maximum possible weight, and it's balanced.
// willItFly(q: [1, 2], w: 5) == false
// willItFly(q: [3, 2, 3], w: 1) == false
// willItFly(q: [3, 2, 3], w: 9) == true
// willItFly(q: [3], w: 5) == true
func willItFly(q: [Int], w: Int) -> Bool {
if q.count == 1 {
return q[0] <= w
}
let sum = q.reduce(0, +)
if sum > w {
return false
}
let middle = q.count / 2
let left = q[0..<middle]
let right = q[middle..<q.count]
let leftSum = left.reduce(0, +)
let rightSum = right.reduce(0, +)
return willItFly(q: Array(left), w: leftSum) && willItFly(q: Array(right), w: rightSum)
}
```
// XCTAssertTrue failed
func willItFly(q: [Int], w: Int) -> Bool {
let sum = q.reduce(0, +)
let maxWeight = q.count * w
return sum <= maxWeight && q.isPalindrome
}
```swift
// Write a function that returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is a palindromic array) and the sum of its elements is less than or equal the maximum possible weight w.
// Example:
// # 1+2 is less than the maximum possible weight, but it's unbalanced.
// # it's balanced, but 3+2+3 is more than the maximum possible weight.
// # 3+2+3 is less than the maximum possible weight, and it's balanced.
// # 3 is less than the maximum possible weight, and it's balanced.
// willItFly(q: [1, 2], w: 5) == false
// willItFly(q: [3, 2, 3], w: 1) == false
// willItFly(q: [3, 2, 3], w: 9) == true
// willItFly(q: [3], w: 5) == true
func willItFly(q: [Int], w: Int) -> Bool {
let sum = q.reduce(0, +)
let maxWeight = q.count * w
return sum <= maxWeight && q.isPalindrome
}
```
return sum <= maxWeight && q.isPalindrome // value of type '[Int]' has no member 'isPalindrome'
func willItFly(q: [Int], w: Int) -> Bool {
let sum = q.reduce(0, +)
return q.count == 1 || (q.count == 2 && sum <= w) || (q.count > 2 && sum <= w && q.sorted() == q)
}
```swift
// Write a function that returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is a palindromic array) and the sum of its elements is less than or equal the maximum possible weight w.
// Example:
// # 1+2 is less than the maximum possible weight, but it's unbalanced.
// # it's balanced, but 3+2+3 is more than the maximum possible weight.
// # 3+2+3 is less than the maximum possible weight, and it's balanced.
// # 3 is less than the maximum possible weight, and it's balanced.
// willItFly(q: [1, 2], w: 5) == false
// willItFly(q: [3, 2, 3], w: 1) == false
// willItFly(q: [3, 2, 3], w: 9) == true
// willItFly(q: [3], w: 5) == true
func willItFly(q: [Int], w: Int) -> Bool {
let sum = q.reduce(0, +)
return q.count == 1 || (q.count == 2 && sum <= w) || (q.count > 2 && sum <= w && q.sorted() == q)
}
```
// XCTAssertTrue failed
func willItFly(q: [Int], w: Int) -> Bool {
let sum = q.reduce(0, +)
if sum > w {
return false
}
let reversed = q.reversed()
let reversedSum = reversed.reduce(0, +)
if sum!= reversedSum {
return false
}
return true
}
```swift
// Write a function that returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is a palindromic array) and the sum of its elements is less than or equal the maximum possible weight w.
// Example:
// # 1+2 is less than the maximum possible weight, but it's unbalanced.
// # it's balanced, but 3+2+3 is more than the maximum possible weight.
// # 3+2+3 is less than the maximum possible weight, and it's balanced.
// # 3 is less than the maximum possible weight, and it's balanced.
// willItFly(q: [1, 2], w: 5) == false
// willItFly(q: [3, 2, 3], w: 1) == false
// willItFly(q: [3, 2, 3], w: 9) == true
// willItFly(q: [3], w: 5) == true
func willItFly(q: [Int], w: Int) -> Bool {
let sum = q.reduce(0, +)
if sum > w {
return false
}
let reversed = q.reversed()
let reversedSum = reversed.reduce(0, +)
if sum!= reversedSum {
return false
}
return true
}
```
if sum!= reversedSum { // '=' must have consistent whitespace on both sides
if sum!= reversedSum { // use of '=' in a boolean context, did you mean '=='?
if sum!= reversedSum { // cannot force unwrap value of non-optional type 'Int'
func willItFly(q: [Int], w: Int) -> Bool {
let sum = q.reduce(0, +)
let max = w - sum
return q.count == 1 && q[0] <= max
}
```swift
// Write a function that returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is a palindromic array) and the sum of its elements is less than or equal the maximum possible weight w.
// Example:
// # 1+2 is less than the maximum possible weight, but it's unbalanced.
// # it's balanced, but 3+2+3 is more than the maximum possible weight.
// # 3+2+3 is less than the maximum possible weight, and it's balanced.
// # 3 is less than the maximum possible weight, and it's balanced.
// willItFly(q: [1, 2], w: 5) == false
// willItFly(q: [3, 2, 3], w: 1) == false
// willItFly(q: [3, 2, 3], w: 9) == true
// willItFly(q: [3], w: 5) == true
func willItFly(q: [Int], w: Int) -> Bool {
let sum = q.reduce(0, +)
let max = w - sum
return q.count == 1 && q[0] <= max
}
```
// XCTAssertTrue failed
func willItFly(q: [Int], w: Int) -> Bool {
let sum = q.reduce(0, +)
return q.count == 1 || (sum <= w && q.sorted() == q)
}
```swift
// Write a function that returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is a palindromic array) and the sum of its elements is less than or equal the maximum possible weight w.
// Example:
// # 1+2 is less than the maximum possible weight, but it's unbalanced.
// # it's balanced, but 3+2+3 is more than the maximum possible weight.
// # 3+2+3 is less than the maximum possible weight, and it's balanced.
// # 3 is less than the maximum possible weight, and it's balanced.
// willItFly(q: [1, 2], w: 5) == false
// willItFly(q: [3, 2, 3], w: 1) == false
// willItFly(q: [3, 2, 3], w: 9) == true
// willItFly(q: [3], w: 5) == true
func willItFly(q: [Int], w: Int) -> Bool {
let sum = q.reduce(0, +)
return q.count == 1 || (sum <= w && q.sorted() == q)
}
```
// XCTAssertTrue failed
func willItFly(q: [Int], w: Int) -> Bool {
return q.isPalindrome && q.sum() <= w
}
```swift
// Write a function that returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is a palindromic array) and the sum of its elements is less than or equal the maximum possible weight w.
// Example:
// # 1+2 is less than the maximum possible weight, but it's unbalanced.
// # it's balanced, but 3+2+3 is more than the maximum possible weight.
// # 3+2+3 is less than the maximum possible weight, and it's balanced.
// # 3 is less than the maximum possible weight, and it's balanced.
// willItFly(q: [1, 2], w: 5) == false
// willItFly(q: [3, 2, 3], w: 1) == false
// willItFly(q: [3, 2, 3], w: 9) == true
// willItFly(q: [3], w: 5) == true
func willItFly(q: [Int], w: Int) -> Bool {
return q.isPalindrome && q.sum() <= w
}
```
return q.isPalindrome && q.sum() <= w // value of type '[Int]' has no member 'sum'
return q.isPalindrome && q.sum() <= w // value of type '[Int]' has no member 'isPalindrome'
func willItFly(q: [Int], w: Int) -> Bool {
let sum = q.reduce(0, +)
let maxWeight = q.count * w
return sum <= maxWeight && q.sorted() == q
}
```swift
// Write a function that returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is a palindromic array) and the sum of its elements is less than or equal the maximum possible weight w.
// Example:
// # 1+2 is less than the maximum possible weight, but it's unbalanced.
// # it's balanced, but 3+2+3 is more than the maximum possible weight.
// # 3+2+3 is less than the maximum possible weight, and it's balanced.
// # 3 is less than the maximum possible weight, and it's balanced.
// willItFly(q: [1, 2], w: 5) == false
// willItFly(q: [3, 2, 3], w: 1) == false
// willItFly(q: [3, 2, 3], w: 9) == true
// willItFly(q: [3], w: 5) == true
func willItFly(q: [Int], w: Int) -> Bool {
let sum = q.reduce(0, +)
let maxWeight = q.count * w
return sum <= maxWeight && q.sorted() == q
}
```
// XCTAssertTrue failed
func willItFly(q: [Int], w: Int) -> Bool {
let sum = q.reduce(0, +)
if sum > w {
return false
}
let isBalanced = q.filter { $0 == q.last }.count == q.count
return isBalanced
}
```swift
// Write a function that returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is a palindromic array) and the sum of its elements is less than or equal the maximum possible weight w.
// Example:
// # 1+2 is less than the maximum possible weight, but it's unbalanced.
// # it's balanced, but 3+2+3 is more than the maximum possible weight.
// # 3+2+3 is less than the maximum possible weight, and it's balanced.
// # 3 is less than the maximum possible weight, and it's balanced.
// willItFly(q: [1, 2], w: 5) == false
// willItFly(q: [3, 2, 3], w: 1) == false
// willItFly(q: [3, 2, 3], w: 9) == true
// willItFly(q: [3], w: 5) == true
func willItFly(q: [Int], w: Int) -> Bool {
let sum = q.reduce(0, +)
if sum > w {
return false
}
let isBalanced = q.filter { $0 == q.last }.count == q.count
return isBalanced
}
```
// XCTAssertTrue failed
func willItFly(q: [Int], w: Int) -> Bool {
if q.count == 1 {
return q[0] <= w
}
let sum = q.reduce(0, +)
let max = w - sum
let sorted = q.sorted()
let first = sorted.first!
let last = sorted.last!
if first + last > max {
return false
}
var newQ = q
newQ.remove(at: 0)
newQ.remove(at: newQ.count - 1)
return willItFly(q: newQ, w: max)
}
```swift
// Write a function that returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is a palindromic array) and the sum of its elements is less than or equal the maximum possible weight w.
// Example:
// # 1+2 is less than the maximum possible weight, but it's unbalanced.
// # it's balanced, but 3+2+3 is more than the maximum possible weight.
// # 3+2+3 is less than the maximum possible weight, and it's balanced.
// # 3 is less than the maximum possible weight, and it's balanced.
// willItFly(q: [1, 2], w: 5) == false
// willItFly(q: [3, 2, 3], w: 1) == false
// willItFly(q: [3, 2, 3], w: 9) == true
// willItFly(q: [3], w: 5) == true
func willItFly(q: [Int], w: Int) -> Bool {
if q.count == 1 {
return q[0] <= w
}
let sum = q.reduce(0, +)
let max = w - sum
let sorted = q.sorted()
let first = sorted.first!
let last = sorted.last!
if first + last > max {
return false
}
var newQ = q
newQ.remove(at: 0)
newQ.remove(at: newQ.count - 1)
return willItFly(q: newQ, w: max)
}
```
// XCTAssertTrue failed
func smallestChange(arr: [Int]) -> Int {
var count = 0
var arr = arr
while!isPalindrome(arr: arr) {
arr = reverse(arr: arr)
count += 1
}
return count
}
func isPalindrome(arr: [Int]) -> Bool {
var arr = arr
for i in 0..<arr.count / 2 {
if arr[i]!= arr[arr.count - 1 - i] {
return false
}
}
return true
}
func reverse(arr: [Int]) -> [Int] {
var arr = arr
for i in 0..<arr.count / 2 {
let temp = arr[i]
arr[i] = arr[arr.count - 1 - i]
arr[arr.count - 1 - i] = temp
}
return arr
}
```swift
// Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// smallestChange(arr: [1, 2, 3, 5, 4, 7, 9, 6]) == 4
// smallestChange(arr: [1, 2, 3, 4, 3, 2, 2]) == 1
// smallestChange(arr: [1, 2, 3, 2, 1]) == 0
func smallestChange(arr: [Int]) -> Int {
var count = 0
var arr = arr
while!isPalindrome(arr: arr) {
arr = reverse(arr: arr)
count += 1
}
return count
}
func isPalindrome(arr: [Int]) -> Bool {
var arr = arr
for i in 0..<arr.count / 2 {
if arr[i]!= arr[arr.count - 1 - i] {
return false
}
}
return true
}
func reverse(arr: [Int]) -> [Int] {
var arr = arr
for i in 0..<arr.count / 2 {
let temp = arr[i]
arr[i] = arr[arr.count - 1 - i]
arr[arr.count - 1 - i] = temp
}
return arr
}
```
while!isPalindrome(arr: arr) { // expected expression, var, or let in 'while' condition
if arr[i]!= arr[arr.count - 1 - i] { // cannot force unwrap value of non-optional type 'Int'
if arr[i]!= arr[arr.count - 1 - i] { // '=' must have consistent whitespace on both sides
if arr[i]!= arr[arr.count - 1 - i] { // use of '=' in a boolean context, did you mean '=='?
func smallestChange(arr: [Int]) -> Int {
var count = 0
var arr = arr
while!isPalindrome(arr: arr) {
arr = arr.reversed()
count += 1
}
return count
}
func isPalindrome(arr: [Int]) -> Bool {
var i = 0
var j = arr.count - 1
while i < j {
if arr[i]!= arr[j] {
return false
}
i += 1
j -= 1
}
return true
}
```swift
// Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// smallestChange(arr: [1, 2, 3, 5, 4, 7, 9, 6]) == 4
// smallestChange(arr: [1, 2, 3, 4, 3, 2, 2]) == 1
// smallestChange(arr: [1, 2, 3, 2, 1]) == 0
func smallestChange(arr: [Int]) -> Int {
var count = 0
var arr = arr
while!isPalindrome(arr: arr) {
arr = arr.reversed()
count += 1
}
return count
}
func isPalindrome(arr: [Int]) -> Bool {
var i = 0
var j = arr.count - 1
while i < j {
if arr[i]!= arr[j] {
return false
}
i += 1
j -= 1
}
return true
}
```
while!isPalindrome(arr: arr) { // expected expression, var, or let in 'while' condition
if arr[i]!= arr[j] { // cannot force unwrap value of non-optional type 'Int'
if arr[i]!= arr[j] { // use of '=' in a boolean context, did you mean '=='?
if arr[i]!= arr[j] { // '=' must have consistent whitespace on both sides
func smallestChange(arr: [Int]) -> Int {
var count = 0
var arr = arr
while!isPalindrome(arr: arr) {
let index = arr.firstIndex(of: arr.max()!)!
arr[index] = arr[index] - 1
count += 1
}
return count
}
func isPalindrome(arr: [Int]) -> Bool {
let reversed = arr.reversed()
for i in 0..<arr.count {
if arr[i]!= reversed[i] {
return false
}
}
return true
}
```swift
// Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// smallestChange(arr: [1, 2, 3, 5, 4, 7, 9, 6]) == 4
// smallestChange(arr: [1, 2, 3, 4, 3, 2, 2]) == 1
// smallestChange(arr: [1, 2, 3, 2, 1]) == 0
func smallestChange(arr: [Int]) -> Int {
var count = 0
var arr = arr
while!isPalindrome(arr: arr) {
let index = arr.firstIndex(of: arr.max()!)!
arr[index] = arr[index] - 1
count += 1
}
return count
}
func isPalindrome(arr: [Int]) -> Bool {
let reversed = arr.reversed()
for i in 0..<arr.count {
if arr[i]!= reversed[i] {
return false
}
}
return true
}
```
while!isPalindrome(arr: arr) { // expected expression, var, or let in 'while' condition
if arr[i]!= reversed[i] { // cannot force unwrap value of non-optional type 'Int'
if arr[i]!= reversed[i] { // '=' must have consistent whitespace on both sides
if arr[i]!= reversed[i] { // use of '=' in a boolean context, did you mean '=='?
if arr[i]!= reversed[i] { // cannot convert value of type 'Int' to expected argument type 'ReversedCollection<[Int]>.Index'
func smallestChange(arr: [Int]) -> Int {
// TODO: Write your code here
}
```swift
// Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// smallestChange(arr: [1, 2, 3, 5, 4, 7, 9, 6]) == 4
// smallestChange(arr: [1, 2, 3, 4, 3, 2, 2]) == 1
// smallestChange(arr: [1, 2, 3, 2, 1]) == 0
func smallestChange(arr: [Int]) -> Int {
// TODO: Write your code here
}
```
} // missing return in global function expected to return 'Int'
func smallestChange(arr: [Int]) -> Int {
var count = 0
var arr = arr
var i = 0
var j = arr.count - 1
while i < j {
if arr[i]!= arr[j] {
count += 1
arr[i] = arr[j]
}
i += 1
j -= 1
}
return count
}
```swift
// Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// smallestChange(arr: [1, 2, 3, 5, 4, 7, 9, 6]) == 4
// smallestChange(arr: [1, 2, 3, 4, 3, 2, 2]) == 1
// smallestChange(arr: [1, 2, 3, 2, 1]) == 0
func smallestChange(arr: [Int]) -> Int {
var count = 0
var arr = arr
var i = 0
var j = arr.count - 1
while i < j {
if arr[i]!= arr[j] {
count += 1
arr[i] = arr[j]
}
i += 1
j -= 1
}
return count
}
```
if arr[i]!= arr[j] { // use of '=' in a boolean context, did you mean '=='?
if arr[i]!= arr[j] { // cannot force unwrap value of non-optional type 'Int'
if arr[i]!= arr[j] { // '=' must have consistent whitespace on both sides
func smallestChange(arr: [Int]) -> Int {
var count = 0
var arr = arr
while!isPalindrome(arr: arr) {
count += 1
arr.remove(at: 0)
}
return count
}
func isPalindrome(arr: [Int]) -> Bool {
var arr = arr
var reversed = [Int]()
while arr.count > 0 {
reversed.append(arr.remove(at: 0))
}
return arr == reversed
}
```swift
// Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// smallestChange(arr: [1, 2, 3, 5, 4, 7, 9, 6]) == 4
// smallestChange(arr: [1, 2, 3, 4, 3, 2, 2]) == 1
// smallestChange(arr: [1, 2, 3, 2, 1]) == 0
func smallestChange(arr: [Int]) -> Int {
var count = 0
var arr = arr
while!isPalindrome(arr: arr) {
count += 1
arr.remove(at: 0)
}
return count
}
func isPalindrome(arr: [Int]) -> Bool {
var arr = arr
var reversed = [Int]()
while arr.count > 0 {
reversed.append(arr.remove(at: 0))
}
return arr == reversed
}
```
while!isPalindrome(arr: arr) { // expected expression, var, or let in 'while' condition
func smallestChange(arr: [Int]) -> Int {
var count = 0
var arr = arr
while!isPalindrome(arr: arr) {
let first = arr.removeFirst()
let last = arr.removeLast()
arr.insert(first, at: 0)
arr.append(last)
count += 1
}
return count
}
func isPalindrome(arr: [Int]) -> Bool {
var arr = arr
var isPalindrome = true
while arr.count > 1 {
let first = arr.removeFirst()
let last = arr.removeLast()
if first!= last {
isPalindrome = false
}
}
return isPalindrome
}
```swift
// Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// smallestChange(arr: [1, 2, 3, 5, 4, 7, 9, 6]) == 4
// smallestChange(arr: [1, 2, 3, 4, 3, 2, 2]) == 1
// smallestChange(arr: [1, 2, 3, 2, 1]) == 0
func smallestChange(arr: [Int]) -> Int {
var count = 0
var arr = arr
while!isPalindrome(arr: arr) {
let first = arr.removeFirst()
let last = arr.removeLast()
arr.insert(first, at: 0)
arr.append(last)
count += 1
}
return count
}
func isPalindrome(arr: [Int]) -> Bool {
var arr = arr
var isPalindrome = true
while arr.count > 1 {
let first = arr.removeFirst()
let last = arr.removeLast()
if first!= last {
isPalindrome = false
}
}
return isPalindrome
}
```
while!isPalindrome(arr: arr) { // expected expression, var, or let in 'while' condition
if first!= last { // use of '=' in a boolean context, did you mean '=='?
if first!= last { // '=' must have consistent whitespace on both sides
if first!= last { // cannot force unwrap value of non-optional type 'Int'
func smallestChange(arr: [Int]) -> Int {
// Write your code here.
}
```swift
// Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// smallestChange(arr: [1, 2, 3, 5, 4, 7, 9, 6]) == 4
// smallestChange(arr: [1, 2, 3, 4, 3, 2, 2]) == 1
// smallestChange(arr: [1, 2, 3, 2, 1]) == 0
func smallestChange(arr: [Int]) -> Int {
// Write your code here.
}
```
} // missing return in global function expected to return 'Int'
func smallestChange(arr: [Int]) -> Int {
var count = 0
var arr = arr
while!isPalindrome(arr: arr) {
arr = arr.sorted()
count += 1
}
return count
}
func isPalindrome(arr: [Int]) -> Bool {
var arr = arr
var reversed = [Int]()
while!arr.isEmpty {
reversed.append(arr.removeLast())
}
return arr == reversed
}
```swift
// Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// smallestChange(arr: [1, 2, 3, 5, 4, 7, 9, 6]) == 4
// smallestChange(arr: [1, 2, 3, 4, 3, 2, 2]) == 1
// smallestChange(arr: [1, 2, 3, 2, 1]) == 0
func smallestChange(arr: [Int]) -> Int {
var count = 0
var arr = arr
while!isPalindrome(arr: arr) {
arr = arr.sorted()
count += 1
}
return count
}
func isPalindrome(arr: [Int]) -> Bool {
var arr = arr
var reversed = [Int]()
while!arr.isEmpty {
reversed.append(arr.removeLast())
}
return arr == reversed
}
```
while!isPalindrome(arr: arr) { // expected expression, var, or let in 'while' condition
while!arr.isEmpty { // expected expression, var, or let in 'while' condition
func smallestChange(arr: [Int]) -> Int {
var count = 0
var left = 0
var right = arr.count - 1
while left < right {
if arr[left] == arr[right] {
left += 1
right -= 1
} else {
count += 1
if arr[left] > arr[right] {
right -= 1
} else {
left += 1
}
}
}
return count
}
```swift
// Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// smallestChange(arr: [1, 2, 3, 5, 4, 7, 9, 6]) == 4
// smallestChange(arr: [1, 2, 3, 4, 3, 2, 2]) == 1
// smallestChange(arr: [1, 2, 3, 2, 1]) == 0
func smallestChange(arr: [Int]) -> Int {
var count = 0
var left = 0
var right = arr.count - 1
while left < right {
if arr[left] == arr[right] {
left += 1
right -= 1
} else {
count += 1
if arr[left] > arr[right] {
right -= 1
} else {
left += 1
}
}
}
return count
}
```
// XCTAssertTrue failed
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
// your code here
}
```swift
// Write a function that accepts two arrays of strings and returns the array that has
// total number of chars in the all strings of the array less than the other array.
// if the two arrays have the same number of chars, return the first array.
// Examples
// totalMatch(lst1: [] as [String], lst2: [] as [String]) == [] as [String]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "Hi"]) == ["hI", "Hi"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hi", "hi", "admin", "project"]) == ["hi", "admin"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "hi", "hi"]) == ["hI", "hi", "hi"]
// totalMatch(lst1: ["4"], lst2: ["1", "2", "3", "4", "5"]) == ["4"]
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
// your code here
}
```
} // missing return in global function expected to return '[String]'
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
// your code here
}
```swift
// Write a function that accepts two arrays of strings and returns the array that has
// total number of chars in the all strings of the array less than the other array.
// if the two arrays have the same number of chars, return the first array.
// Examples
// totalMatch(lst1: [] as [String], lst2: [] as [String]) == [] as [String]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "Hi"]) == ["hI", "Hi"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hi", "hi", "admin", "project"]) == ["hi", "admin"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "hi", "hi"]) == ["hI", "hi", "hi"]
// totalMatch(lst1: ["4"], lst2: ["1", "2", "3", "4", "5"]) == ["4"]
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
// your code here
}
```
} // missing return in global function expected to return '[String]'
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var result = [String]()
if lst1.count == 0 && lst2.count == 0 {
return result
}
if lst1.count == 0 {
return lst2
}
if lst2.count == 0 {
return lst1
}
var total1 = 0
var total2 = 0
for i in lst1 {
total1 += i.count
}
for i in lst2 {
total2 += i.count
}
if total1 < total2 {
return lst1
} else if total1 > total2 {
return lst2
} else {
return lst1
}
}
```swift
// Write a function that accepts two arrays of strings and returns the array that has
// total number of chars in the all strings of the array less than the other array.
// if the two arrays have the same number of chars, return the first array.
// Examples
// totalMatch(lst1: [] as [String], lst2: [] as [String]) == [] as [String]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "Hi"]) == ["hI", "Hi"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hi", "hi", "admin", "project"]) == ["hi", "admin"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "hi", "hi"]) == ["hI", "hi", "hi"]
// totalMatch(lst1: ["4"], lst2: ["1", "2", "3", "4", "5"]) == ["4"]
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var result = [String]()
if lst1.count == 0 && lst2.count == 0 {
return result
}
if lst1.count == 0 {
return lst2
}
if lst2.count == 0 {
return lst1
}
var total1 = 0
var total2 = 0
for i in lst1 {
total1 += i.count
}
for i in lst2 {
total2 += i.count
}
if total1 < total2 {
return lst1
} else if total1 > total2 {
return lst2
} else {
return lst1
}
}
```
var result = [String]() // variable 'result' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var result: [String] = []
var total1 = 0
var total2 = 0
for i in lst1 {
total1 += i.count
}
for i in lst2 {
total2 += i.count
}
if total1 < total2 {
result = lst1
} else if total1 > total2 {
result = lst2
} else {
result = lst1
}
return result
}
```swift
// Write a function that accepts two arrays of strings and returns the array that has
// total number of chars in the all strings of the array less than the other array.
// if the two arrays have the same number of chars, return the first array.
// Examples
// totalMatch(lst1: [] as [String], lst2: [] as [String]) == [] as [String]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "Hi"]) == ["hI", "Hi"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hi", "hi", "admin", "project"]) == ["hi", "admin"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "hi", "hi"]) == ["hI", "hi", "hi"]
// totalMatch(lst1: ["4"], lst2: ["1", "2", "3", "4", "5"]) == ["4"]
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var result: [String] = []
var total1 = 0
var total2 = 0
for i in lst1 {
total1 += i.count
}
for i in lst2 {
total2 += i.count
}
if total1 < total2 {
result = lst1
} else if total1 > total2 {
result = lst2
} else {
result = lst1
}
return result
}
```
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var result = [String]()
let total1 = lst1.reduce(0) { $0 + $1.count }
let total2 = lst2.reduce(0) { $0 + $1.count }
if total1 < total2 {
result = lst1
} else if total1 > total2 {
result = lst2
} else {
result = lst1
}
return result
}
```swift
// Write a function that accepts two arrays of strings and returns the array that has
// total number of chars in the all strings of the array less than the other array.
// if the two arrays have the same number of chars, return the first array.
// Examples
// totalMatch(lst1: [] as [String], lst2: [] as [String]) == [] as [String]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "Hi"]) == ["hI", "Hi"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hi", "hi", "admin", "project"]) == ["hi", "admin"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "hi", "hi"]) == ["hI", "hi", "hi"]
// totalMatch(lst1: ["4"], lst2: ["1", "2", "3", "4", "5"]) == ["4"]
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var result = [String]()
let total1 = lst1.reduce(0) { $0 + $1.count }
let total2 = lst2.reduce(0) { $0 + $1.count }
if total1 < total2 {
result = lst1
} else if total1 > total2 {
result = lst2
} else {
result = lst1
}
return result
}
```
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var result: [String] = []
var total1: Int = 0
var total2: Int = 0
for i in lst1 {
total1 += i.count
}
for i in lst2 {
total2 += i.count
}
if total1 < total2 {
return lst1
} else if total1 > total2 {
return lst2
} else {
return lst1
}
}
```swift
// Write a function that accepts two arrays of strings and returns the array that has
// total number of chars in the all strings of the array less than the other array.
// if the two arrays have the same number of chars, return the first array.
// Examples
// totalMatch(lst1: [] as [String], lst2: [] as [String]) == [] as [String]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "Hi"]) == ["hI", "Hi"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hi", "hi", "admin", "project"]) == ["hi", "admin"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "hi", "hi"]) == ["hI", "hi", "hi"]
// totalMatch(lst1: ["4"], lst2: ["1", "2", "3", "4", "5"]) == ["4"]
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var result: [String] = []
var total1: Int = 0
var total2: Int = 0
for i in lst1 {
total1 += i.count
}
for i in lst2 {
total2 += i.count
}
if total1 < total2 {
return lst1
} else if total1 > total2 {
return lst2
} else {
return lst1
}
}
```
var result: [String] = [] // variable 'result' was never used; consider replacing with '_' or removing it
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var result: [String] = []
var total1: Int = 0
var total2: Int = 0
for i in lst1 {
total1 += i.count
}
for i in lst2 {
total2 += i.count
}
if total1 < total2 {
result = lst1
} else if total1 > total2 {
result = lst2
} else {
result = lst1
}
return result
}
```swift
// Write a function that accepts two arrays of strings and returns the array that has
// total number of chars in the all strings of the array less than the other array.
// if the two arrays have the same number of chars, return the first array.
// Examples
// totalMatch(lst1: [] as [String], lst2: [] as [String]) == [] as [String]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "Hi"]) == ["hI", "Hi"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hi", "hi", "admin", "project"]) == ["hi", "admin"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "hi", "hi"]) == ["hI", "hi", "hi"]
// totalMatch(lst1: ["4"], lst2: ["1", "2", "3", "4", "5"]) == ["4"]
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var result: [String] = []
var total1: Int = 0
var total2: Int = 0
for i in lst1 {
total1 += i.count
}
for i in lst2 {
total2 += i.count
}
if total1 < total2 {
result = lst1
} else if total1 > total2 {
result = lst2
} else {
result = lst1
}
return result
}
```
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var result: [String] = []
var sum1: Int = 0
var sum2: Int = 0
for i in lst1 {
sum1 += i.count
}
for i in lst2 {
sum2 += i.count
}
if sum1 < sum2 {
result = lst1
} else if sum1 > sum2 {
result = lst2
} else {
result = lst1
}
return result
}
```swift
// Write a function that accepts two arrays of strings and returns the array that has
// total number of chars in the all strings of the array less than the other array.
// if the two arrays have the same number of chars, return the first array.
// Examples
// totalMatch(lst1: [] as [String], lst2: [] as [String]) == [] as [String]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "Hi"]) == ["hI", "Hi"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hi", "hi", "admin", "project"]) == ["hi", "admin"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "hi", "hi"]) == ["hI", "hi", "hi"]
// totalMatch(lst1: ["4"], lst2: ["1", "2", "3", "4", "5"]) == ["4"]
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var result: [String] = []
var sum1: Int = 0
var sum2: Int = 0
for i in lst1 {
sum1 += i.count
}
for i in lst2 {
sum2 += i.count
}
if sum1 < sum2 {
result = lst1
} else if sum1 > sum2 {
result = lst2
} else {
result = lst1
}
return result
}
```
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
// your code here
}
```swift
// Write a function that accepts two arrays of strings and returns the array that has
// total number of chars in the all strings of the array less than the other array.
// if the two arrays have the same number of chars, return the first array.
// Examples
// totalMatch(lst1: [] as [String], lst2: [] as [String]) == [] as [String]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "Hi"]) == ["hI", "Hi"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hi", "hi", "admin", "project"]) == ["hi", "admin"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "hi", "hi"]) == ["hI", "hi", "hi"]
// totalMatch(lst1: ["4"], lst2: ["1", "2", "3", "4", "5"]) == ["4"]
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
// your code here
}
```
} // missing return in global function expected to return '[String]'
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var result: [String] = []
var total1: Int = 0
var total2: Int = 0
for str in lst1 {
total1 += str.count
}
for str in lst2 {
total2 += str.count
}
if total1 < total2 {
return lst1
} else if total1 > total2 {
return lst2
} else {
return lst1
}
}
```swift
// Write a function that accepts two arrays of strings and returns the array that has
// total number of chars in the all strings of the array less than the other array.
// if the two arrays have the same number of chars, return the first array.
// Examples
// totalMatch(lst1: [] as [String], lst2: [] as [String]) == [] as [String]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "Hi"]) == ["hI", "Hi"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hi", "hi", "admin", "project"]) == ["hi", "admin"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "hi", "hi"]) == ["hI", "hi", "hi"]
// totalMatch(lst1: ["4"], lst2: ["1", "2", "3", "4", "5"]) == ["4"]
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var result: [String] = []
var total1: Int = 0
var total2: Int = 0
for str in lst1 {
total1 += str.count
}
for str in lst2 {
total2 += str.count
}
if total1 < total2 {
return lst1
} else if total1 > total2 {
return lst2
} else {
return lst1
}
}
```
var result: [String] = [] // variable 'result' was never used; consider replacing with '_' or removing it
func isMultiplyPrime(a: Int) -> Bool {
// Write your code here
}
```swift
// Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// 30 = 2 * 3 * 5
// isMultiplyPrime(a: 30) == true
func isMultiplyPrime(a: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isMultiplyPrime(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// 30 = 2 * 3 * 5
// isMultiplyPrime(a: 30) == true
func isMultiplyPrime(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isMultiplyPrime(a: Int) -> Bool {
// Your code here
}
```swift
// Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// 30 = 2 * 3 * 5
// isMultiplyPrime(a: 30) == true
func isMultiplyPrime(a: Int) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func isMultiplyPrime(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// 30 = 2 * 3 * 5
// isMultiplyPrime(a: 30) == true
func isMultiplyPrime(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isMultiplyPrime(a: Int) -> Bool {
// Write your code here
}
```swift
// Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// 30 = 2 * 3 * 5
// isMultiplyPrime(a: 30) == true
func isMultiplyPrime(a: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isMultiplyPrime(a: Int) -> Bool {
return false
}
```swift
// Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// 30 = 2 * 3 * 5
// isMultiplyPrime(a: 30) == true
func isMultiplyPrime(a: Int) -> Bool {
return false
}
```
// XCTAssertTrue failed
func isMultiplyPrime(a: Int) -> Bool {
// Write your code here
}
```swift
// Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// 30 = 2 * 3 * 5
// isMultiplyPrime(a: 30) == true
func isMultiplyPrime(a: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isMultiplyPrime(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// 30 = 2 * 3 * 5
// isMultiplyPrime(a: 30) == true
func isMultiplyPrime(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isMultiplyPrime(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// 30 = 2 * 3 * 5
// isMultiplyPrime(a: 30) == true
func isMultiplyPrime(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isMultiplyPrime(a: Int) -> Bool {
return true
}
```swift
// Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// 30 = 2 * 3 * 5
// isMultiplyPrime(a: 30) == true
func isMultiplyPrime(a: Int) -> Bool {
return true
}
```
// XCTAssertTrue failed
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```swift
// Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// isSimplePower(x: 1, n: 4) == true
// isSimplePower(x: 2, n: 2) == true
// isSimplePower(x: 8, n: 2) == true
// isSimplePower(x: 3, n: 2) == false
// isSimplePower(x: 3, n: 1) == false
// isSimplePower(x: 5, n: 3) == false
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```swift
// Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// isSimplePower(x: 1, n: 4) == true
// isSimplePower(x: 2, n: 2) == true
// isSimplePower(x: 8, n: 2) == true
// isSimplePower(x: 3, n: 2) == false
// isSimplePower(x: 3, n: 1) == false
// isSimplePower(x: 5, n: 3) == false
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```swift
// Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// isSimplePower(x: 1, n: 4) == true
// isSimplePower(x: 2, n: 2) == true
// isSimplePower(x: 8, n: 2) == true
// isSimplePower(x: 3, n: 2) == false
// isSimplePower(x: 3, n: 1) == false
// isSimplePower(x: 5, n: 3) == false
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```swift
// Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// isSimplePower(x: 1, n: 4) == true
// isSimplePower(x: 2, n: 2) == true
// isSimplePower(x: 8, n: 2) == true
// isSimplePower(x: 3, n: 2) == false
// isSimplePower(x: 3, n: 1) == false
// isSimplePower(x: 5, n: 3) == false
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSimplePower(x: Int, n: Int) -> Bool {
return true
}
```swift
// Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// isSimplePower(x: 1, n: 4) == true
// isSimplePower(x: 2, n: 2) == true
// isSimplePower(x: 8, n: 2) == true
// isSimplePower(x: 3, n: 2) == false
// isSimplePower(x: 3, n: 1) == false
// isSimplePower(x: 5, n: 3) == false
func isSimplePower(x: Int, n: Int) -> Bool {
return true
}
```
// XCTAssertTrue failed
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```swift
// Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// isSimplePower(x: 1, n: 4) == true
// isSimplePower(x: 2, n: 2) == true
// isSimplePower(x: 8, n: 2) == true
// isSimplePower(x: 3, n: 2) == false
// isSimplePower(x: 3, n: 1) == false
// isSimplePower(x: 5, n: 3) == false
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```swift
// Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// isSimplePower(x: 1, n: 4) == true
// isSimplePower(x: 2, n: 2) == true
// isSimplePower(x: 8, n: 2) == true
// isSimplePower(x: 3, n: 2) == false
// isSimplePower(x: 3, n: 1) == false
// isSimplePower(x: 5, n: 3) == false
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```swift
// Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// isSimplePower(x: 1, n: 4) == true
// isSimplePower(x: 2, n: 2) == true
// isSimplePower(x: 8, n: 2) == true
// isSimplePower(x: 3, n: 2) == false
// isSimplePower(x: 3, n: 1) == false
// isSimplePower(x: 5, n: 3) == false
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSimplePower(x: Int, n: Int) -> Bool {
return true
}
```swift
// Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// isSimplePower(x: 1, n: 4) == true
// isSimplePower(x: 2, n: 2) == true
// isSimplePower(x: 8, n: 2) == true
// isSimplePower(x: 3, n: 2) == false
// isSimplePower(x: 3, n: 1) == false
// isSimplePower(x: 5, n: 3) == false
func isSimplePower(x: Int, n: Int) -> Bool {
return true
}
```
// XCTAssertTrue failed
func isSimplePower(x: Int, n: Int) -> Bool {
return true
}
```swift
// Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// isSimplePower(x: 1, n: 4) == true
// isSimplePower(x: 2, n: 2) == true
// isSimplePower(x: 8, n: 2) == true
// isSimplePower(x: 3, n: 2) == false
// isSimplePower(x: 3, n: 1) == false
// isSimplePower(x: 5, n: 3) == false
func isSimplePower(x: Int, n: Int) -> Bool {
return true
}
```
// XCTAssertTrue failed
func iscube(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that takes an integer a and returns true
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// iscube(a: 1) == true
// iscube(a: 2) == false
// iscube(a: -1) == true
// iscube(a: 64) == true
// iscube(a: 0) == true
// iscube(a: 180) == false
func iscube(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func iscube(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that takes an integer a and returns true
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// iscube(a: 1) == true
// iscube(a: 2) == false
// iscube(a: -1) == true
// iscube(a: 64) == true
// iscube(a: 0) == true
// iscube(a: 180) == false
func iscube(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func iscube(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that takes an integer a and returns true
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// iscube(a: 1) == true
// iscube(a: 2) == false
// iscube(a: -1) == true
// iscube(a: 64) == true
// iscube(a: 0) == true
// iscube(a: 180) == false
func iscube(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func iscube(a: Int) -> Bool {
return true
}
```swift
// Write a function that takes an integer a and returns true
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// iscube(a: 1) == true
// iscube(a: 2) == false
// iscube(a: -1) == true
// iscube(a: 64) == true
// iscube(a: 0) == true
// iscube(a: 180) == false
func iscube(a: Int) -> Bool {
return true
}
```
// XCTAssertTrue failed
func iscube(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that takes an integer a and returns true
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// iscube(a: 1) == true
// iscube(a: 2) == false
// iscube(a: -1) == true
// iscube(a: 64) == true
// iscube(a: 0) == true
// iscube(a: 180) == false
func iscube(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func iscube(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that takes an integer a and returns true
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// iscube(a: 1) == true
// iscube(a: 2) == false
// iscube(a: -1) == true
// iscube(a: 64) == true
// iscube(a: 0) == true
// iscube(a: 180) == false
func iscube(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func iscube(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that takes an integer a and returns true
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// iscube(a: 1) == true
// iscube(a: 2) == false
// iscube(a: -1) == true
// iscube(a: 64) == true
// iscube(a: 0) == true
// iscube(a: 180) == false
func iscube(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func iscube(a: Int) -> Bool {
return true
}
```swift
// Write a function that takes an integer a and returns true
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// iscube(a: 1) == true
// iscube(a: 2) == false
// iscube(a: -1) == true
// iscube(a: 64) == true
// iscube(a: 0) == true
// iscube(a: 180) == false
func iscube(a: Int) -> Bool {
return true
}
```
// XCTAssertTrue failed
func iscube(a: Int) -> Bool {
return false
}
```swift
// Write a function that takes an integer a and returns true
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// iscube(a: 1) == true
// iscube(a: 2) == false
// iscube(a: -1) == true
// iscube(a: 64) == true
// iscube(a: 0) == true
// iscube(a: 180) == false
func iscube(a: Int) -> Bool {
return false
}
```
// XCTAssertTrue failed
func iscube(a: Int) -> Bool {
return true
}
```swift
// Write a function that takes an integer a and returns true
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// iscube(a: 1) == true
// iscube(a: 2) == false
// iscube(a: -1) == true
// iscube(a: 64) == true
// iscube(a: 0) == true
// iscube(a: 180) == false
func iscube(a: Int) -> Bool {
return true
}
```
// XCTAssertTrue failed
func hexKey(num: String) -> Int {
var count = 0
let primes = [2, 3, 5, 7, 11, 13]
for char in num {
if let digit = Int(String(char)) {
if primes.contains(digit) {
count += 1
}
} else {
switch char {
case "A":
count += 1
case "B":
count += 11
case "C":
count += 13
case "D":
count += 13
case "E":
count += 17
case "F":
count += 17
default:
break
}
}
}
return count
}
```swift
// You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// hexKey(num: "AB") == 1
// hexKey(num: "1077E") == 2
// hexKey(num: "ABED1A33") == 4
// hexKey(num: "123456789ABCDEF0") == 6
// hexKey(num: "2020") == 2
func hexKey(num: String) -> Int {
var count = 0
let primes = [2, 3, 5, 7, 11, 13]
for char in num {
if let digit = Int(String(char)) {
if primes.contains(digit) {
count += 1
}
} else {
switch char {
case "A":
count += 1
case "B":
count += 11
case "C":
count += 13
case "D":
count += 13
case "E":
count += 17
case "F":
count += 17
default:
break
}
}
}
return count
}
```
// XCTAssertTrue failed
func hexKey(num: String) -> Int {
var count = 0
for char in num {
if char == "A" || char == "B" || char == "C" || char == "D" || char == "E" || char == "F" {
count += 1
}
}
return count
}
```swift
// You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// hexKey(num: "AB") == 1
// hexKey(num: "1077E") == 2
// hexKey(num: "ABED1A33") == 4
// hexKey(num: "123456789ABCDEF0") == 6
// hexKey(num: "2020") == 2
func hexKey(num: String) -> Int {
var count = 0
for char in num {
if char == "A" || char == "B" || char == "C" || char == "D" || char == "E" || char == "F" {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func hexKey(num: String) -> Int {
var count = 0
let primes = [2, 3, 5, 7, 11, 13]
for char in num {
if primes.contains(Int(String(char), radix: 16)!) {
count += 1
}
}
return count
}
```swift
// You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// hexKey(num: "AB") == 1
// hexKey(num: "1077E") == 2
// hexKey(num: "ABED1A33") == 4
// hexKey(num: "123456789ABCDEF0") == 6
// hexKey(num: "2020") == 2
func hexKey(num: String) -> Int {
var count = 0
let primes = [2, 3, 5, 7, 11, 13]
for char in num {
if primes.contains(Int(String(char), radix: 16)!) {
count += 1
}
}
return count
}
```
func hexKey(num: String) -> Int {
var count = 0
let hex = ["2", "3", "5", "7", "B", "D"]
for i in num {
if hex.contains(String(i)) {
count += 1
}
}
return count
}
```swift
// You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// hexKey(num: "AB") == 1
// hexKey(num: "1077E") == 2
// hexKey(num: "ABED1A33") == 4
// hexKey(num: "123456789ABCDEF0") == 6
// hexKey(num: "2020") == 2
func hexKey(num: String) -> Int {
var count = 0
let hex = ["2", "3", "5", "7", "B", "D"]
for i in num {
if hex.contains(String(i)) {
count += 1
}
}
return count
}
```
func hexKey(num: String) -> Int {
var count = 0
for char in num {
switch char {
case "2", "3", "5", "7", "B", "D":
count += 1
default:
break
}
}
return count
}
```swift
// You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// hexKey(num: "AB") == 1
// hexKey(num: "1077E") == 2
// hexKey(num: "ABED1A33") == 4
// hexKey(num: "123456789ABCDEF0") == 6
// hexKey(num: "2020") == 2
func hexKey(num: String) -> Int {
var count = 0
for char in num {
switch char {
case "2", "3", "5", "7", "B", "D":
count += 1
default:
break
}
}
return count
}
```
func hexKey(num: String) -> Int {
let hex = ["0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, "A": 10, "B": 11, "C": 12, "D": 13, "E": 14, "F": 15]
var count = 0
for char in num {
if hex[String(char)]! % 2 == 0 {
count += 1
}
}
return count
}
```swift
// You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// hexKey(num: "AB") == 1
// hexKey(num: "1077E") == 2
// hexKey(num: "ABED1A33") == 4
// hexKey(num: "123456789ABCDEF0") == 6
// hexKey(num: "2020") == 2
func hexKey(num: String) -> Int {
let hex = ["0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, "A": 10, "B": 11, "C": 12, "D": 13, "E": 14, "F": 15]
var count = 0
for char in num {
if hex[String(char)]! % 2 == 0 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func hexKey(num: String) -> Int {
var count = 0
for char in num {
switch char {
case "2", "3", "5", "7", "B", "D":
count += 1
default:
break
}
}
return count
}
```swift
// You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// hexKey(num: "AB") == 1
// hexKey(num: "1077E") == 2
// hexKey(num: "ABED1A33") == 4
// hexKey(num: "123456789ABCDEF0") == 6
// hexKey(num: "2020") == 2
func hexKey(num: String) -> Int {
var count = 0
for char in num {
switch char {
case "2", "3", "5", "7", "B", "D":
count += 1
default:
break
}
}
return count
}
```
func hexKey(num: String) -> Int {
var count = 0
for char in num {
if char == "2" || char == "3" || char == "5" || char == "7" || char == "B" || char == "D" {
count += 1
}
}
return count
}
```swift
// You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// hexKey(num: "AB") == 1
// hexKey(num: "1077E") == 2
// hexKey(num: "ABED1A33") == 4
// hexKey(num: "123456789ABCDEF0") == 6
// hexKey(num: "2020") == 2
func hexKey(num: String) -> Int {
var count = 0
for char in num {
if char == "2" || char == "3" || char == "5" || char == "7" || char == "B" || char == "D" {
count += 1
}
}
return count
}
```
func hexKey(num: String) -> Int {
let hex = ["0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, "A": 10, "B": 11, "C": 12, "D": 13, "E": 14, "F": 15]
var count = 0
for char in num {
if hex[String(char)]! % 2 == 0 {
count += 1
}
}
return count
}
```swift
// You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// hexKey(num: "AB") == 1
// hexKey(num: "1077E") == 2
// hexKey(num: "ABED1A33") == 4
// hexKey(num: "123456789ABCDEF0") == 6
// hexKey(num: "2020") == 2
func hexKey(num: String) -> Int {
let hex = ["0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, "A": 10, "B": 11, "C": 12, "D": 13, "E": 14, "F": 15]
var count = 0
for char in num {
if hex[String(char)]! % 2 == 0 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func hexKey(num: String) -> Int {
let hex = "0123456789ABCDEF"
var count = 0
for char in num {
if hex.contains(char) {
count += 1
}
}
return count
}
```swift
// You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// hexKey(num: "AB") == 1
// hexKey(num: "1077E") == 2
// hexKey(num: "ABED1A33") == 4
// hexKey(num: "123456789ABCDEF0") == 6
// hexKey(num: "2020") == 2
func hexKey(num: String) -> Int {
let hex = "0123456789ABCDEF"
var count = 0
for char in num {
if hex.contains(char) {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func decimalToBinary(decimal: Int) -> String {
var result = ""
var remainder = decimal
while remainder > 0 {
result = "\(remainder % 2)" + result
remainder /= 2
}
return "db" + result + "db"
}
```swift
// You will be given a number in decimal form and your task is to convert it to
// binary format. The function should return a string, with each character representing a binary
// number. Each character in the string will be '0' or '1'.
// There will be an extra couple of characters 'db' at the beginning and at the end of the string.
// The extra characters are there to help with the format.
// Examples:
// decimalToBinary(decimal: 15) == "db1111db"
// decimalToBinary(decimal: 32) == "db100000db"
func decimalToBinary(decimal: Int) -> String {
var result = ""
var remainder = decimal
while remainder > 0 {
result = "\(remainder % 2)" + result
remainder /= 2
}
return "db" + result + "db"
}
```
// XCTAssertTrue failed
func decimalToBinary(decimal: Int) -> String {
var binary = ""
var decimal = decimal
while decimal > 0 {
binary = "\(decimal % 2)" + binary
decimal /= 2
}
return "db" + binary + "db"
}
```swift
// You will be given a number in decimal form and your task is to convert it to
// binary format. The function should return a string, with each character representing a binary
// number. Each character in the string will be '0' or '1'.
// There will be an extra couple of characters 'db' at the beginning and at the end of the string.
// The extra characters are there to help with the format.
// Examples:
// decimalToBinary(decimal: 15) == "db1111db"
// decimalToBinary(decimal: 32) == "db100000db"
func decimalToBinary(decimal: Int) -> String {
var binary = ""
var decimal = decimal
while decimal > 0 {
binary = "\(decimal % 2)" + binary
decimal /= 2
}
return "db" + binary + "db"
}
```
// XCTAssertTrue failed
func decimalToBinary(decimal: Int) -> String {
var binary = ""
var decimal = decimal
while decimal > 0 {
binary = "\(decimal % 2)\(binary)"
decimal /= 2
}
return "db\(binary)db"
}
```swift
// You will be given a number in decimal form and your task is to convert it to
// binary format. The function should return a string, with each character representing a binary
// number. Each character in the string will be '0' or '1'.
// There will be an extra couple of characters 'db' at the beginning and at the end of the string.
// The extra characters are there to help with the format.
// Examples:
// decimalToBinary(decimal: 15) == "db1111db"
// decimalToBinary(decimal: 32) == "db100000db"
func decimalToBinary(decimal: Int) -> String {
var binary = ""
var decimal = decimal
while decimal > 0 {
binary = "\(decimal % 2)\(binary)"
decimal /= 2
}
return "db\(binary)db"
}
```
// XCTAssertTrue failed
func decimalToBinary(decimal: Int) -> String {
var binary = ""
var decimal = decimal
while decimal > 0 {
binary = "\(decimal % 2)" + binary
decimal /= 2
}
return "db" + binary + "db"
}
```swift
// You will be given a number in decimal form and your task is to convert it to
// binary format. The function should return a string, with each character representing a binary
// number. Each character in the string will be '0' or '1'.
// There will be an extra couple of characters 'db' at the beginning and at the end of the string.
// The extra characters are there to help with the format.
// Examples:
// decimalToBinary(decimal: 15) == "db1111db"
// decimalToBinary(decimal: 32) == "db100000db"
func decimalToBinary(decimal: Int) -> String {
var binary = ""
var decimal = decimal
while decimal > 0 {
binary = "\(decimal % 2)" + binary
decimal /= 2
}
return "db" + binary + "db"
}
```
// XCTAssertTrue failed
func decimalToBinary(decimal: Int) -> String {
var result = ""
var number = decimal
while number > 0 {
result = "\(number % 2)\(result)"
number /= 2
}
return "db\(result)db"
}
```swift
// You will be given a number in decimal form and your task is to convert it to
// binary format. The function should return a string, with each character representing a binary
// number. Each character in the string will be '0' or '1'.
// There will be an extra couple of characters 'db' at the beginning and at the end of the string.
// The extra characters are there to help with the format.
// Examples:
// decimalToBinary(decimal: 15) == "db1111db"
// decimalToBinary(decimal: 32) == "db100000db"
func decimalToBinary(decimal: Int) -> String {
var result = ""
var number = decimal
while number > 0 {
result = "\(number % 2)\(result)"
number /= 2
}
return "db\(result)db"
}
```
// XCTAssertTrue failed
func decimalToBinary(decimal: Int) -> String {
return ""
}
```swift
// You will be given a number in decimal form and your task is to convert it to
// binary format. The function should return a string, with each character representing a binary
// number. Each character in the string will be '0' or '1'.
// There will be an extra couple of characters 'db' at the beginning and at the end of the string.
// The extra characters are there to help with the format.
// Examples:
// decimalToBinary(decimal: 15) == "db1111db"
// decimalToBinary(decimal: 32) == "db100000db"
func decimalToBinary(decimal: Int) -> String {
return ""
}
```
// XCTAssertTrue failed
func decimalToBinary(decimal: Int) -> String {
var binary = ""
var decimal = decimal
while decimal > 0 {
binary = "\(decimal % 2)" + binary
decimal /= 2
}
return "db" + binary + "db"
}
```swift
// You will be given a number in decimal form and your task is to convert it to
// binary format. The function should return a string, with each character representing a binary
// number. Each character in the string will be '0' or '1'.
// There will be an extra couple of characters 'db' at the beginning and at the end of the string.
// The extra characters are there to help with the format.
// Examples:
// decimalToBinary(decimal: 15) == "db1111db"
// decimalToBinary(decimal: 32) == "db100000db"
func decimalToBinary(decimal: Int) -> String {
var binary = ""
var decimal = decimal
while decimal > 0 {
binary = "\(decimal % 2)" + binary
decimal /= 2
}
return "db" + binary + "db"
}
```
// XCTAssertTrue failed
func decimalToBinary(decimal: Int) -> String {
var result = ""
var decimal = decimal
while decimal > 0 {
result = "\(decimal % 2)" + result
decimal /= 2
}
return "db" + result + "db"
}
```swift
// You will be given a number in decimal form and your task is to convert it to
// binary format. The function should return a string, with each character representing a binary
// number. Each character in the string will be '0' or '1'.
// There will be an extra couple of characters 'db' at the beginning and at the end of the string.
// The extra characters are there to help with the format.
// Examples:
// decimalToBinary(decimal: 15) == "db1111db"
// decimalToBinary(decimal: 32) == "db100000db"
func decimalToBinary(decimal: Int) -> String {
var result = ""
var decimal = decimal
while decimal > 0 {
result = "\(decimal % 2)" + result
decimal /= 2
}
return "db" + result + "db"
}
```
// XCTAssertTrue failed
func decimalToBinary(decimal: Int) -> String {
var binary = ""
var decimal = decimal
while decimal > 0 {
binary = "\(decimal % 2)" + binary
decimal /= 2
}
return "db" + binary + "db"
}
```swift
// You will be given a number in decimal form and your task is to convert it to
// binary format. The function should return a string, with each character representing a binary
// number. Each character in the string will be '0' or '1'.
// There will be an extra couple of characters 'db' at the beginning and at the end of the string.
// The extra characters are there to help with the format.
// Examples:
// decimalToBinary(decimal: 15) == "db1111db"
// decimalToBinary(decimal: 32) == "db100000db"
func decimalToBinary(decimal: Int) -> String {
var binary = ""
var decimal = decimal
while decimal > 0 {
binary = "\(decimal % 2)" + binary
decimal /= 2
}
return "db" + binary + "db"
}
```
// XCTAssertTrue failed
func decimalToBinary(decimal: Int) -> String {
var binary = ""
var decimal = decimal
while decimal > 0 {
binary = "\(decimal % 2)" + binary
decimal /= 2
}
return "db" + binary + "db"
}
```swift
// You will be given a number in decimal form and your task is to convert it to
// binary format. The function should return a string, with each character representing a binary
// number. Each character in the string will be '0' or '1'.
// There will be an extra couple of characters 'db' at the beginning and at the end of the string.
// The extra characters are there to help with the format.
// Examples:
// decimalToBinary(decimal: 15) == "db1111db"
// decimalToBinary(decimal: 32) == "db100000db"
func decimalToBinary(decimal: Int) -> String {
var binary = ""
var decimal = decimal
while decimal > 0 {
binary = "\(decimal % 2)" + binary
decimal /= 2
}
return "db" + binary + "db"
}
```
// XCTAssertTrue failed
func isHappy(s: String) -> Bool {
// your code here
}
```swift
// You are given a string s.
// Your task is to check if the string is hapswift or not.
// A string is hapswift if its length is at least 3 and every 3 consecutive letters are distinct
// For example:
// isHappy(s: "a") == false
// isHappy(s: "aa") == false
// isHappy(s: "abcd") == true
// isHappy(s: "aabb") == false
// isHappy(s: "adb") == true
// isHappy(s: "xyy") == false
func isHappy(s: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isHappy(s: String) -> Bool {
if s.count < 3 {
return false
}
let s = Array(s)
for i in 0..<s.count - 2 {
if s[i] == s[i+1] && s[i] == s[i+2] {
return false
}
}
return true
}
```swift
// You are given a string s.
// Your task is to check if the string is hapswift or not.
// A string is hapswift if its length is at least 3 and every 3 consecutive letters are distinct
// For example:
// isHappy(s: "a") == false
// isHappy(s: "aa") == false
// isHappy(s: "abcd") == true
// isHappy(s: "aabb") == false
// isHappy(s: "adb") == true
// isHappy(s: "xyy") == false
func isHappy(s: String) -> Bool {
if s.count < 3 {
return false
}
let s = Array(s)
for i in 0..<s.count - 2 {
if s[i] == s[i+1] && s[i] == s[i+2] {
return false
}
}
return true
}
```
// XCTAssertTrue failed
func isHappy(s: String) -> Bool {
guard s.count >= 3 else { return false }
var set = Set<Character>()
for i in 0..<s.count - 2 {
let sub = s[i..<i+3]
if set.contains(sub) { return false }
set.insert(sub)
}
return true
}
```swift
// You are given a string s.
// Your task is to check if the string is hapswift or not.
// A string is hapswift if its length is at least 3 and every 3 consecutive letters are distinct
// For example:
// isHappy(s: "a") == false
// isHappy(s: "aa") == false
// isHappy(s: "abcd") == true
// isHappy(s: "aabb") == false
// isHappy(s: "adb") == true
// isHappy(s: "xyy") == false
func isHappy(s: String) -> Bool {
guard s.count >= 3 else { return false }
var set = Set<Character>()
for i in 0..<s.count - 2 {
let sub = s[i..<i+3]
if set.contains(sub) { return false }
set.insert(sub)
}
return true
}
```
let sub = s[i..<i+3] // 'subscript(_:)' is unavailable: cannot subscript String with an integer range, use a String.Index range instead.
set.insert(sub) // cannot convert value of type 'String' to expected argument type 'Character'
func isHappy(s: String) -> Bool {
let s = s.characters.map { String($0) }
var seen = Set<String>()
var current = s
while true {
if seen.contains(current) {
return false
}
seen.insert(current)
var next = [String]()
for i in 0..<current.count - 2 {
next.append(current[i...i+2].joined())
}
current = next
}
}
```swift
// You are given a string s.
// Your task is to check if the string is hapswift or not.
// A string is hapswift if its length is at least 3 and every 3 consecutive letters are distinct
// For example:
// isHappy(s: "a") == false
// isHappy(s: "aa") == false
// isHappy(s: "abcd") == true
// isHappy(s: "aabb") == false
// isHappy(s: "adb") == true
// isHappy(s: "xyy") == false
func isHappy(s: String) -> Bool {
let s = s.characters.map { String($0) }
var seen = Set<String>()
var current = s
while true {
if seen.contains(current) {
return false
}
seen.insert(current)
var next = [String]()
for i in 0..<current.count - 2 {
next.append(current[i...i+2].joined())
}
current = next
}
}
```
let s = s.characters.map { String($0) } // 'characters' is unavailable: Please use String directly
seen.insert(current) // cannot convert value of type '[String]' to expected argument type 'String'
func isHappy(s: String) -> Bool {
var s = s
while s.count >= 3 {
let first = s.removeFirst()
let second = s.removeFirst()
let third = s.removeFirst()
if first == second || first == third || second == third {
return false
}
}
return true
}
```swift
// You are given a string s.
// Your task is to check if the string is hapswift or not.
// A string is hapswift if its length is at least 3 and every 3 consecutive letters are distinct
// For example:
// isHappy(s: "a") == false
// isHappy(s: "aa") == false
// isHappy(s: "abcd") == true
// isHappy(s: "aabb") == false
// isHappy(s: "adb") == true
// isHappy(s: "xyy") == false
func isHappy(s: String) -> Bool {
var s = s
while s.count >= 3 {
let first = s.removeFirst()
let second = s.removeFirst()
let third = s.removeFirst()
if first == second || first == third || second == third {
return false
}
}
return true
}
```
// XCTAssertTrue failed
func isHappy(s: String) -> Bool {
// Your code goes here
}
```swift
// You are given a string s.
// Your task is to check if the string is hapswift or not.
// A string is hapswift if its length is at least 3 and every 3 consecutive letters are distinct
// For example:
// isHappy(s: "a") == false
// isHappy(s: "aa") == false
// isHappy(s: "abcd") == true
// isHappy(s: "aabb") == false
// isHappy(s: "adb") == true
// isHappy(s: "xyy") == false
func isHappy(s: String) -> Bool {
// Your code goes here
}
```
} // missing return in global function expected to return 'Bool'
func isHappy(s: String) -> Bool {
var dict = [Character: Int]()
for char in s {
if dict[char] == nil {
dict[char] = 1
} else {
dict[char]! += 1
}
}
for (key, value) in dict {
if value > 1 {
return false
}
}
return true
}
```swift
// You are given a string s.
// Your task is to check if the string is hapswift or not.
// A string is hapswift if its length is at least 3 and every 3 consecutive letters are distinct
// For example:
// isHappy(s: "a") == false
// isHappy(s: "aa") == false
// isHappy(s: "abcd") == true
// isHappy(s: "aabb") == false
// isHappy(s: "adb") == true
// isHappy(s: "xyy") == false
func isHappy(s: String) -> Bool {
var dict = [Character: Int]()
for char in s {
if dict[char] == nil {
dict[char] = 1
} else {
dict[char]! += 1
}
}
for (key, value) in dict {
if value > 1 {
return false
}
}
return true
}
```
for (key, value) in dict { // immutable value 'key' was never used; consider replacing with '_' or removing it
// XCTAssertTrue failed
func isHappy(s: String) -> Bool {
guard s.count >= 3 else { return false }
var set = Set<Character>()
for i in 0..<s.count {
if i + 2 < s.count {
set.insert(s[i])
set.insert(s[i + 1])
set.insert(s[i + 2])
}
if set.count!= 3 {
return false
}
set.removeAll()
}
return true
}
```swift
// You are given a string s.
// Your task is to check if the string is hapswift or not.
// A string is hapswift if its length is at least 3 and every 3 consecutive letters are distinct
// For example:
// isHappy(s: "a") == false
// isHappy(s: "aa") == false
// isHappy(s: "abcd") == true
// isHappy(s: "aabb") == false
// isHappy(s: "adb") == true
// isHappy(s: "xyy") == false
func isHappy(s: String) -> Bool {
guard s.count >= 3 else { return false }
var set = Set<Character>()
for i in 0..<s.count {
if i + 2 < s.count {
set.insert(s[i])
set.insert(s[i + 1])
set.insert(s[i + 2])
}
if set.count!= 3 {
return false
}
set.removeAll()
}
return true
}
```
set.insert(s[i]) // 'subscript(_:)' is unavailable: cannot subscript String with an Int, use a String.Index instead.
set.insert(s[i + 1]) // 'subscript(_:)' is unavailable: cannot subscript String with an Int, use a String.Index instead.
set.insert(s[i + 2]) // 'subscript(_:)' is unavailable: cannot subscript String with an Int, use a String.Index instead.
if set.count!= 3 { // use of '=' in a boolean context, did you mean '=='?
if set.count!= 3 { // cannot force unwrap value of non-optional type 'Int'
if set.count!= 3 { // '=' must have consistent whitespace on both sides
func isHappy(s: String) -> Bool {
let s = Array(s)
for i in 0..<s.count-2 {
if s[i] == s[i+1] && s[i+1] == s[i+2] {
return false
}
}
return true
}
```swift
// You are given a string s.
// Your task is to check if the string is hapswift or not.
// A string is hapswift if its length is at least 3 and every 3 consecutive letters are distinct
// For example:
// isHappy(s: "a") == false
// isHappy(s: "aa") == false
// isHappy(s: "abcd") == true
// isHappy(s: "aabb") == false
// isHappy(s: "adb") == true
// isHappy(s: "xyy") == false
func isHappy(s: String) -> Bool {
let s = Array(s)
for i in 0..<s.count-2 {
if s[i] == s[i+1] && s[i+1] == s[i+2] {
return false
}
}
return true
}
```
// Fatal error: Range requires lowerBound <= upperBound
func isHappy(s: String) -> Bool {
var set = Set<Character>()
for char in s {
if set.contains(char) {
return false
}
set.insert(char)
}
return true
}
```swift
// You are given a string s.
// Your task is to check if the string is hapswift or not.
// A string is hapswift if its length is at least 3 and every 3 consecutive letters are distinct
// For example:
// isHappy(s: "a") == false
// isHappy(s: "aa") == false
// isHappy(s: "abcd") == true
// isHappy(s: "aabb") == false
// isHappy(s: "adb") == true
// isHappy(s: "xyy") == false
func isHappy(s: String) -> Bool {
var set = Set<Character>()
for char in s {
if set.contains(char) {
return false
}
set.insert(char)
}
return true
}
```
// XCTAssertTrue failed
func numericalLetterGrade(grades: [Double]) -> [String] {
var grades = grades
var letterGrades = [String]()
for i in 0..<grades.count {
if grades[i] >= 4.0 {
letterGrades.append("A+")
} else if grades[i] >= 3.7 {
letterGrades.append("A")
} else if grades[i] >= 3.3 {
letterGrades.append("A-")
} else if grades[i] >= 3.0 {
letterGrades.append("B+")
} else if grades[i] >= 2.7 {
letterGrades.append("B")
} else if grades[i] >= 2.3 {
letterGrades.append("B-")
} else if grades[i] >= 2.0 {
letterGrades.append("C+")
} else if grades[i] >= 1.7 {
letterGrades.append("C")
} else if grades[i] >= 1.3 {
letterGrades.append("C-")
} else if grades[i] >= 1.0 {
letterGrades.append("D+")
} else if grades[i] >= 0.7 {
letterGrades.append("D")
} else if grades[i] >= 0.0 {
letterGrades.append("D-")
} else {
letterGrades.append("E")
}
}
return letterGrades
}
```swift
// It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that can output an array of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// numericalLetterGrade(grades: [4.0, 3, 1.7, 2, 3.5]) == ["A+", "B", "C-", "C", "A-"]
func numericalLetterGrade(grades: [Double]) -> [String] {
var grades = grades
var letterGrades = [String]()
for i in 0..<grades.count {
if grades[i] >= 4.0 {
letterGrades.append("A+")
} else if grades[i] >= 3.7 {
letterGrades.append("A")
} else if grades[i] >= 3.3 {
letterGrades.append("A-")
} else if grades[i] >= 3.0 {
letterGrades.append("B+")
} else if grades[i] >= 2.7 {
letterGrades.append("B")
} else if grades[i] >= 2.3 {
letterGrades.append("B-")
} else if grades[i] >= 2.0 {
letterGrades.append("C+")
} else if grades[i] >= 1.7 {
letterGrades.append("C")
} else if grades[i] >= 1.3 {
letterGrades.append("C-")
} else if grades[i] >= 1.0 {
letterGrades.append("D+")
} else if grades[i] >= 0.7 {
letterGrades.append("D")
} else if grades[i] >= 0.0 {
letterGrades.append("D-")
} else {
letterGrades.append("E")
}
}
return letterGrades
}
```
var grades = grades // variable 'grades' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func numericalLetterGrade(grades: [Double]) -> [String] {
// Your code here
}
```swift
// It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that can output an array of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// numericalLetterGrade(grades: [4.0, 3, 1.7, 2, 3.5]) == ["A+", "B", "C-", "C", "A-"]
func numericalLetterGrade(grades: [Double]) -> [String] {
// Your code here
}
```
} // missing return in global function expected to return '[String]'
func numericalLetterGrade(grades: [Double]) -> [String] {
var grades = grades
var letterGrades: [String] = []
for i in 0..<grades.count {
if grades[i] >= 4.0 {
letterGrades.append("A+")
} else if grades[i] >= 3.7 {
letterGrades.append("A")
} else if grades[i] >= 3.3 {
letterGrades.append("A-")
} else if grades[i] >= 3.0 {
letterGrades.append("B+")
} else if grades[i] >= 2.7 {
letterGrades.append("B")
} else if grades[i] >= 2.3 {
letterGrades.append("B-")
} else if grades[i] >= 2.0 {
letterGrades.append("C+")
} else if grades[i] >= 1.7 {
letterGrades.append("C")
} else if grades[i] >= 1.3 {
letterGrades.append("C-")
} else if grades[i] >= 1.0 {
letterGrades.append("D+")
} else if grades[i] >= 0.7 {
letterGrades.append("D")
} else if grades[i] >= 0.0 {
letterGrades.append("D-")
} else {
letterGrades.append("E")
}
}
return letterGrades
}
```swift
// It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that can output an array of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// numericalLetterGrade(grades: [4.0, 3, 1.7, 2, 3.5]) == ["A+", "B", "C-", "C", "A-"]
func numericalLetterGrade(grades: [Double]) -> [String] {
var grades = grades
var letterGrades: [String] = []
for i in 0..<grades.count {
if grades[i] >= 4.0 {
letterGrades.append("A+")
} else if grades[i] >= 3.7 {
letterGrades.append("A")
} else if grades[i] >= 3.3 {
letterGrades.append("A-")
} else if grades[i] >= 3.0 {
letterGrades.append("B+")
} else if grades[i] >= 2.7 {
letterGrades.append("B")
} else if grades[i] >= 2.3 {
letterGrades.append("B-")
} else if grades[i] >= 2.0 {
letterGrades.append("C+")
} else if grades[i] >= 1.7 {
letterGrades.append("C")
} else if grades[i] >= 1.3 {
letterGrades.append("C-")
} else if grades[i] >= 1.0 {
letterGrades.append("D+")
} else if grades[i] >= 0.7 {
letterGrades.append("D")
} else if grades[i] >= 0.0 {
letterGrades.append("D-")
} else {
letterGrades.append("E")
}
}
return letterGrades
}
```
var grades = grades // variable 'grades' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func numericalLetterGrade(grades: [Double]) -> [String] {
var grades = grades
var letterGrades = [String]()
for i in 0..<grades.count {
if grades[i] >= 4.0 {
letterGrades.append("A+")
} else if grades[i] >= 3.7 {
letterGrades.append("A")
} else if grades[i] >= 3.3 {
letterGrades.append("A-")
} else if grades[i] >= 3.0 {
letterGrades.append("B+")
} else if grades[i] >= 2.7 {
letterGrades.append("B")
} else if grades[i] >= 2.3 {
letterGrades.append("B-")
} else if grades[i] >= 2.0 {
letterGrades.append("C+")
} else if grades[i] >= 1.7 {
letterGrades.append("C")
} else if grades[i] >= 1.3 {
letterGrades.append("C-")
} else if grades[i] >= 1.0 {
letterGrades.append("D+")
} else if grades[i] >= 0.7 {
letterGrades.append("D")
} else if grades[i] >= 0.0 {
letterGrades.append("D-")
} else {
letterGrades.append("E")
}
}
return letterGrades
}
```swift
// It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that can output an array of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// numericalLetterGrade(grades: [4.0, 3, 1.7, 2, 3.5]) == ["A+", "B", "C-", "C", "A-"]
func numericalLetterGrade(grades: [Double]) -> [String] {
var grades = grades
var letterGrades = [String]()
for i in 0..<grades.count {
if grades[i] >= 4.0 {
letterGrades.append("A+")
} else if grades[i] >= 3.7 {
letterGrades.append("A")
} else if grades[i] >= 3.3 {
letterGrades.append("A-")
} else if grades[i] >= 3.0 {
letterGrades.append("B+")
} else if grades[i] >= 2.7 {
letterGrades.append("B")
} else if grades[i] >= 2.3 {
letterGrades.append("B-")
} else if grades[i] >= 2.0 {
letterGrades.append("C+")
} else if grades[i] >= 1.7 {
letterGrades.append("C")
} else if grades[i] >= 1.3 {
letterGrades.append("C-")
} else if grades[i] >= 1.0 {
letterGrades.append("D+")
} else if grades[i] >= 0.7 {
letterGrades.append("D")
} else if grades[i] >= 0.0 {
letterGrades.append("D-")
} else {
letterGrades.append("E")
}
}
return letterGrades
}
```
var grades = grades // variable 'grades' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func numericalLetterGrade(grades: [Double]) -> [String] {
var grades = grades
var letterGrades: [String] = []
for i in 0..<grades.count {
if grades[i] >= 4.0 {
letterGrades.append("A+")
} else if grades[i] >= 3.7 {
letterGrades.append("A")
} else if grades[i] >= 3.3 {
letterGrades.append("A-")
} else if grades[i] >= 3.0 {
letterGrades.append("B+")
} else if grades[i] >= 2.7 {
letterGrades.append("B")
} else if grades[i] >= 2.3 {
letterGrades.append("B-")
} else if grades[i] >= 2.0 {
letterGrades.append("C+")
} else if grades[i] >= 1.7 {
letterGrades.append("C")
} else if grades[i] >= 1.3 {
letterGrades.append("C-")
} else if grades[i] >= 1.0 {
letterGrades.append("D+")
} else if grades[i] >= 0.7 {
letterGrades.append("D")
} else if grades[i] >= 0.0 {
letterGrades.append("D-")
} else {
letterGrades.append("E")
}
}
return letterGrades
}
```swift
// It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that can output an array of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// numericalLetterGrade(grades: [4.0, 3, 1.7, 2, 3.5]) == ["A+", "B", "C-", "C", "A-"]
func numericalLetterGrade(grades: [Double]) -> [String] {
var grades = grades
var letterGrades: [String] = []
for i in 0..<grades.count {
if grades[i] >= 4.0 {
letterGrades.append("A+")
} else if grades[i] >= 3.7 {
letterGrades.append("A")
} else if grades[i] >= 3.3 {
letterGrades.append("A-")
} else if grades[i] >= 3.0 {
letterGrades.append("B+")
} else if grades[i] >= 2.7 {
letterGrades.append("B")
} else if grades[i] >= 2.3 {
letterGrades.append("B-")
} else if grades[i] >= 2.0 {
letterGrades.append("C+")
} else if grades[i] >= 1.7 {
letterGrades.append("C")
} else if grades[i] >= 1.3 {
letterGrades.append("C-")
} else if grades[i] >= 1.0 {
letterGrades.append("D+")
} else if grades[i] >= 0.7 {
letterGrades.append("D")
} else if grades[i] >= 0.0 {
letterGrades.append("D-")
} else {
letterGrades.append("E")
}
}
return letterGrades
}
```
var grades = grades // variable 'grades' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func numericalLetterGrade(grades: [Double]) -> [String] {
var letterGrades: [String] = []
for grade in grades {
if grade >= 4.0 {
letterGrades.append("A+")
} else if grade >= 3.7 {
letterGrades.append("A")
} else if grade >= 3.3 {
letterGrades.append("A-")
} else if grade >= 3.0 {
letterGrades.append("B+")
} else if grade >= 2.7 {
letterGrades.append("B")
} else if grade >= 2.3 {
letterGrades.append("B-")
} else if grade >= 2.0 {
letterGrades.append("C+")
} else if grade >= 1.7 {
letterGrades.append("C")
} else if grade >= 1.3 {
letterGrades.append("C-")
} else if grade >= 1.0 {
letterGrades.append("D+")
} else if grade >= 0.7 {
letterGrades.append("D")
} else if grade >= 0.0 {
letterGrades.append("D-")
} else {
letterGrades.append("E")
}
}
return letterGrades
}
```swift
// It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that can output an array of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// numericalLetterGrade(grades: [4.0, 3, 1.7, 2, 3.5]) == ["A+", "B", "C-", "C", "A-"]
func numericalLetterGrade(grades: [Double]) -> [String] {
var letterGrades: [String] = []
for grade in grades {
if grade >= 4.0 {
letterGrades.append("A+")
} else if grade >= 3.7 {
letterGrades.append("A")
} else if grade >= 3.3 {
letterGrades.append("A-")
} else if grade >= 3.0 {
letterGrades.append("B+")
} else if grade >= 2.7 {
letterGrades.append("B")
} else if grade >= 2.3 {
letterGrades.append("B-")
} else if grade >= 2.0 {
letterGrades.append("C+")
} else if grade >= 1.7 {
letterGrades.append("C")
} else if grade >= 1.3 {
letterGrades.append("C-")
} else if grade >= 1.0 {
letterGrades.append("D+")
} else if grade >= 0.7 {
letterGrades.append("D")
} else if grade >= 0.0 {
letterGrades.append("D-")
} else {
letterGrades.append("E")
}
}
return letterGrades
}
```
// XCTAssertTrue failed
func numericalLetterGrade(grades: [Double]) -> [String] {
var letterGrades: [String] = []
for grade in grades {
if grade >= 4.0 {
letterGrades.append("A+")
} else if grade >= 3.7 {
letterGrades.append("A")
} else if grade >= 3.3 {
letterGrades.append("A-")
} else if grade >= 3.0 {
letterGrades.append("B+")
} else if grade >= 2.7 {
letterGrades.append("B")
} else if grade >= 2.3 {
letterGrades.append("B-")
} else if grade >= 2.0 {
letterGrades.append("C+")
} else if grade >= 1.7 {
letterGrades.append("C")
} else if grade >= 1.3 {
letterGrades.append("C-")
} else if grade >= 1.0 {
letterGrades.append("D+")
} else if grade >= 0.7 {
letterGrades.append("D")
} else if grade >= 0.0 {
letterGrades.append("D-")
} else {
letterGrades.append("E")
}
}
return letterGrades
}
```swift
// It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that can output an array of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// numericalLetterGrade(grades: [4.0, 3, 1.7, 2, 3.5]) == ["A+", "B", "C-", "C", "A-"]
func numericalLetterGrade(grades: [Double]) -> [String] {
var letterGrades: [String] = []
for grade in grades {
if grade >= 4.0 {
letterGrades.append("A+")
} else if grade >= 3.7 {
letterGrades.append("A")
} else if grade >= 3.3 {
letterGrades.append("A-")
} else if grade >= 3.0 {
letterGrades.append("B+")
} else if grade >= 2.7 {
letterGrades.append("B")
} else if grade >= 2.3 {
letterGrades.append("B-")
} else if grade >= 2.0 {
letterGrades.append("C+")
} else if grade >= 1.7 {
letterGrades.append("C")
} else if grade >= 1.3 {
letterGrades.append("C-")
} else if grade >= 1.0 {
letterGrades.append("D+")
} else if grade >= 0.7 {
letterGrades.append("D")
} else if grade >= 0.0 {
letterGrades.append("D-")
} else {
letterGrades.append("E")
}
}
return letterGrades
}
```
// XCTAssertTrue failed
func numericalLetterGrade(grades: [Double]) -> [String] {
var grades = grades
var letterGrades: [String] = []
for grade in grades {
if grade >= 4.0 {
letterGrades.append("A+")
} else if grade >= 3.7 {
letterGrades.append("A")
} else if grade >= 3.3 {
letterGrades.append("A-")
} else if grade >= 3.0 {
letterGrades.append("B+")
} else if grade >= 2.7 {
letterGrades.append("B")
} else if grade >= 2.3 {
letterGrades.append("B-")
} else if grade >= 2.0 {
letterGrades.append("C+")
} else if grade >= 1.7 {
letterGrades.append("C")
} else if grade >= 1.3 {
letterGrades.append("C-")
} else if grade >= 1.0 {
letterGrades.append("D+")
} else if grade >= 0.7 {
letterGrades.append("D")
} else if grade >= 0.0 {
letterGrades.append("D-")
} else {
letterGrades.append("E")
}
}
return letterGrades
}
```swift
// It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that can output an array of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// numericalLetterGrade(grades: [4.0, 3, 1.7, 2, 3.5]) == ["A+", "B", "C-", "C", "A-"]
func numericalLetterGrade(grades: [Double]) -> [String] {
var grades = grades
var letterGrades: [String] = []
for grade in grades {
if grade >= 4.0 {
letterGrades.append("A+")
} else if grade >= 3.7 {
letterGrades.append("A")
} else if grade >= 3.3 {
letterGrades.append("A-")
} else if grade >= 3.0 {
letterGrades.append("B+")
} else if grade >= 2.7 {
letterGrades.append("B")
} else if grade >= 2.3 {
letterGrades.append("B-")
} else if grade >= 2.0 {
letterGrades.append("C+")
} else if grade >= 1.7 {
letterGrades.append("C")
} else if grade >= 1.3 {
letterGrades.append("C-")
} else if grade >= 1.0 {
letterGrades.append("D+")
} else if grade >= 0.7 {
letterGrades.append("D")
} else if grade >= 0.0 {
letterGrades.append("D-")
} else {
letterGrades.append("E")
}
}
return letterGrades
}
```
var grades = grades // variable 'grades' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func numericalLetterGrade(grades: [Double]) -> [String] {
// your code here
}
```swift
// It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that can output an array of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// numericalLetterGrade(grades: [4.0, 3, 1.7, 2, 3.5]) == ["A+", "B", "C-", "C", "A-"]
func numericalLetterGrade(grades: [Double]) -> [String] {
// your code here
}
```
} // missing return in global function expected to return '[String]'
func numericalLetterGrade(grades: [Double]) -> [String] {
var letterGrades: [String] = []
for grade in grades {
if grade >= 4.0 {
letterGrades.append("A+")
} else if grade >= 3.7 {
letterGrades.append("A")
} else if grade >= 3.3 {
letterGrades.append("A-")
} else if grade >= 3.0 {
letterGrades.append("B+")
} else if grade >= 2.7 {
letterGrades.append("B")
} else if grade >= 2.3 {
letterGrades.append("B-")
} else if grade >= 2.0 {
letterGrades.append("C+")
} else if grade >= 1.7 {
letterGrades.append("C")
} else if grade >= 1.3 {
letterGrades.append("C-")
} else if grade >= 1.0 {
letterGrades.append("D+")
} else if grade >= 0.7 {
letterGrades.append("D")
} else if grade >= 0.0 {
letterGrades.append("D-")
} else {
letterGrades.append("E")
}
}
return letterGrades
}
```swift
// It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that can output an array of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// numericalLetterGrade(grades: [4.0, 3, 1.7, 2, 3.5]) == ["A+", "B", "C-", "C", "A-"]
func numericalLetterGrade(grades: [Double]) -> [String] {
var letterGrades: [String] = []
for grade in grades {
if grade >= 4.0 {
letterGrades.append("A+")
} else if grade >= 3.7 {
letterGrades.append("A")
} else if grade >= 3.3 {
letterGrades.append("A-")
} else if grade >= 3.0 {
letterGrades.append("B+")
} else if grade >= 2.7 {
letterGrades.append("B")
} else if grade >= 2.3 {
letterGrades.append("B-")
} else if grade >= 2.0 {
letterGrades.append("C+")
} else if grade >= 1.7 {
letterGrades.append("C")
} else if grade >= 1.3 {
letterGrades.append("C-")
} else if grade >= 1.0 {
letterGrades.append("D+")
} else if grade >= 0.7 {
letterGrades.append("D")
} else if grade >= 0.0 {
letterGrades.append("D-")
} else {
letterGrades.append("E")
}
}
return letterGrades
}
```
// XCTAssertTrue failed
func primeLength(string: String) -> Bool {
return true
}
```swift
// Write a function that takes a string and returns true if the string
// length is a prime number or false otherwise
// Examples
// primeLength(string: "Hello") == true
// primeLength(string: "abcdcba") == true
// primeLength(string: "kittens") == true
// primeLength(string: "orange") == false
func primeLength(string: String) -> Bool {
return true
}
```
// XCTAssertTrue failed
func primeLength(string: String) -> Bool {
return true
}
```swift
// Write a function that takes a string and returns true if the string
// length is a prime number or false otherwise
// Examples
// primeLength(string: "Hello") == true
// primeLength(string: "abcdcba") == true
// primeLength(string: "kittens") == true
// primeLength(string: "orange") == false
func primeLength(string: String) -> Bool {
return true
}
```
// XCTAssertTrue failed
func primeLength(string: String) -> Bool {
return true
}
```swift
// Write a function that takes a string and returns true if the string
// length is a prime number or false otherwise
// Examples
// primeLength(string: "Hello") == true
// primeLength(string: "abcdcba") == true
// primeLength(string: "kittens") == true
// primeLength(string: "orange") == false
func primeLength(string: String) -> Bool {
return true
}
```
// XCTAssertTrue failed
func primeLength(string: String) -> Bool {
return true
}
```swift
// Write a function that takes a string and returns true if the string
// length is a prime number or false otherwise
// Examples
// primeLength(string: "Hello") == true
// primeLength(string: "abcdcba") == true
// primeLength(string: "kittens") == true
// primeLength(string: "orange") == false
func primeLength(string: String) -> Bool {
return true
}
```
// XCTAssertTrue failed
func primeLength(string: String) -> Bool {
return true
}
```swift
// Write a function that takes a string and returns true if the string
// length is a prime number or false otherwise
// Examples
// primeLength(string: "Hello") == true
// primeLength(string: "abcdcba") == true
// primeLength(string: "kittens") == true
// primeLength(string: "orange") == false
func primeLength(string: String) -> Bool {
return true
}
```
// XCTAssertTrue failed
func primeLength(string: String) -> Bool {
return true
}
```swift
// Write a function that takes a string and returns true if the string
// length is a prime number or false otherwise
// Examples
// primeLength(string: "Hello") == true
// primeLength(string: "abcdcba") == true
// primeLength(string: "kittens") == true
// primeLength(string: "orange") == false
func primeLength(string: String) -> Bool {
return true
}
```
// XCTAssertTrue failed
func primeLength(string: String) -> Bool {
return true
}
```swift
// Write a function that takes a string and returns true if the string
// length is a prime number or false otherwise
// Examples
// primeLength(string: "Hello") == true
// primeLength(string: "abcdcba") == true
// primeLength(string: "kittens") == true
// primeLength(string: "orange") == false
func primeLength(string: String) -> Bool {
return true
}
```
// XCTAssertTrue failed
func primeLength(string: String) -> Bool {
return true
}
```swift
// Write a function that takes a string and returns true if the string
// length is a prime number or false otherwise
// Examples
// primeLength(string: "Hello") == true
// primeLength(string: "abcdcba") == true
// primeLength(string: "kittens") == true
// primeLength(string: "orange") == false
func primeLength(string: String) -> Bool {
return true
}
```
// XCTAssertTrue failed
func primeLength(string: String) -> Bool {
return true
}
```swift
// Write a function that takes a string and returns true if the string
// length is a prime number or false otherwise
// Examples
// primeLength(string: "Hello") == true
// primeLength(string: "abcdcba") == true
// primeLength(string: "kittens") == true
// primeLength(string: "orange") == false
func primeLength(string: String) -> Bool {
return true
}
```
// XCTAssertTrue failed
func primeLength(string: String) -> Bool {
return true
}
```swift
// Write a function that takes a string and returns true if the string
// length is a prime number or false otherwise
// Examples
// primeLength(string: "Hello") == true
// primeLength(string: "abcdcba") == true
// primeLength(string: "kittens") == true
// primeLength(string: "orange") == false
func primeLength(string: String) -> Bool {
return true
}
```
// XCTAssertTrue failed
func startsOneEnds(n: Int) -> Int {
// TODO: implement this function
}
```swift
// Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
func startsOneEnds(n: Int) -> Int {
// TODO: implement this function
}
```
} // missing return in global function expected to return 'Int'
func startsOneEnds(n: Int) -> Int {
// TODO: Implement this function
}
```swift
// Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
func startsOneEnds(n: Int) -> Int {
// TODO: Implement this function
}
```
} // missing return in global function expected to return 'Int'
func startsOneEnds(n: Int) -> Int {
// TODO: implement this function
}
```swift
// Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
func startsOneEnds(n: Int) -> Int {
// TODO: implement this function
}
```
} // missing return in global function expected to return 'Int'
func startsOneEnds(n: Int) -> Int {
// TODO: Implement this function
}
```swift
// Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
func startsOneEnds(n: Int) -> Int {
// TODO: Implement this function
}
```
} // missing return in global function expected to return 'Int'
func startsOneEnds(n: Int) -> Int {
// TODO: implement
}
```swift
// Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
func startsOneEnds(n: Int) -> Int {
// TODO: implement
}
```
} // missing return in global function expected to return 'Int'
func startsOneEnds(n: Int) -> Int {
// TODO: implement
return 0
}
```swift
// Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
func startsOneEnds(n: Int) -> Int {
// TODO: implement
return 0
}
```
// XCTAssertTrue failed
func startsOneEnds(n: Int) -> Int {
// TODO: implement
}
```swift
// Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
func startsOneEnds(n: Int) -> Int {
// TODO: implement
}
```
} // missing return in global function expected to return 'Int'
func startsOneEnds(n: Int) -> Int {
// TODO: Implement this function
}
```swift
// Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
func startsOneEnds(n: Int) -> Int {
// TODO: Implement this function
}
```
} // missing return in global function expected to return 'Int'
func startsOneEnds(n: Int) -> Int {
// TODO: Implement this function
}
```swift
// Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
func startsOneEnds(n: Int) -> Int {
// TODO: Implement this function
}
```
} // missing return in global function expected to return 'Int'
func startsOneEnds(n: Int) -> Int {
// TODO: implement
return 0
}
```swift
// Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
func startsOneEnds(n: Int) -> Int {
// TODO: implement
return 0
}
```
// XCTAssertTrue failed
func solve(N: Int) -> String {
var result = ""
var n = N
while n > 0 {
result = "\(n % 2)" + result
n /= 2
}
return result
}
```swift
// Given a positive integer N, return the total sum of its digits in binary.
// Example
// Variables:
// @N integer
// Constraints: 0 ≤ N ≤ 10000.
// Output:
// a string of binary number
// solve(N: 1000) == "1"
// solve(N: 150) == "110"
// solve(N: 147) == "1100"
func solve(N: Int) -> String {
var result = ""
var n = N
while n > 0 {
result = "\(n % 2)" + result
n /= 2
}
return result
}
```
// XCTAssertTrue failed
func solve(N: Int) -> String {
var result = ""
var n = N
while n > 0 {
result = String(n % 2) + result
n /= 2
}
return result
}
```swift
// Given a positive integer N, return the total sum of its digits in binary.
// Example
// Variables:
// @N integer
// Constraints: 0 ≤ N ≤ 10000.
// Output:
// a string of binary number
// solve(N: 1000) == "1"
// solve(N: 150) == "110"
// solve(N: 147) == "1100"
func solve(N: Int) -> String {
var result = ""
var n = N
while n > 0 {
result = String(n % 2) + result
n /= 2
}
return result
}
```
// XCTAssertTrue failed
func solve(N: Int) -> String {
var result = ""
var n = N
while n > 0 {
result = "\(n % 2)" + result
n /= 2
}
return result
}
```swift
// Given a positive integer N, return the total sum of its digits in binary.
// Example
// Variables:
// @N integer
// Constraints: 0 ≤ N ≤ 10000.
// Output:
// a string of binary number
// solve(N: 1000) == "1"
// solve(N: 150) == "110"
// solve(N: 147) == "1100"
func solve(N: Int) -> String {
var result = ""
var n = N
while n > 0 {
result = "\(n % 2)" + result
n /= 2
}
return result
}
```
// XCTAssertTrue failed
func solve(N: Int) -> String {
var result = ""
var n = N
while n > 0 {
result = String(n % 2) + result
n /= 2
}
return result
}
```swift
// Given a positive integer N, return the total sum of its digits in binary.
// Example
// Variables:
// @N integer
// Constraints: 0 ≤ N ≤ 10000.
// Output:
// a string of binary number
// solve(N: 1000) == "1"
// solve(N: 150) == "110"
// solve(N: 147) == "1100"
func solve(N: Int) -> String {
var result = ""
var n = N
while n > 0 {
result = String(n % 2) + result
n /= 2
}
return result
}
```
// XCTAssertTrue failed
func solve(N: Int) -> String {
var sum = 0
var N = N
while N > 0 {
sum += N % 2
N /= 2
}
return String(sum)
}
```swift
// Given a positive integer N, return the total sum of its digits in binary.
// Example
// Variables:
// @N integer
// Constraints: 0 ≤ N ≤ 10000.
// Output:
// a string of binary number
// solve(N: 1000) == "1"
// solve(N: 150) == "110"
// solve(N: 147) == "1100"
func solve(N: Int) -> String {
var sum = 0
var N = N
while N > 0 {
sum += N % 2
N /= 2
}
return String(sum)
}
```
// XCTAssertTrue failed
func solve(N: Int) -> String {
var result = ""
var N = N
while N > 0 {
result = "\(N % 2)" + result
N /= 2
}
return result
}
```swift
// Given a positive integer N, return the total sum of its digits in binary.
// Example
// Variables:
// @N integer
// Constraints: 0 ≤ N ≤ 10000.
// Output:
// a string of binary number
// solve(N: 1000) == "1"
// solve(N: 150) == "110"
// solve(N: 147) == "1100"
func solve(N: Int) -> String {
var result = ""
var N = N
while N > 0 {
result = "\(N % 2)" + result
N /= 2
}
return result
}
```
// XCTAssertTrue failed
func solve(N: Int) -> String {
var result = ""
var n = N
while n > 0 {
result = "\(n % 2)" + result
n /= 2
}
return result
}
```swift
// Given a positive integer N, return the total sum of its digits in binary.
// Example
// Variables:
// @N integer
// Constraints: 0 ≤ N ≤ 10000.
// Output:
// a string of binary number
// solve(N: 1000) == "1"
// solve(N: 150) == "110"
// solve(N: 147) == "1100"
func solve(N: Int) -> String {
var result = ""
var n = N
while n > 0 {
result = "\(n % 2)" + result
n /= 2
}
return result
}
```
// XCTAssertTrue failed
func solve(N: Int) -> String {
var result = ""
var N = N
while N > 0 {
result = "\(N % 2)" + result
N /= 2
}
return result
}
```swift
// Given a positive integer N, return the total sum of its digits in binary.
// Example
// Variables:
// @N integer
// Constraints: 0 ≤ N ≤ 10000.
// Output:
// a string of binary number
// solve(N: 1000) == "1"
// solve(N: 150) == "110"
// solve(N: 147) == "1100"
func solve(N: Int) -> String {
var result = ""
var N = N
while N > 0 {
result = "\(N % 2)" + result
N /= 2
}
return result
}
```
// XCTAssertTrue failed
func solve(N: Int) -> String {
var result = ""
var n = N
while n > 0 {
result = String(n % 2) + result
n /= 2
}
return result
}
```swift
// Given a positive integer N, return the total sum of its digits in binary.
// Example
// Variables:
// @N integer
// Constraints: 0 ≤ N ≤ 10000.
// Output:
// a string of binary number
// solve(N: 1000) == "1"
// solve(N: 150) == "110"
// solve(N: 147) == "1100"
func solve(N: Int) -> String {
var result = ""
var n = N
while n > 0 {
result = String(n % 2) + result
n /= 2
}
return result
}
```
// XCTAssertTrue failed
func solve(N: Int) -> String {
var sum = 0
var N = N
while N > 0 {
sum += N % 2
N /= 2
}
return String(sum)
}
```swift
// Given a positive integer N, return the total sum of its digits in binary.
// Example
// Variables:
// @N integer
// Constraints: 0 ≤ N ≤ 10000.
// Output:
// a string of binary number
// solve(N: 1000) == "1"
// solve(N: 150) == "110"
// solve(N: 147) == "1100"
func solve(N: Int) -> String {
var sum = 0
var N = N
while N > 0 {
sum += N % 2
N /= 2
}
return String(sum)
}
```
// XCTAssertTrue failed
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers lst. add the even elements that are at odd indices..
// Examples:
// add(lst: [4, 2, 6, 7]) == 2
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```
// XCTAssertTrue failed
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers lst. add the even elements that are at odd indices..
// Examples:
// add(lst: [4, 2, 6, 7]) == 2
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```
// XCTAssertTrue failed
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers lst. add the even elements that are at odd indices..
// Examples:
// add(lst: [4, 2, 6, 7]) == 2
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```
// XCTAssertTrue failed
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers lst. add the even elements that are at odd indices..
// Examples:
// add(lst: [4, 2, 6, 7]) == 2
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```
// XCTAssertTrue failed
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers lst. add the even elements that are at odd indices..
// Examples:
// add(lst: [4, 2, 6, 7]) == 2
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```
// XCTAssertTrue failed
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers lst. add the even elements that are at odd indices..
// Examples:
// add(lst: [4, 2, 6, 7]) == 2
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```
// XCTAssertTrue failed
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers lst. add the even elements that are at odd indices..
// Examples:
// add(lst: [4, 2, 6, 7]) == 2
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```
// XCTAssertTrue failed
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers lst. add the even elements that are at odd indices..
// Examples:
// add(lst: [4, 2, 6, 7]) == 2
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```
// XCTAssertTrue failed
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers lst. add the even elements that are at odd indices..
// Examples:
// add(lst: [4, 2, 6, 7]) == 2
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```
// XCTAssertTrue failed
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers lst. add the even elements that are at odd indices..
// Examples:
// add(lst: [4, 2, 6, 7]) == 2
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```
// XCTAssertTrue failed
func antiShuffle(s: String) -> String {
var result = ""
var temp = ""
for char in s {
if char == " " {
result += temp
temp = ""
result += " "
} else {
temp += String(char)
}
}
result += temp
return result
}
```swift
// Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank spaces in the sentence.
// For example:
// antiShuffle(s: "Hi") == "Hi"
// antiShuffle(s: "hello") == "ehllo"
// antiShuffle(s: "Hello World!!!") == "Hello !!!Wdlor"
func antiShuffle(s: String) -> String {
var result = ""
var temp = ""
for char in s {
if char == " " {
result += temp
temp = ""
result += " "
} else {
temp += String(char)
}
}
result += temp
return result
}
```
// XCTAssertTrue failed
func antiShuffle(s: String) -> String {
// Write your code here
return ""
}
```swift
// Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank spaces in the sentence.
// For example:
// antiShuffle(s: "Hi") == "Hi"
// antiShuffle(s: "hello") == "ehllo"
// antiShuffle(s: "Hello World!!!") == "Hello !!!Wdlor"
func antiShuffle(s: String) -> String {
// Write your code here
return ""
}
```
// XCTAssertTrue failed
func antiShuffle(s: String) -> String {
var result = ""
let words = s.components(separatedBy: " ")
for word in words {
let sortedWord = word.sorted()
result += String(sortedWord) + " "
}
return result
}
```swift
// Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank spaces in the sentence.
// For example:
// antiShuffle(s: "Hi") == "Hi"
// antiShuffle(s: "hello") == "ehllo"
// antiShuffle(s: "Hello World!!!") == "Hello !!!Wdlor"
func antiShuffle(s: String) -> String {
var result = ""
let words = s.components(separatedBy: " ")
for word in words {
let sortedWord = word.sorted()
result += String(sortedWord) + " "
}
return result
}
```
// XCTAssertTrue failed
```swift
// Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank spaces in the sentence.
// For example:
// antiShuffle(s: "Hi") == "Hi"
// antiShuffle(s: "hello") == "ehllo"
// antiShuffle(s: "Hello World!!!") == "Hello !!!Wdlor"
func antiShuffle(s: String) -> String {
var result = ""
var temp = ""
var temp2 = ""
var temp3 = ""
var temp4 = ""
var temp5 = ""
var temp6 = ""
var temp7 = ""
var temp8 = ""
var temp9 = ""
var temp10 = ""
var temp11 = ""
var temp12 = ""
var temp13 = ""
var temp14 = ""
var temp15 = ""
var temp16 = ""
var temp17 = ""
var temp18 = ""
var temp19 = ""
var temp20 = ""
var temp21 = ""
var temp22 = ""
var temp23 = ""
var temp24 = ""
var temp25 = ""
var temp26 = ""
var temp27 = ""
var temp28 = ""
var temp29 = ""
var temp30 = ""
var temp31 = ""
var temp32 = ""
var temp33 = ""
var temp34 = ""
var temp35 = ""
var temp36 = ""
var temp37 = ""
var temp38 = ""
var temp39 = ""
var temp40 = ""
var temp41 = ""
var temp42 = ""
var temp43 = ""
var temp44 = ""
var temp45 = ""
var temp46 = ""
var temp47 = ""
var temp48 = ""
var temp49 = ""
var temp50 = ""
var temp51 = ""
var temp52 = ""
var temp53 = ""
var temp54 = ""
var temp55 = ""
var temp56 = ""
var temp57 = ""
var temp58 = ""
var temp59 = ""
var temp60 = ""
var temp61 = ""
var temp62 = ""
var temp63 = ""
var temp64 = ""
var temp65 = ""
var temp66 = ""
var temp67 = ""
var temp68 = ""
var temp69 = ""
var temp70 = ""
var temp71 = ""
var temp72 = ""
var temp73 = ""
var temp74 = ""
var temp75 = ""
var temp76 = ""
var temp77 = ""
var temp78 = ""
var temp79 = ""
var temp80 = ""
var temp81 = ""
var temp82 = ""
var temp83 = ""
var temp84 = ""
var temp85 = ""
var temp86 = ""
var temp87 = ""
var temp88 = ""
var temp89 = ""
var temp90 = ""
var temp91 = ""
var temp92 = ""
var temp93 = ""
var temp94 = ""
var temp95 = ""
var temp96 = ""
var temp97 = ""
var temp98 = ""
var temp99 = ""
var temp100 = ""
var temp101 = ""
var temp102 = ""
var temp103 = ""
var temp104 = ""
var temp105 = ""
var temp106 = ""
var temp107 = ""
var temp108 = ""
var temp109 = ""
var temp110 = ""
var temp111 = ""
var temp112 = ""
var temp113 = ""
var temp114 = ""
var temp115 = ""
var temp116 = ""
var temp117 = ""
var temp118 = ""
var temp119 = ""
var temp120 = ""
var temp121 = ""
var temp122 = ""
var temp123 = ""
var temp124 = ""
var temp125 = ""
var temp126 = ""
var temp127 = ""
var temp128 = ""
var temp129 = ""
var temp130 = ""
var temp131 = ""
var temp132 = ""
var temp133 = ""
var temp134 = ""
var temp135 = ""
var temp136 = ""
var temp137 = ""
var temp138 = ""
var temp139 = ""
var temp140 = ""
var temp141 = ""
XCTAssertTrue(antiShuffle(s: "Hi") == "Hi") // cannot find 'antiShuffle' in scope
XCTAssertTrue(antiShuffle(s: "hello") == "ehllo") // cannot find 'antiShuffle' in scope
XCTAssertTrue(antiShuffle(s: "number") == "bemnru") // cannot find 'antiShuffle' in scope
XCTAssertTrue(antiShuffle(s: "abcd") == "abcd") // cannot find 'antiShuffle' in scope
XCTAssertTrue(antiShuffle(s: "Hello World!!!") == "Hello !!!Wdlor") // cannot find 'antiShuffle' in scope
XCTAssertTrue(antiShuffle(s: "") == "") // cannot find 'antiShuffle' in scope
XCTAssertTrue(antiShuffle(s: "Hi. My name is Mister Robot. How are you?") == ".Hi My aemn is Meirst .Rboot How aer ?ouy") // cannot find 'antiShuffle' in scope
func antiShuffle(s: String) -> String {
var result = ""
let words = s.split(separator: " ")
for word in words {
let sortedWord = String(word.sorted())
result += sortedWord + " "
}
return result
}
```swift
// Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank spaces in the sentence.
// For example:
// antiShuffle(s: "Hi") == "Hi"
// antiShuffle(s: "hello") == "ehllo"
// antiShuffle(s: "Hello World!!!") == "Hello !!!Wdlor"
func antiShuffle(s: String) -> String {
var result = ""
let words = s.split(separator: " ")
for word in words {
let sortedWord = String(word.sorted())
result += sortedWord + " "
}
return result
}
```
// XCTAssertTrue failed
```swift
// Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank spaces in the sentence.
// For example:
// antiShuffle(s: "Hi") == "Hi"
// antiShuffle(s: "hello") == "ehllo"
// antiShuffle(s: "Hello World!!!") == "Hello !!!Wdlor"
func antiShuffle(s: String) -> String {
var result = ""
var temp = ""
var temp2 = ""
var temp3 = ""
var temp4 = ""
var temp5 = ""
var temp6 = ""
var temp7 = ""
var temp8 = ""
var temp9 = ""
var temp10 = ""
var temp11 = ""
var temp12 = ""
var temp13 = ""
var temp14 = ""
var temp15 = ""
var temp16 = ""
var temp17 = ""
var temp18 = ""
var temp19 = ""
var temp20 = ""
var temp21 = ""
var temp22 = ""
var temp23 = ""
var temp24 = ""
var temp25 = ""
var temp26 = ""
var temp27 = ""
var temp28 = ""
var temp29 = ""
var temp30 = ""
var temp31 = ""
var temp32 = ""
var temp33 = ""
var temp34 = ""
var temp35 = ""
var temp36 = ""
var temp37 = ""
var temp38 = ""
var temp39 = ""
var temp40 = ""
var temp41 = ""
var temp42 = ""
var temp43 = ""
var temp44 = ""
var temp45 = ""
var temp46 = ""
var temp47 = ""
var temp48 = ""
var temp49 = ""
var temp50 = ""
var temp51 = ""
var temp52 = ""
var temp53 = ""
var temp54 = ""
var temp55 = ""
var temp56 = ""
var temp57 = ""
var temp58 = ""
var temp59 = ""
var temp60 = ""
var temp61 = ""
var temp62 = ""
var temp63 = ""
var temp64 = ""
var temp65 = ""
var temp66 = ""
var temp67 = ""
var temp68 = ""
var temp69 = ""
var temp70 = ""
var temp71 = ""
var temp72 = ""
var temp73 = ""
var temp74 = ""
var temp75 = ""
var temp76 = ""
var temp77 = ""
var temp78 = ""
var temp79 = ""
var temp80 = ""
var temp81 = ""
var temp82 = ""
var temp83 = ""
var temp84 = ""
var temp85 = ""
var temp86 = ""
var temp87 = ""
var temp88 = ""
var temp89 = ""
var temp90 = ""
var temp91 = ""
var temp92 = ""
var temp93 = ""
var temp94 = ""
var temp95 = ""
var temp96 = ""
var temp97 = ""
var temp98 = ""
var temp99 = ""
var temp100 = ""
var temp101 = ""
var temp102 = ""
var temp103 = ""
var temp104 = ""
var temp105 = ""
var temp106 = ""
var temp107 = ""
var temp108 = ""
var temp109 = ""
var temp110 = ""
var temp111 = ""
var temp112 = ""
var temp113 = ""
var temp114 = ""
var temp115 = ""
var temp116 = ""
var temp117 = ""
var temp118 = ""
var temp119 = ""
var temp120 = ""
var temp121 = ""
var temp122 = ""
var temp123 = ""
var temp124 = ""
var temp125 = ""
var temp126 = ""
var temp127 = ""
var temp128 = ""
var temp129 = ""
var temp130 = ""
var temp131 = ""
var temp132 = ""
var temp133 = ""
var temp134 = ""
var temp135 = ""
var temp136 = ""
var temp137 = ""
var temp138 = ""
var temp139 = ""
var temp140 = ""
var temp141 = ""
XCTAssertTrue(antiShuffle(s: "Hi") == "Hi") // cannot find 'antiShuffle' in scope
XCTAssertTrue(antiShuffle(s: "hello") == "ehllo") // cannot find 'antiShuffle' in scope
XCTAssertTrue(antiShuffle(s: "number") == "bemnru") // cannot find 'antiShuffle' in scope
XCTAssertTrue(antiShuffle(s: "abcd") == "abcd") // cannot find 'antiShuffle' in scope
XCTAssertTrue(antiShuffle(s: "Hello World!!!") == "Hello !!!Wdlor") // cannot find 'antiShuffle' in scope
XCTAssertTrue(antiShuffle(s: "") == "") // cannot find 'antiShuffle' in scope
XCTAssertTrue(antiShuffle(s: "Hi. My name is Mister Robot. How are you?") == ".Hi My aemn is Meirst .Rboot How aer ?ouy") // cannot find 'antiShuffle' in scope
```swift
// Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank spaces in the sentence.
// For example:
// antiShuffle(s: "Hi") == "Hi"
// antiShuffle(s: "hello") == "ehllo"
// antiShuffle(s: "Hello World!!!") == "Hello !!!Wdlor"
func antiShuffle(s: String) -> String {
var result = ""
var temp = ""
var temp2 = ""
var temp3 = ""
var temp4 = ""
var temp5 = ""
var temp6 = ""
var temp7 = ""
var temp8 = ""
var temp9 = ""
var temp10 = ""
var temp11 = ""
var temp12 = ""
var temp13 = ""
var temp14 = ""
var temp15 = ""
var temp16 = ""
var temp17 = ""
var temp18 = ""
var temp19 = ""
var temp20 = ""
var temp21 = ""
var temp22 = ""
var temp23 = ""
var temp24 = ""
var temp25 = ""
var temp26 = ""
var temp27 = ""
var temp28 = ""
var temp29 = ""
var temp30 = ""
var temp31 = ""
var temp32 = ""
var temp33 = ""
var temp34 = ""
var temp35 = ""
var temp36 = ""
var temp37 = ""
var temp38 = ""
var temp39 = ""
var temp40 = ""
var temp41 = ""
var temp42 = ""
var temp43 = ""
var temp44 = ""
var temp45 = ""
var temp46 = ""
var temp47 = ""
var temp48 = ""
var temp49 = ""
var temp50 = ""
var temp51 = ""
var temp52 = ""
var temp53 = ""
var temp54 = ""
var temp55 = ""
var temp56 = ""
var temp57 = ""
var temp58 = ""
var temp59 = ""
var temp60 = ""
var temp61 = ""
var temp62 = ""
var temp63 = ""
var temp64 = ""
var temp65 = ""
var temp66 = ""
var temp67 = ""
var temp68 = ""
var temp69 = ""
var temp70 = ""
var temp71 = ""
var temp72 = ""
var temp73 = ""
var temp74 = ""
var temp75 = ""
var temp76 = ""
var temp77 = ""
var temp78 = ""
var temp79 = ""
var temp80 = ""
var temp81 = ""
var temp82 = ""
var temp83 = ""
var temp84 = ""
var temp85 = ""
var temp86 = ""
var temp87 = ""
var temp88 = ""
var temp89 = ""
var temp90 = ""
var temp91 = ""
var temp92 = ""
var temp93 = ""
var temp94 = ""
var temp95 = ""
var temp96 = ""
var temp97 = ""
var temp98 = ""
var temp99 = ""
var temp100 = ""
var temp101 = ""
var temp102 = ""
var temp103 = ""
var temp104 = ""
var temp105 = ""
var temp106 = ""
var temp107 = ""
var temp108 = ""
var temp109 = ""
var temp110 = ""
var temp111 = ""
var temp112 = ""
var temp113 = ""
var temp114 = ""
var temp115 = ""
var temp116 = ""
var temp117 = ""
var temp118 = ""
var temp119 = ""
var temp120 = ""
var temp121 = ""
var temp122 = ""
var temp123 = ""
var temp124 = ""
var temp125 = ""
var temp126 = ""
var temp127 = ""
var temp128 = ""
var temp129 = ""
var temp130 = ""
var temp131 = ""
var temp132 = ""
var temp133 = ""
var temp134 = ""
var temp135 = ""
var temp136 = ""
var temp137 = ""
var temp138 = ""
var temp139 = ""
var temp140 = ""
var temp141 = ""
XCTAssertTrue(antiShuffle(s: "Hi") == "Hi") // cannot find 'antiShuffle' in scope
XCTAssertTrue(antiShuffle(s: "hello") == "ehllo") // cannot find 'antiShuffle' in scope
XCTAssertTrue(antiShuffle(s: "number") == "bemnru") // cannot find 'antiShuffle' in scope
XCTAssertTrue(antiShuffle(s: "abcd") == "abcd") // cannot find 'antiShuffle' in scope
XCTAssertTrue(antiShuffle(s: "Hello World!!!") == "Hello !!!Wdlor") // cannot find 'antiShuffle' in scope
XCTAssertTrue(antiShuffle(s: "") == "") // cannot find 'antiShuffle' in scope
XCTAssertTrue(antiShuffle(s: "Hi. My name is Mister Robot. How are you?") == ".Hi My aemn is Meirst .Rboot How aer ?ouy") // cannot find 'antiShuffle' in scope
func antiShuffle(s: String) -> String {
var result = ""
let words = s.split(separator: " ")
for word in words {
let sortedWord = String(word.sorted(by: <))
result += sortedWord + " "
}
return result.trimmingCharacters(in:.whitespaces)
}
```swift
// Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank spaces in the sentence.
// For example:
// antiShuffle(s: "Hi") == "Hi"
// antiShuffle(s: "hello") == "ehllo"
// antiShuffle(s: "Hello World!!!") == "Hello !!!Wdlor"
func antiShuffle(s: String) -> String {
var result = ""
let words = s.split(separator: " ")
for word in words {
let sortedWord = String(word.sorted(by: <))
result += sortedWord + " "
}
return result.trimmingCharacters(in:.whitespaces)
}
```
func antiShuffle(s: String) -> String {
var result = ""
var words = s.components(separatedBy: " ")
for word in words {
var temp = word.sorted()
result += String(temp) + " "
}
return result
}
```swift
// Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank spaces in the sentence.
// For example:
// antiShuffle(s: "Hi") == "Hi"
// antiShuffle(s: "hello") == "ehllo"
// antiShuffle(s: "Hello World!!!") == "Hello !!!Wdlor"
func antiShuffle(s: String) -> String {
var result = ""
var words = s.components(separatedBy: " ")
for word in words {
var temp = word.sorted()
result += String(temp) + " "
}
return result
}
```
var words = s.components(separatedBy: " ") // variable 'words' was never mutated; consider changing to 'let' constant
var temp = word.sorted() // variable 'temp' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func antiShuffle(s: String) -> String {
// Write your code here
return ""
}
```swift
// Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank spaces in the sentence.
// For example:
// antiShuffle(s: "Hi") == "Hi"
// antiShuffle(s: "hello") == "ehllo"
// antiShuffle(s: "Hello World!!!") == "Hello !!!Wdlor"
func antiShuffle(s: String) -> String {
// Write your code here
return ""
}
```
// XCTAssertTrue failed
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
// your code here
}
```swift
// You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of tuples, [(x1, y1), (x2, y2) ...] such that
// each tuple is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// getRow(lst: [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], x: 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]
// getRow(lst: [] as [[Int]], x: 1) == [] as [(Int, Int)]
// getRow(lst: [[] as [Int], [1], [1, 2, 3]], x: 3) == [(2, 2)]
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
// your code here
}
```
} // missing return in global function expected to return '[(Int, Int)]'
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
// your code here
}
```swift
// You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of tuples, [(x1, y1), (x2, y2) ...] such that
// each tuple is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// getRow(lst: [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], x: 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]
// getRow(lst: [] as [[Int]], x: 1) == [] as [(Int, Int)]
// getRow(lst: [[] as [Int], [1], [1, 2, 3]], x: 3) == [(2, 2)]
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
// your code here
}
```
} // missing return in global function expected to return '[(Int, Int)]'
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
// your code here
}
```swift
// You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of tuples, [(x1, y1), (x2, y2) ...] such that
// each tuple is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// getRow(lst: [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], x: 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]
// getRow(lst: [] as [[Int]], x: 1) == [] as [(Int, Int)]
// getRow(lst: [[] as [Int], [1], [1, 2, 3]], x: 3) == [(2, 2)]
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
// your code here
}
```
} // missing return in global function expected to return '[(Int, Int)]'
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
var result: [(Int, Int)] = []
for (i, row) in lst.enumerated() {
for (j, val) in row.enumerated() {
if val == x {
result.append((i, j))
}
}
}
return result
}
```swift
// You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of tuples, [(x1, y1), (x2, y2) ...] such that
// each tuple is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// getRow(lst: [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], x: 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]
// getRow(lst: [] as [[Int]], x: 1) == [] as [(Int, Int)]
// getRow(lst: [[] as [Int], [1], [1, 2, 3]], x: 3) == [(2, 2)]
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
var result: [(Int, Int)] = []
for (i, row) in lst.enumerated() {
for (j, val) in row.enumerated() {
if val == x {
result.append((i, j))
}
}
}
return result
}
```
// XCTAssertTrue failed
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
var result: [(Int, Int)] = []
for (i, row) in lst.enumerated() {
for (j, item) in row.enumerated() {
if item == x {
result.append((i, j))
}
}
}
return result
}
```swift
// You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of tuples, [(x1, y1), (x2, y2) ...] such that
// each tuple is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// getRow(lst: [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], x: 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]
// getRow(lst: [] as [[Int]], x: 1) == [] as [(Int, Int)]
// getRow(lst: [[] as [Int], [1], [1, 2, 3]], x: 3) == [(2, 2)]
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
var result: [(Int, Int)] = []
for (i, row) in lst.enumerated() {
for (j, item) in row.enumerated() {
if item == x {
result.append((i, j))
}
}
}
return result
}
```
// XCTAssertTrue failed
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
return []
}
```swift
// You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of tuples, [(x1, y1), (x2, y2) ...] such that
// each tuple is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// getRow(lst: [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], x: 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]
// getRow(lst: [] as [[Int]], x: 1) == [] as [(Int, Int)]
// getRow(lst: [[] as [Int], [1], [1, 2, 3]], x: 3) == [(2, 2)]
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
return []
}
```
// XCTAssertTrue failed
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
var result: [(Int, Int)] = []
for (i, row) in lst.enumerated() {
for (j, item) in row.enumerated() {
if item == x {
result.append((i, j))
}
}
}
return result
}
```swift
// You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of tuples, [(x1, y1), (x2, y2) ...] such that
// each tuple is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// getRow(lst: [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], x: 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]
// getRow(lst: [] as [[Int]], x: 1) == [] as [(Int, Int)]
// getRow(lst: [[] as [Int], [1], [1, 2, 3]], x: 3) == [(2, 2)]
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
var result: [(Int, Int)] = []
for (i, row) in lst.enumerated() {
for (j, item) in row.enumerated() {
if item == x {
result.append((i, j))
}
}
}
return result
}
```
// XCTAssertTrue failed
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
return []
}
```swift
// You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of tuples, [(x1, y1), (x2, y2) ...] such that
// each tuple is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// getRow(lst: [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], x: 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]
// getRow(lst: [] as [[Int]], x: 1) == [] as [(Int, Int)]
// getRow(lst: [[] as [Int], [1], [1, 2, 3]], x: 3) == [(2, 2)]
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
return []
}
```
// XCTAssertTrue failed
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
var result: [(Int, Int)] = []
for (i, row) in lst.enumerated() {
for (j, value) in row.enumerated() {
if value == x {
result.append((i, j))
}
}
}
return result
}
```swift
// You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of tuples, [(x1, y1), (x2, y2) ...] such that
// each tuple is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// getRow(lst: [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], x: 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]
// getRow(lst: [] as [[Int]], x: 1) == [] as [(Int, Int)]
// getRow(lst: [[] as [Int], [1], [1, 2, 3]], x: 3) == [(2, 2)]
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
var result: [(Int, Int)] = []
for (i, row) in lst.enumerated() {
for (j, value) in row.enumerated() {
if value == x {
result.append((i, j))
}
}
}
return result
}
```
// XCTAssertTrue failed
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
var result: [(Int, Int)] = []
for (i, row) in lst.enumerated() {
for (j, value) in row.enumerated() {
if value == x {
result.append((i, j))
}
}
}
return result
}
```swift
// You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of tuples, [(x1, y1), (x2, y2) ...] such that
// each tuple is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// getRow(lst: [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], x: 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]
// getRow(lst: [] as [[Int]], x: 1) == [] as [(Int, Int)]
// getRow(lst: [[] as [Int], [1], [1, 2, 3]], x: 3) == [(2, 2)]
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
var result: [(Int, Int)] = []
for (i, row) in lst.enumerated() {
for (j, value) in row.enumerated() {
if value == x {
result.append((i, j))
}
}
}
return result
}
```
// XCTAssertTrue failed
func sortArray(array: [Int]) -> [Int] {
// Write your code here
}
```swift
// Given an array of non-negative integers, return a coswift of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// sortArray(array: [] as [Int]) == [] as [Int]
// sortArray(array: [5]) == [5]
// sortArray(array: [2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5]
// sortArray(array: [2, 4, 3, 0, 1, 5, 6]) == [6, 5, 4, 3, 2, 1, 0]
func sortArray(array: [Int]) -> [Int] {
// Write your code here
}
```
} // missing return in global function expected to return '[Int]'
func sortArray(array: [Int]) -> [Int] {
var result = array
if array.count > 1 {
let sum = array.first! + array.last!
if sum % 2 == 0 {
result.sort { $0 > $1 }
} else {
result.sort { $0 < $1 }
}
}
return result
}
```swift
// Given an array of non-negative integers, return a coswift of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// sortArray(array: [] as [Int]) == [] as [Int]
// sortArray(array: [5]) == [5]
// sortArray(array: [2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5]
// sortArray(array: [2, 4, 3, 0, 1, 5, 6]) == [6, 5, 4, 3, 2, 1, 0]
func sortArray(array: [Int]) -> [Int] {
var result = array
if array.count > 1 {
let sum = array.first! + array.last!
if sum % 2 == 0 {
result.sort { $0 > $1 }
} else {
result.sort { $0 < $1 }
}
}
return result
}
```
func sortArray(array: [Int]) -> [Int] {
// Write your code here
}
```swift
// Given an array of non-negative integers, return a coswift of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// sortArray(array: [] as [Int]) == [] as [Int]
// sortArray(array: [5]) == [5]
// sortArray(array: [2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5]
// sortArray(array: [2, 4, 3, 0, 1, 5, 6]) == [6, 5, 4, 3, 2, 1, 0]
func sortArray(array: [Int]) -> [Int] {
// Write your code here
}
```
} // missing return in global function expected to return '[Int]'
func sortArray(array: [Int]) -> [Int] {
// Write your code here
var result = array
if result.count == 0 {
return result
}
let sum = result[0] + result[result.count - 1]
if sum % 2 == 0 {
result.sort(by: >)
} else {
result.sort(by: <)
}
return result
}
```swift
// Given an array of non-negative integers, return a coswift of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// sortArray(array: [] as [Int]) == [] as [Int]
// sortArray(array: [5]) == [5]
// sortArray(array: [2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5]
// sortArray(array: [2, 4, 3, 0, 1, 5, 6]) == [6, 5, 4, 3, 2, 1, 0]
func sortArray(array: [Int]) -> [Int] {
// Write your code here
var result = array
if result.count == 0 {
return result
}
let sum = result[0] + result[result.count - 1]
if sum % 2 == 0 {
result.sort(by: >)
} else {
result.sort(by: <)
}
return result
}
```
func sortArray(array: [Int]) -> [Int] {
return []
}
```swift
// Given an array of non-negative integers, return a coswift of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// sortArray(array: [] as [Int]) == [] as [Int]
// sortArray(array: [5]) == [5]
// sortArray(array: [2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5]
// sortArray(array: [2, 4, 3, 0, 1, 5, 6]) == [6, 5, 4, 3, 2, 1, 0]
func sortArray(array: [Int]) -> [Int] {
return []
}
```
// XCTAssertTrue failed
func sortArray(array: [Int]) -> [Int] {
// Write your code here.
}
```swift
// Given an array of non-negative integers, return a coswift of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// sortArray(array: [] as [Int]) == [] as [Int]
// sortArray(array: [5]) == [5]
// sortArray(array: [2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5]
// sortArray(array: [2, 4, 3, 0, 1, 5, 6]) == [6, 5, 4, 3, 2, 1, 0]
func sortArray(array: [Int]) -> [Int] {
// Write your code here.
}
```
} // missing return in global function expected to return '[Int]'
func sortArray(array: [Int]) -> [Int] {
var result = array
if array.count > 1 {
let sum = array.first! + array.last!
if sum % 2 == 0 {
result.sort { $0 > $1 }
} else {
result.sort { $0 < $1 }
}
}
return result
}
```swift
// Given an array of non-negative integers, return a coswift of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// sortArray(array: [] as [Int]) == [] as [Int]
// sortArray(array: [5]) == [5]
// sortArray(array: [2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5]
// sortArray(array: [2, 4, 3, 0, 1, 5, 6]) == [6, 5, 4, 3, 2, 1, 0]
func sortArray(array: [Int]) -> [Int] {
var result = array
if array.count > 1 {
let sum = array.first! + array.last!
if sum % 2 == 0 {
result.sort { $0 > $1 }
} else {
result.sort { $0 < $1 }
}
}
return result
}
```
func sortArray(array: [Int]) -> [Int] {
return []
}
```swift
// Given an array of non-negative integers, return a coswift of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// sortArray(array: [] as [Int]) == [] as [Int]
// sortArray(array: [5]) == [5]
// sortArray(array: [2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5]
// sortArray(array: [2, 4, 3, 0, 1, 5, 6]) == [6, 5, 4, 3, 2, 1, 0]
func sortArray(array: [Int]) -> [Int] {
return []
}
```
// XCTAssertTrue failed
func sortArray(array: [Int]) -> [Int] {
// Write your code here.
return []
}
```swift
// Given an array of non-negative integers, return a coswift of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// sortArray(array: [] as [Int]) == [] as [Int]
// sortArray(array: [5]) == [5]
// sortArray(array: [2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5]
// sortArray(array: [2, 4, 3, 0, 1, 5, 6]) == [6, 5, 4, 3, 2, 1, 0]
func sortArray(array: [Int]) -> [Int] {
// Write your code here.
return []
}
```
// XCTAssertTrue failed
func sortArray(array: [Int]) -> [Int] {
var result = array
if array.count > 1 {
let sum = array.first! + array.last!
if sum % 2 == 0 {
result.sort(by: >)
} else {
result.sort(by: <)
}
}
return result
}
```swift
// Given an array of non-negative integers, return a coswift of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// sortArray(array: [] as [Int]) == [] as [Int]
// sortArray(array: [5]) == [5]
// sortArray(array: [2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5]
// sortArray(array: [2, 4, 3, 0, 1, 5, 6]) == [6, 5, 4, 3, 2, 1, 0]
func sortArray(array: [Int]) -> [Int] {
var result = array
if array.count > 1 {
let sum = array.first! + array.last!
if sum % 2 == 0 {
result.sort(by: >)
} else {
result.sort(by: <)
}
}
return result
}
```
func encrypt(s: String) -> String {
var result = ""
for char in s {
if let index = alphabet.index(of: char) {
let newIndex = index.advanced(by: 2)
if newIndex >= alphabet.count {
result += alphabet[newIndex - alphabet.count]
} else {
result += alphabet[newIndex]
}
}
}
return result
}
func decrypt(s: String) -> String {
var result = ""
for char in s {
if let index = alphabet.index(of: char) {
let newIndex = index.advanced(by: -2)
if newIndex < 0 {
result += alphabet[alphabet.count + newIndex]
} else {
result += alphabet[newIndex]
}
}
}
return result
}
```swift
// Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// encrypt(s: "hi") == "lm"
// encrypt(s: "asdfghjkl") == "ewhjklnop"
// encrypt(s: "gf") == "kj"
// encrypt(s: "et") == "ix"
func encrypt(s: String) -> String {
var result = ""
for char in s {
if let index = alphabet.index(of: char) {
let newIndex = index.advanced(by: 2)
if newIndex >= alphabet.count {
result += alphabet[newIndex - alphabet.count]
} else {
result += alphabet[newIndex]
}
}
}
return result
}
// Create a function decrypt that takes a string as an argument and
// returns a string decrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift up by two multiplied to two places.
// For example:
// decrypt(s: "lm") == "hi"
// decrypt(s: "ewhjklnop") == "asdfghjkl"
// decrypt(s: "kj") == "gf"
// decrypt(s: "ix") == "et"
func decrypt(s: String) -> String {
var result = ""
for char in s {
if let index = alphabet.index(of: char) {
let newIndex = index.advanced(by: -2)
if newIndex < 0 {
result += alphabet[alphabet.count + newIndex]
} else {
result += alphabet[newIndex]
}
}
}
return result
}
```
if let index = alphabet.index(of: char) { // cannot find 'alphabet' in scope
if newIndex >= alphabet.count { // cannot find 'alphabet' in scope
result += alphabet[newIndex - alphabet.count] // cannot find 'alphabet' in scope
result += alphabet[newIndex - alphabet.count] // cannot find 'alphabet' in scope
result += alphabet[newIndex] // cannot find 'alphabet' in scope
if let index = alphabet.index(of: char) { // cannot find 'alphabet' in scope
result += alphabet[alphabet.count + newIndex] // cannot find 'alphabet' in scope
result += alphabet[alphabet.count + newIndex] // cannot find 'alphabet' in scope
result += alphabet[newIndex] // cannot find 'alphabet' in scope
func encrypt(s: String) -> String {
var encrypted = ""
for char in s {
if let index = alphabet.firstIndex(of: char) {
let newIndex = index + 2
if newIndex >= alphabet.count {
encrypted += alphabet[newIndex - alphabet.count]
} else {
encrypted += alphabet[newIndex]
}
}
}
return encrypted
}
func decrypt(s: String) -> String {
var decrypted = ""
for char in s {
if let index = alphabet.firstIndex(of: char) {
let newIndex = index - 2
if newIndex < 0 {
decrypted += alphabet[alphabet.count + newIndex]
} else {
decrypted += alphabet[newIndex]
}
}
}
return decrypted
}
func reverse(s: String) -> String {
var reversed = ""
for char in s {
reversed = String(char) + reversed
}
return reversed
}
```swift
// Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// encrypt(s: "hi") == "lm"
// encrypt(s: "asdfghjkl") == "ewhjklnop"
// encrypt(s: "gf") == "kj"
// encrypt(s: "et") == "ix"
func encrypt(s: String) -> String {
var encrypted = ""
for char in s {
if let index = alphabet.firstIndex(of: char) {
let newIndex = index + 2
if newIndex >= alphabet.count {
encrypted += alphabet[newIndex - alphabet.count]
} else {
encrypted += alphabet[newIndex]
}
}
}
return encrypted
}
// Create a function decrypt that takes a string as an argument and
// returns a string decrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift up by two multiplied to two places.
// For example:
// decrypt(s: "lm") == "hi"
// decrypt(s: "ewhjklnop") == "asdfghjkl"
// decrypt(s: "kj") == "gf"
// decrypt(s: "ix") == "et"
func decrypt(s: String) -> String {
var decrypted = ""
for char in s {
if let index = alphabet.firstIndex(of: char) {
let newIndex = index - 2
if newIndex < 0 {
decrypted += alphabet[alphabet.count + newIndex]
} else {
decrypted += alphabet[newIndex]
}
}
}
return decrypted
}
// Create a function that takes a string as an argument and returns
// a string with the letters reversed.
// For example:
// reverse(s: "hi") == "ih"
// reverse(s: "asdfghjkl") == "lkjhgfdsa"
// reverse(s: "gf") == "fg"
// reverse(s: "et") == "te"
func reverse(s: String) -> String {
var reversed = ""
for char in s {
reversed = String(char) + reversed
}
return reversed
}
// Create a function that takes a string as an argument and returns
// a string with the letters reversed.
// For example:
// reverse(s: "hi") == "ih"
// reverse(s: "asdfghjkl") == "lkjhgfdsa"
// reverse(s: "gf") == "fg"
// reverse(s: "et") == "te"
func reverse(s: String) -> String {
var reversed = ""
for char in s {
reversed = String(char) + reversed
}
return reversed
}
// Create a function that takes a string as an argument and returns
// a string with the letters reversed.
// For example:
// reverse(s: "hi") == "ih"
// reverse(s: "asdfghjkl") == "lkjhgfdsa"
// reverse(s: "gf") == "fg"
// reverse(s: "et") == "te"
func reverse(s: String) -> String {
var reversed = ""
for char in s {
reversed = String(char) + reversed
}
return reversed
}
// Create a function that takes a string as an argument and returns
// a string with the letters reversed.
// For example:
// reverse(s: "hi") == "ih"
// reverse(s: "asdfghjkl") == "lkjhgfdsa"
// reverse(s: "gf") == "fg"
// reverse(s: "et") == "te"
func reverse(s: String) -> String {
var reversed = ""
for char in s {
reversed = String(char) + reversed
}
return reversed
}
// Create a function that takes a string as an argument and returns
// a string with the letters reversed.
// For example:
// reverse(s: "hi") == "ih"
// reverse(s: "asdfghjkl") == "lkjhgfdsa"
// reverse(s: "gf") == "fg"
// reverse(s: "et") == "te"
func reverse(s: String) -> String {
var reversed = ""
for char in s {
reversed = String(char) + reversed
}
return reversed
}
// Create a function that takes a string as an argument and returns
// a string with the letters reversed.
// For example:
// reverse(s: "hi") == "ih"
// reverse(s: "asdfghjkl") == "lkjhgfdsa"
// reverse(s: "gf") == "fg"
// reverse(s: "et") == "te"
func reverse(s: String) -> String {
var reversed = ""
for char
if let index = alphabet.firstIndex(of: char) { // cannot find 'alphabet' in scope
if newIndex >= alphabet.count { // cannot find 'alphabet' in scope
encrypted += alphabet[newIndex - alphabet.count] // cannot find 'alphabet' in scope
encrypted += alphabet[newIndex - alphabet.count] // cannot find 'alphabet' in scope
encrypted += alphabet[newIndex] // cannot find 'alphabet' in scope
if let index = alphabet.firstIndex(of: char) { // cannot find 'alphabet' in scope
decrypted += alphabet[alphabet.count + newIndex] // cannot find 'alphabet' in scope
decrypted += alphabet[alphabet.count + newIndex] // cannot find 'alphabet' in scope
decrypted += alphabet[newIndex] // cannot find 'alphabet' in scope
func encrypt(s: String) -> String {
var encrypted = ""
for char in s {
if let index = alphabet.firstIndex(of: char) {
let newIndex = index + 2
if newIndex >= alphabet.count {
encrypted.append(alphabet[newIndex - alphabet.count])
} else {
encrypted.append(alphabet[newIndex])
}
}
}
return encrypted
}
```swift
// Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// encrypt(s: "hi") == "lm"
// encrypt(s: "asdfghjkl") == "ewhjklnop"
// encrypt(s: "gf") == "kj"
// encrypt(s: "et") == "ix"
func encrypt(s: String) -> String {
var encrypted = ""
for char in s {
if let index = alphabet.firstIndex(of: char) {
let newIndex = index + 2
if newIndex >= alphabet.count {
encrypted.append(alphabet[newIndex - alphabet.count])
} else {
encrypted.append(alphabet[newIndex])
}
}
}
return encrypted
}
```
if let index = alphabet.firstIndex(of: char) { // cannot find 'alphabet' in scope
if newIndex >= alphabet.count { // cannot find 'alphabet' in scope
encrypted.append(alphabet[newIndex - alphabet.count]) // cannot find 'alphabet' in scope
encrypted.append(alphabet[newIndex - alphabet.count]) // cannot find 'alphabet' in scope
encrypted.append(alphabet[newIndex]) // cannot find 'alphabet' in scope
func encrypt(s: String) -> String {
var result = ""
for char in s {
if let index = alphabet.index(of: char) {
let newIndex = index + 2
if newIndex > alphabet.count - 1 {
result += alphabet[newIndex - alphabet.count]
} else {
result += alphabet[newIndex]
}
}
}
return result
}
```swift
// Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// encrypt(s: "hi") == "lm"
// encrypt(s: "asdfghjkl") == "ewhjklnop"
// encrypt(s: "gf") == "kj"
// encrypt(s: "et") == "ix"
func encrypt(s: String) -> String {
var result = ""
for char in s {
if let index = alphabet.index(of: char) {
let newIndex = index + 2
if newIndex > alphabet.count - 1 {
result += alphabet[newIndex - alphabet.count]
} else {
result += alphabet[newIndex]
}
}
}
return result
}
```
if let index = alphabet.index(of: char) { // cannot find 'alphabet' in scope
if newIndex > alphabet.count - 1 { // cannot find 'alphabet' in scope
result += alphabet[newIndex - alphabet.count] // cannot find 'alphabet' in scope
result += alphabet[newIndex - alphabet.count] // cannot find 'alphabet' in scope
result += alphabet[newIndex] // cannot find 'alphabet' in scope
func encrypt(s: String) -> String {
var result = ""
for char in s {
if let index = alphabet.firstIndex(of: char) {
let newIndex = index + 2
if newIndex > alphabet.count - 1 {
result.append(alphabet[newIndex - alphabet.count])
} else {
result.append(alphabet[newIndex])
}
}
}
return result
}
```swift
// Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// encrypt(s: "hi") == "lm"
// encrypt(s: "asdfghjkl") == "ewhjklnop"
// encrypt(s: "gf") == "kj"
// encrypt(s: "et") == "ix"
func encrypt(s: String) -> String {
var result = ""
for char in s {
if let index = alphabet.firstIndex(of: char) {
let newIndex = index + 2
if newIndex > alphabet.count - 1 {
result.append(alphabet[newIndex - alphabet.count])
} else {
result.append(alphabet[newIndex])
}
}
}
return result
}
```
if let index = alphabet.firstIndex(of: char) { // cannot find 'alphabet' in scope
if newIndex > alphabet.count - 1 { // cannot find 'alphabet' in scope
result.append(alphabet[newIndex - alphabet.count]) // cannot find 'alphabet' in scope
result.append(alphabet[newIndex - alphabet.count]) // cannot find 'alphabet' in scope
result.append(alphabet[newIndex]) // cannot find 'alphabet' in scope
func encrypt(s: String) -> String {
var encrypted = ""
for char in s {
if let index = alphabet.firstIndex(of: char) {
let newIndex = index + 2
if newIndex > alphabet.count - 1 {
encrypted += alphabet[newIndex - alphabet.count]
} else {
encrypted += alphabet[newIndex]
}
}
}
return encrypted
}
func decrypt(s: String) -> String {
var decrypted = ""
for char in s {
if let index = alphabet.firstIndex(of: char) {
let newIndex = index - 2
if newIndex < 0 {
decrypted += alphabet[alphabet.count + newIndex]
} else {
decrypted += alphabet[newIndex]
}
}
}
return decrypted
}
```swift
// Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// encrypt(s: "hi") == "lm"
// encrypt(s: "asdfghjkl") == "ewhjklnop"
// encrypt(s: "gf") == "kj"
// encrypt(s: "et") == "ix"
func encrypt(s: String) -> String {
var encrypted = ""
for char in s {
if let index = alphabet.firstIndex(of: char) {
let newIndex = index + 2
if newIndex > alphabet.count - 1 {
encrypted += alphabet[newIndex - alphabet.count]
} else {
encrypted += alphabet[newIndex]
}
}
}
return encrypted
}
// Create a function decrypt that takes a string as an argument and
// returns a string decrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift up by two multiplied to two places.
// For example:
// decrypt(s: "lm") == "hi"
// decrypt(s: "ewhjklnop") == "asdfghjkl"
// decrypt(s: "kj") == "gf"
// decrypt(s: "ix") == "et"
func decrypt(s: String) -> String {
var decrypted = ""
for char in s {
if let index = alphabet.firstIndex(of: char) {
let newIndex = index - 2
if newIndex < 0 {
decrypted += alphabet[alphabet.count + newIndex]
} else {
decrypted += alphabet[newIndex]
}
}
}
return decrypted
}
```
if let index = alphabet.firstIndex(of: char) { // cannot find 'alphabet' in scope
if newIndex > alphabet.count - 1 { // cannot find 'alphabet' in scope
encrypted += alphabet[newIndex - alphabet.count] // cannot find 'alphabet' in scope
encrypted += alphabet[newIndex - alphabet.count] // cannot find 'alphabet' in scope
encrypted += alphabet[newIndex] // cannot find 'alphabet' in scope
if let index = alphabet.firstIndex(of: char) { // cannot find 'alphabet' in scope
decrypted += alphabet[alphabet.count + newIndex] // cannot find 'alphabet' in scope
decrypted += alphabet[alphabet.count + newIndex] // cannot find 'alphabet' in scope
decrypted += alphabet[newIndex] // cannot find 'alphabet' in scope
func encrypt(s: String) -> String {
var encryptedString = ""
for character in s {
if let index = alphabet.firstIndex(of: character) {
let newIndex = index + 2
if newIndex > alphabet.count - 1 {
let newIndex = newIndex - alphabet.count
encryptedString += alphabet[newIndex]
} else {
encryptedString += alphabet[newIndex]
}
}
}
return encryptedString
}
```swift
// Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// encrypt(s: "hi") == "lm"
// encrypt(s: "asdfghjkl") == "ewhjklnop"
// encrypt(s: "gf") == "kj"
// encrypt(s: "et") == "ix"
func encrypt(s: String) -> String {
var encryptedString = ""
for character in s {
if let index = alphabet.firstIndex(of: character) {
let newIndex = index + 2
if newIndex > alphabet.count - 1 {
let newIndex = newIndex - alphabet.count
encryptedString += alphabet[newIndex]
} else {
encryptedString += alphabet[newIndex]
}
}
}
return encryptedString
}
```
if let index = alphabet.firstIndex(of: character) { // cannot find 'alphabet' in scope
if newIndex > alphabet.count - 1 { // cannot find 'alphabet' in scope
let newIndex = newIndex - alphabet.count // cannot find 'alphabet' in scope
encryptedString += alphabet[newIndex] // cannot find 'alphabet' in scope
encryptedString += alphabet[newIndex] // cannot find 'alphabet' in scope
func encrypt(s: String) -> String {
var result = ""
for char in s {
if let index = alphabet.index(of: char) {
let newIndex = index.advanced(by: 2)
if newIndex > alphabet.count - 1 {
result += alphabet[newIndex - alphabet.count]
} else {
result += alphabet[newIndex]
}
}
}
return result
}
```swift
// Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// encrypt(s: "hi") == "lm"
// encrypt(s: "asdfghjkl") == "ewhjklnop"
// encrypt(s: "gf") == "kj"
// encrypt(s: "et") == "ix"
func encrypt(s: String) -> String {
var result = ""
for char in s {
if let index = alphabet.index(of: char) {
let newIndex = index.advanced(by: 2)
if newIndex > alphabet.count - 1 {
result += alphabet[newIndex - alphabet.count]
} else {
result += alphabet[newIndex]
}
}
}
return result
}
```
if let index = alphabet.index(of: char) { // cannot find 'alphabet' in scope
if newIndex > alphabet.count - 1 { // cannot find 'alphabet' in scope
result += alphabet[newIndex - alphabet.count] // cannot find 'alphabet' in scope
result += alphabet[newIndex - alphabet.count] // cannot find 'alphabet' in scope
result += alphabet[newIndex] // cannot find 'alphabet' in scope
func encrypt(s: String) -> String {
var encrypted = ""
for char in s {
if let index = alphabet.index(of: char) {
let newIndex = index.advanced(by: 2)
if newIndex > alphabet.count - 1 {
let newIndex = newIndex - alphabet.count
encrypted += alphabet[newIndex]
} else {
encrypted += alphabet[newIndex]
}
}
}
return encrypted
}
```swift
// Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// encrypt(s: "hi") == "lm"
// encrypt(s: "asdfghjkl") == "ewhjklnop"
// encrypt(s: "gf") == "kj"
// encrypt(s: "et") == "ix"
func encrypt(s: String) -> String {
var encrypted = ""
for char in s {
if let index = alphabet.index(of: char) {
let newIndex = index.advanced(by: 2)
if newIndex > alphabet.count - 1 {
let newIndex = newIndex - alphabet.count
encrypted += alphabet[newIndex]
} else {
encrypted += alphabet[newIndex]
}
}
}
return encrypted
}
```
if let index = alphabet.index(of: char) { // cannot find 'alphabet' in scope
if newIndex > alphabet.count - 1 { // cannot find 'alphabet' in scope
let newIndex = newIndex - alphabet.count // cannot find 'alphabet' in scope
encrypted += alphabet[newIndex] // cannot find 'alphabet' in scope
encrypted += alphabet[newIndex] // cannot find 'alphabet' in scope
func encrypt(s: String) -> String {
var encryptedString = ""
for char in s {
if let index = alphabet.firstIndex(of: char) {
let newIndex = index + 2
if newIndex > alphabet.count - 1 {
let newIndex = newIndex - alphabet.count
encryptedString += alphabet[newIndex]
} else {
encryptedString += alphabet[newIndex]
}
}
}
return encryptedString
}
func decrypt(s: String) -> String {
var decryptedString = ""
for char in s {
if let index = alphabet.firstIndex(of: char) {
let newIndex = index - 2
if newIndex < 0 {
let newIndex = newIndex + alphabet.count
decryptedString += alphabet[newIndex]
} else {
decryptedString += alphabet[newIndex]
}
}
}
return decryptedString
}
```swift
// Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// encrypt(s: "hi") == "lm"
// encrypt(s: "asdfghjkl") == "ewhjklnop"
// encrypt(s: "gf") == "kj"
// encrypt(s: "et") == "ix"
func encrypt(s: String) -> String {
var encryptedString = ""
for char in s {
if let index = alphabet.firstIndex(of: char) {
let newIndex = index + 2
if newIndex > alphabet.count - 1 {
let newIndex = newIndex - alphabet.count
encryptedString += alphabet[newIndex]
} else {
encryptedString += alphabet[newIndex]
}
}
}
return encryptedString
}
// Create a function decrypt that takes a string as an argument and
// returns a string decrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift up by two multiplied to two places.
// For example:
// decrypt(s: "lm") == "hi"
// decrypt(s: "ewhjklnop") == "asdfghjkl"
// decrypt(s: "kj") == "gf"
// decrypt(s: "ix") == "et"
func decrypt(s: String) -> String {
var decryptedString = ""
for char in s {
if let index = alphabet.firstIndex(of: char) {
let newIndex = index - 2
if newIndex < 0 {
let newIndex = newIndex + alphabet.count
decryptedString += alphabet[newIndex]
} else {
decryptedString += alphabet[newIndex]
}
}
}
return decryptedString
}
```
if let index = alphabet.firstIndex(of: char) { // cannot find 'alphabet' in scope
if newIndex > alphabet.count - 1 { // cannot find 'alphabet' in scope
let newIndex = newIndex - alphabet.count // cannot find 'alphabet' in scope
encryptedString += alphabet[newIndex] // cannot find 'alphabet' in scope
encryptedString += alphabet[newIndex] // cannot find 'alphabet' in scope
if let index = alphabet.firstIndex(of: char) { // cannot find 'alphabet' in scope
let newIndex = newIndex + alphabet.count // cannot find 'alphabet' in scope
decryptedString += alphabet[newIndex] // cannot find 'alphabet' in scope
decryptedString += alphabet[newIndex] // cannot find 'alphabet' in scope
func nextSmallest(lst: [Int]) -> Int? {
// your code here
}
```swift
// You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return nil if there is no such element.
// nextSmallest(lst: [1, 2, 3, 4, 5]) == 2
// nextSmallest(lst: [5, 1, 4, 3, 2]) == 2
// nextSmallest(lst: [] as [Int]) == nil
// nextSmallest(lst: [1, 1]) == nil
func nextSmallest(lst: [Int]) -> Int? {
// your code here
}
```
} // missing return in global function expected to return 'Int?'
func nextSmallest(lst: [Int]) -> Int? {
var result: Int?
var min: Int?
var min2: Int?
for i in lst {
if min == nil || i < min! {
min = i
} else if min2 == nil || i < min2! {
min2 = i
}
}
if min2!= nil {
result = min2
}
return result
}
```swift
// You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return nil if there is no such element.
// nextSmallest(lst: [1, 2, 3, 4, 5]) == 2
// nextSmallest(lst: [5, 1, 4, 3, 2]) == 2
// nextSmallest(lst: [] as [Int]) == nil
// nextSmallest(lst: [1, 1]) == nil
func nextSmallest(lst: [Int]) -> Int? {
var result: Int?
var min: Int?
var min2: Int?
for i in lst {
if min == nil || i < min! {
min = i
} else if min2 == nil || i < min2! {
min2 = i
}
}
if min2!= nil {
result = min2
}
return result
}
```
if min2!= nil { // use of '=' in a boolean context, did you mean '=='?
if min2!= nil { // 'nil' cannot be assigned to type 'Int'
if min2!= nil { // '=' must have consistent whitespace on both sides
func nextSmallest(lst: [Int]) -> Int? {
// your code here
}
```swift
// You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return nil if there is no such element.
// nextSmallest(lst: [1, 2, 3, 4, 5]) == 2
// nextSmallest(lst: [5, 1, 4, 3, 2]) == 2
// nextSmallest(lst: [] as [Int]) == nil
// nextSmallest(lst: [1, 1]) == nil
func nextSmallest(lst: [Int]) -> Int? {
// your code here
}
```
} // missing return in global function expected to return 'Int?'
func nextSmallest(lst: [Int]) -> Int? {
guard lst.count > 1 else { return nil }
let sorted = lst.sorted()
let second = sorted[1]
let index = lst.firstIndex(of: second)
let next = lst[index! + 1]
return next
}
```swift
// You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return nil if there is no such element.
// nextSmallest(lst: [1, 2, 3, 4, 5]) == 2
// nextSmallest(lst: [5, 1, 4, 3, 2]) == 2
// nextSmallest(lst: [] as [Int]) == nil
// nextSmallest(lst: [1, 1]) == nil
func nextSmallest(lst: [Int]) -> Int? {
guard lst.count > 1 else { return nil }
let sorted = lst.sorted()
let second = sorted[1]
let index = lst.firstIndex(of: second)
let next = lst[index! + 1]
return next
}
```
// XCTAssertTrue failed
func nextSmallest(lst: [Int]) -> Int? {
var sorted = lst.sorted()
if sorted.count < 2 {
return nil
}
return sorted[1]
}
```swift
// You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return nil if there is no such element.
// nextSmallest(lst: [1, 2, 3, 4, 5]) == 2
// nextSmallest(lst: [5, 1, 4, 3, 2]) == 2
// nextSmallest(lst: [] as [Int]) == nil
// nextSmallest(lst: [1, 1]) == nil
func nextSmallest(lst: [Int]) -> Int? {
var sorted = lst.sorted()
if sorted.count < 2 {
return nil
}
return sorted[1]
}
```
var sorted = lst.sorted() // variable 'sorted' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func nextSmallest(lst: [Int]) -> Int? {
guard lst.count > 1 else { return nil }
var smallest = lst[0]
var secondSmallest = lst[1]
for i in 1..<lst.count {
if lst[i] < smallest {
secondSmallest = smallest
smallest = lst[i]
} else if lst[i] < secondSmallest {
secondSmallest = lst[i]
}
}
return secondSmallest
}
```swift
// You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return nil if there is no such element.
// nextSmallest(lst: [1, 2, 3, 4, 5]) == 2
// nextSmallest(lst: [5, 1, 4, 3, 2]) == 2
// nextSmallest(lst: [] as [Int]) == nil
// nextSmallest(lst: [1, 1]) == nil
func nextSmallest(lst: [Int]) -> Int? {
guard lst.count > 1 else { return nil }
var smallest = lst[0]
var secondSmallest = lst[1]
for i in 1..<lst.count {
if lst[i] < smallest {
secondSmallest = smallest
smallest = lst[i]
} else if lst[i] < secondSmallest {
secondSmallest = lst[i]
}
}
return secondSmallest
}
```
// XCTAssertTrue failed
func nextSmallest(lst: [Int]) -> Int? {
guard lst.count > 1 else { return nil }
let sorted = lst.sorted()
let second = sorted[1]
let index = lst.firstIndex(of: second)
let next = lst[index! + 1]
return next
}
```swift
// You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return nil if there is no such element.
// nextSmallest(lst: [1, 2, 3, 4, 5]) == 2
// nextSmallest(lst: [5, 1, 4, 3, 2]) == 2
// nextSmallest(lst: [] as [Int]) == nil
// nextSmallest(lst: [1, 1]) == nil
func nextSmallest(lst: [Int]) -> Int? {
guard lst.count > 1 else { return nil }
let sorted = lst.sorted()
let second = sorted[1]
let index = lst.firstIndex(of: second)
let next = lst[index! + 1]
return next
}
```
// XCTAssertTrue failed
func nextSmallest(lst: [Int]) -> Int? {
guard lst.count > 1 else { return nil }
let sorted = lst.sorted()
let first = sorted[0]
let second = sorted[1]
return first == second? nil : second
}
```swift
// You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return nil if there is no such element.
// nextSmallest(lst: [1, 2, 3, 4, 5]) == 2
// nextSmallest(lst: [5, 1, 4, 3, 2]) == 2
// nextSmallest(lst: [] as [Int]) == nil
// nextSmallest(lst: [1, 1]) == nil
func nextSmallest(lst: [Int]) -> Int? {
guard lst.count > 1 else { return nil }
let sorted = lst.sorted()
let first = sorted[0]
let second = sorted[1]
return first == second? nil : second
}
```
return first == second? nil : second // cannot use optional chaining on non-optional value of type 'Int'
return first == second? nil : second // consecutive statements on a line must be separated by ';'
return first == second? nil : second // cannot convert return expression of type 'Bool' to return type 'Int?'
return first == second? nil : second // expected expression
return first == second? nil : second // 'nil' requires a contextual type
return first == second? nil : second // consecutive statements on a line must be separated by ';'
func nextSmallest(lst: [Int]) -> Int? {
guard lst.count > 1 else { return nil }
let sorted = lst.sorted()
let second = sorted[1]
let index = lst.firstIndex(of: second)
let next = lst.dropFirst(index! + 1)
return next.first
}
```swift
// You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return nil if there is no such element.
// nextSmallest(lst: [1, 2, 3, 4, 5]) == 2
// nextSmallest(lst: [5, 1, 4, 3, 2]) == 2
// nextSmallest(lst: [] as [Int]) == nil
// nextSmallest(lst: [1, 1]) == nil
func nextSmallest(lst: [Int]) -> Int? {
guard lst.count > 1 else { return nil }
let sorted = lst.sorted()
let second = sorted[1]
let index = lst.firstIndex(of: second)
let next = lst.dropFirst(index! + 1)
return next.first
}
```
// XCTAssertTrue failed
func nextSmallest(lst: [Int]) -> Int? {
guard lst.count > 1 else { return nil }
var sorted = lst.sorted()
let first = sorted.removeFirst()
let second = sorted.removeFirst()
return second
}
```swift
// You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return nil if there is no such element.
// nextSmallest(lst: [1, 2, 3, 4, 5]) == 2
// nextSmallest(lst: [5, 1, 4, 3, 2]) == 2
// nextSmallest(lst: [] as [Int]) == nil
// nextSmallest(lst: [1, 1]) == nil
func nextSmallest(lst: [Int]) -> Int? {
guard lst.count > 1 else { return nil }
var sorted = lst.sorted()
let first = sorted.removeFirst()
let second = sorted.removeFirst()
return second
}
```
let first = sorted.removeFirst() // initialization of immutable value 'first' was never used; consider replacing with assignment to '_' or removing it
// XCTAssertTrue failed
func isBored(S: String) -> Int {
let words = S.components(separatedBy: ".?!")
let bored = words.filter { $0.lowercased().hasPrefix("i") }
return bored.count
}
```swift
// You'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with the word "I".
// Sentences are delimited by '.', '?' or '!'.
// For example:
// isBored(S: "Hello world") == 0
// isBored(S: "The sky is blue. The sun is shining. I love this weather") == 1
func isBored(S: String) -> Int {
let words = S.components(separatedBy: ".?!")
let bored = words.filter { $0.lowercased().hasPrefix("i") }
return bored.count
}
```
// XCTAssertTrue failed
func isBored(S: String) -> Int {
let words = S.components(separatedBy: " ")
var boredoms = 0
for word in words {
if word.lowercased() == "i" {
boredoms += 1
}
}
return boredoms
}
```swift
// You'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with the word "I".
// Sentences are delimited by '.', '?' or '!'.
// For example:
// isBored(S: "Hello world") == 0
// isBored(S: "The sky is blue. The sun is shining. I love this weather") == 1
func isBored(S: String) -> Int {
let words = S.components(separatedBy: " ")
var boredoms = 0
for word in words {
if word.lowercased() == "i" {
boredoms += 1
}
}
return boredoms
}
```
// XCTAssertTrue failed
func isBored(S: String) -> Int {
let sentences = S.components(separatedBy: ".!?")
let bored = sentences.filter { $0.hasPrefix("I") }
return bored.count
}
```swift
// You'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with the word "I".
// Sentences are delimited by '.', '?' or '!'.
// For example:
// isBored(S: "Hello world") == 0
// isBored(S: "The sky is blue. The sun is shining. I love this weather") == 1
func isBored(S: String) -> Int {
let sentences = S.components(separatedBy: ".!?")
let bored = sentences.filter { $0.hasPrefix("I") }
return bored.count
}
```
// XCTAssertTrue failed
func isBored(S: String) -> Int {
let words = S.components(separatedBy: " ")
var bored = 0
for word in words {
if word.lowercased() == "i" {
bored += 1
}
}
return bored
}
```swift
// You'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with the word "I".
// Sentences are delimited by '.', '?' or '!'.
// For example:
// isBored(S: "Hello world") == 0
// isBored(S: "The sky is blue. The sun is shining. I love this weather") == 1
func isBored(S: String) -> Int {
let words = S.components(separatedBy: " ")
var bored = 0
for word in words {
if word.lowercased() == "i" {
bored += 1
}
}
return bored
}
```
// XCTAssertTrue failed
func isBored(S: String) -> Int {
let words = S.components(separatedBy: " ")
var boredoms = 0
for word in words {
if word.lowercased() == "i" {
boredoms += 1
}
}
return boredoms
}
```swift
// You'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with the word "I".
// Sentences are delimited by '.', '?' or '!'.
// For example:
// isBored(S: "Hello world") == 0
// isBored(S: "The sky is blue. The sun is shining. I love this weather") == 1
func isBored(S: String) -> Int {
let words = S.components(separatedBy: " ")
var boredoms = 0
for word in words {
if word.lowercased() == "i" {
boredoms += 1
}
}
return boredoms
}
```
// XCTAssertTrue failed
func isBored(S: String) -> Int {
let words = S.components(separatedBy: " ")
let sentences = words.joined(separator: " ").components(separatedBy: ".!?")
let bored = sentences.filter { $0.hasPrefix("I") }
return bored.count
}
```swift
// You'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with the word "I".
// Sentences are delimited by '.', '?' or '!'.
// For example:
// isBored(S: "Hello world") == 0
// isBored(S: "The sky is blue. The sun is shining. I love this weather") == 1
func isBored(S: String) -> Int {
let words = S.components(separatedBy: " ")
let sentences = words.joined(separator: " ").components(separatedBy: ".!?")
let bored = sentences.filter { $0.hasPrefix("I") }
return bored.count
}
```
// XCTAssertTrue failed
func isBored(S: String) -> Int {
let words = S.components(separatedBy: ".?!")
let bored = words.filter { $0.lowercased().hasPrefix("i") }
return bored.count
}
```swift
// You'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with the word "I".
// Sentences are delimited by '.', '?' or '!'.
// For example:
// isBored(S: "Hello world") == 0
// isBored(S: "The sky is blue. The sun is shining. I love this weather") == 1
func isBored(S: String) -> Int {
let words = S.components(separatedBy: ".?!")
let bored = words.filter { $0.lowercased().hasPrefix("i") }
return bored.count
}
```
// XCTAssertTrue failed
func isBored(S: String) -> Int {
let words = S.components(separatedBy: ".!?")
let bored = words.filter { $0.lowercased().hasPrefix("i") }
return bored.count
}
```swift
// You'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with the word "I".
// Sentences are delimited by '.', '?' or '!'.
// For example:
// isBored(S: "Hello world") == 0
// isBored(S: "The sky is blue. The sun is shining. I love this weather") == 1
func isBored(S: String) -> Int {
let words = S.components(separatedBy: ".!?")
let bored = words.filter { $0.lowercased().hasPrefix("i") }
return bored.count
}
```
// XCTAssertTrue failed
func isBored(S: String) -> Int {
let words = S.components(separatedBy: " ")
var bored = 0
for word in words {
if word.lowercased() == "i" {
bored += 1
}
}
return bored
}
```swift
// You'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with the word "I".
// Sentences are delimited by '.', '?' or '!'.
// For example:
// isBored(S: "Hello world") == 0
// isBored(S: "The sky is blue. The sun is shining. I love this weather") == 1
func isBored(S: String) -> Int {
let words = S.components(separatedBy: " ")
var bored = 0
for word in words {
if word.lowercased() == "i" {
bored += 1
}
}
return bored
}
```
// XCTAssertTrue failed
func isBored(S: String) -> Int {
let words = S.components(separatedBy: " ")
var bored = 0
for word in words {
if word.lowercased() == "i" {
bored += 1
}
}
return bored
}
```swift
// You'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with the word "I".
// Sentences are delimited by '.', '?' or '!'.
// For example:
// isBored(S: "Hello world") == 0
// isBored(S: "The sky is blue. The sun is shining. I love this weather") == 1
func isBored(S: String) -> Int {
let words = S.components(separatedBy: " ")
var bored = 0
for word in words {
if word.lowercased() == "i" {
bored += 1
}
}
return bored
}
```
// XCTAssertTrue failed
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z || y == x + z || z == x + y {
return true
}
return false
}
```swift
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z || y == x + z || z == x + y {
return true
}
return false
}
```
// XCTAssertTrue failed
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x.truncatingRemainder(dividingBy: 1) == 0 && y.truncatingRemainder(dividingBy: 1) == 0 && z.truncatingRemainder(dividingBy: 1) == 0 {
if x + y == z || x + z == y || y + z == x {
return true
} else {
return false
}
} else {
return false
}
}
```swift
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x.truncatingRemainder(dividingBy: 1) == 0 && y.truncatingRemainder(dividingBy: 1) == 0 && z.truncatingRemainder(dividingBy: 1) == 0 {
if x + y == z || x + z == y || y + z == x {
return true
} else {
return false
}
} else {
return false
}
}
```
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x.truncatingRemainder(dividingBy: 1) == 0 && y.truncatingRemainder(dividingBy: 1) == 0 && z.truncatingRemainder(dividingBy: 1) == 0 {
if x + y == z || x + z == y || y + z == x {
return true
}
}
return false
}
```swift
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x.truncatingRemainder(dividingBy: 1) == 0 && y.truncatingRemainder(dividingBy: 1) == 0 && z.truncatingRemainder(dividingBy: 1) == 0 {
if x + y == z || x + z == y || y + z == x {
return true
}
}
return false
}
```
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z || y == x + z || z == x + y {
return true
} else {
return false
}
}
```swift
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z || y == x + z || z == x + y {
return true
} else {
return false
}
}
```
// XCTAssertTrue failed
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x.truncatingRemainder(dividingBy: 1) == 0 && y.truncatingRemainder(dividingBy: 1) == 0 && z.truncatingRemainder(dividingBy: 1) == 0 {
if x == y + z || x == z + y || y == x + z || y == z + x || z == x + y || z == y + x {
return true
}
}
return false
}
```swift
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x.truncatingRemainder(dividingBy: 1) == 0 && y.truncatingRemainder(dividingBy: 1) == 0 && z.truncatingRemainder(dividingBy: 1) == 0 {
if x == y + z || x == z + y || y == x + z || y == z + x || z == x + y || z == y + x {
return true
}
}
return false
}
```
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z || y == x + z || z == x + y {
return true
}
return false
}
```swift
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z || y == x + z || z == x + y {
return true
}
return false
}
```
// XCTAssertTrue failed
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z || y == x + z || z == x + y {
return true
} else {
return false
}
}
```swift
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z || y == x + z || z == x + y {
return true
} else {
return false
}
}
```
// XCTAssertTrue failed
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == (y + z) || y == (x + z) || z == (x + y) {
return true
} else {
return false
}
}
```swift
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == (y + z) || y == (x + z) || z == (x + y) {
return true
} else {
return false
}
}
```
// XCTAssertTrue failed
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z || y == x + z || z == x + y {
return true
} else {
return false
}
}
```swift
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z || y == x + z || z == x + y {
return true
} else {
return false
}
}
```
// XCTAssertTrue failed
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z || y == x + z || z == x + y {
return true
}
return false
}
```swift
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z || y == x + z || z == x + y {
return true
}
return false
}
```
// XCTAssertTrue failed
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result += char.uppercased()
} else {
result += char.lowercased()
}
}
return result
}
func removeVowels(message: String) -> String {
var result = ""
for char in message {
if!"aeiou".contains(char) {
result += String(char)
}
}
return result
}
```swift
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result += char.uppercased()
} else {
result += char.lowercased()
}
}
return result
}
// Write a function that takes a string and returns a string with
// all the vowels removed.
// Examples:
// removeVowels(message: "This is a message") == "Ths s s mgsscg"
func removeVowels(message: String) -> String {
var result = ""
for char in message {
if!"aeiou".contains(char) {
result += String(char)
}
}
return result
}
// Write a function that takes a string and returns a string with
// all the vowels removed.
// Examples:
// removeVowels(message: "This is a message") == "Ths s s mgsscg"
func removeVowels(message: String) -> String {
var result = ""
for char in message {
if!"aeiou".contains(char) {
result += String(char)
}
}
return result
}
// Write a function that takes a string and returns a string with
// all the vowels removed.
// Examples:
// removeVowels(message: "This is a message") == "Ths s s mgsscg"
func removeVowels(message: String) -> String {
var result = ""
for char in message {
if!"aeiou".contains(char) {
result += String(char)
}
}
return result
}
// Write a function that takes a string and returns a string with
// all the vowels removed.
// Examples:
// removeVowels(message: "This is a message") == "Ths s s mgsscg"
func removeVowels(message: String) -> String {
var result = ""
for char in message {
if!"aeiou".contains(char) {
result += String(char)
}
}
return result
}
// Write a function that takes a string and returns a string with
// all the vowels removed.
// Examples:
// removeVowels(message: "This is a message") == "Ths s s mgsscg"
func removeVowels(message: String) -> String {
var result = ""
for char in message {
if!"aeiou".contains(char) {
result += String(char)
}
}
return result
}
// Write a function that takes a string and returns a string with
// all the vowels removed.
// Examples:
// removeVowels(message: "This is a message") == "Ths s s mgsscg"
func removeVowels(message: String) -> String {
var result = ""
for char in message {
if!"aeiou".contains(char) {
result += String(char)
}
}
return result
}
// Write a function that takes a string and returns a string with
// all the vowels removed.
// Examples:
// removeVowels(message: "This is a message") == "Ths s s mgsscg"
func removeVowels(message: String) -> String {
var result = ""
for char in message {
if!"aeiou".contains(char) {
result += String(char)
}
}
return result
}
// Write a function that takes a string and returns a string with
// all the vowels removed.
// Examples:
// removeVowels(message: "This is a message") == "Ths s s mgsscg"
func removeVowels(message: String) -> String {
var result = ""
for char in message {
if!"aeiou".contains(char) {
result += String(char)
}
}
return result
}
// Write a function that takes a string and returns a string with
// all the vowels removed.
// Examples:
// removeVowels(message: "This is a message") == "Ths s s mgsscg"
func removeVowels(message: String) -> String {
var result = ""
for char in message {
if!"aeiou".contains(char) {
result += String(char)
}
}
return result
}
// Write
if!"aeiou".contains(char) { // expected expression, var, or let in 'if' condition
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result.append(char.uppercased())
} else if char.isUppercase {
result.append(char.lowercased())
} else {
result.append(char)
}
}
return result
}
```swift
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result.append(char.uppercased())
} else if char.isUppercase {
result.append(char.lowercased())
} else {
result.append(char)
}
}
return result
}
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result.append(char.uppercased())
} else if char.isUppercase {
result.append(char.lowercased())
} else {
result.append(char)
}
}
return result
}
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result.append(char.uppercased())
} else if char.isUppercase {
result.append(char.lowercased())
} else {
result.append(char)
}
}
return result
}
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result.append(char.uppercased())
} else if char.isUppercase {
result.append(char.lowercased())
} else {
result.append(char)
}
}
return result
}
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result.append(char.uppercased())
} else if char.isUppercase {
result.append(char.lowercased())
} else {
result.append(char)
}
}
return result
}
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result.append(char.uppercased())
} else if char.isUppercase {
result.append(char.lowercased())
} else {
result.append(char
// XCTAssertTrue failed
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result.append(char.uppercased())
} else {
result.append(char.lowercased())
}
}
return result
}
```swift
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result.append(char.uppercased())
} else {
result.append(char.lowercased())
}
}
return result
}
```
// XCTAssertTrue failed
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result.append(char.uppercased())
} else {
result.append(char.lowercased())
}
}
return result
}
```swift
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result.append(char.uppercased())
} else {
result.append(char.lowercased())
}
}
return result
}
```
// XCTAssertTrue failed
func encode(message: String) -> String {
var encodedMessage = ""
for char in message {
if char.isLowercase {
encodedMessage.append(char.uppercased())
} else {
encodedMessage.append(char.lowercased())
}
}
return encodedMessage
}
```swift
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var encodedMessage = ""
for char in message {
if char.isLowercase {
encodedMessage.append(char.uppercased())
} else {
encodedMessage.append(char.lowercased())
}
}
return encodedMessage
}
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var encodedMessage = ""
for char in message {
if char.isLowercase {
encodedMessage.append(char.uppercased())
} else {
encodedMessage.append(char.lowercased())
}
}
return encodedMessage
}
```
// XCTAssertTrue failed
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result.append(char.uppercased())
} else {
result.append(char.lowercased())
}
}
return result
}
```swift
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result.append(char.uppercased())
} else {
result.append(char.lowercased())
}
}
return result
}
```
// XCTAssertTrue failed
func encode(message: String) -> String {
var encodedMessage = ""
for letter in message {
if letter.isLowercase {
encodedMessage.append(letter.uppercased())
} else {
encodedMessage.append(letter.lowercased())
}
}
return encodedMessage
}
```swift
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var encodedMessage = ""
for letter in message {
if letter.isLowercase {
encodedMessage.append(letter.uppercased())
} else {
encodedMessage.append(letter.lowercased())
}
}
return encodedMessage
}
```
// XCTAssertTrue failed
func encode(message: String) -> String {
var encoded = ""
for char in message {
if char.isLetter {
if char.isUppercase {
encoded.append(String(char).lowercased())
} else {
encoded.append(String(char).uppercased())
}
} else {
encoded.append(char)
}
}
return encoded
}
```swift
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var encoded = ""
for char in message {
if char.isLetter {
if char.isUppercase {
encoded.append(String(char).lowercased())
} else {
encoded.append(String(char).uppercased())
}
} else {
encoded.append(char)
}
}
return encoded
}
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var encoded = ""
for char in message {
if char.isLetter {
if char.isUppercase {
encoded.append(String(char).lowercased())
} else {
encoded.append(String(char).uppercased())
}
} else {
encoded.append(char)
}
}
return encoded
}
```
// XCTAssertTrue failed
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result.append(char.uppercased())
} else {
result.append(char.lowercased())
}
}
return result
}
```swift
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result.append(char.uppercased())
} else {
result.append(char.lowercased())
}
}
return result
}
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result.append(char.uppercased())
} else {
result.append(char.lowercased())
}
}
return result
}
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result.append(char.uppercased())
} else {
result.append(char.lowercased())
}
}
return result
}
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result.append(char.uppercased())
} else {
result.append(char.lowercased())
}
}
return result
}
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result.append(char.uppercased())
} else {
result.append(char.lowercased())
}
}
return result
}
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result.append(char.uppercased())
} else {
result.append(char.lowercased())
}
}
return result
}
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(
// XCTAssertTrue failed
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result.append(char.uppercased())
} else if char.isUppercase {
result.append(char.lowercased())
} else {
result.append(char)
}
}
return result
}
```swift
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var result = ""
for char in message {
if char.isLowercase {
result.append(char.uppercased())
} else if char.isUppercase {
result.append(char.lowercased())
} else {
result.append(char)
}
}
return result
}
```
// XCTAssertTrue failed
func skjkasdkd(lst: [Int]) -> Int {
var max = 0
var sum = 0
for i in lst {
if i > max {
max = i
}
}
var maxString = String(max)
for i in maxString {
if Int(String(i))!= nil {
sum += Int(String(i))!
}
}
return sum
}
```swift
// You are given an array of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// skjkasdkd(lst: [0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3]) == 10
// skjkasdkd(lst: [1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) == 25
// skjkasdkd(lst: [1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3]) == 13
// skjkasdkd(lst: [0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) == 11
// skjkasdkd(lst: [0, 81, 12, 3, 1, 21]) == 3
// skjkasdkd(lst: [0, 8, 1, 2, 1, 7]) == 7
func skjkasdkd(lst: [Int]) -> Int {
var max = 0
var sum = 0
for i in lst {
if i > max {
max = i
}
}
var maxString = String(max)
for i in maxString {
if Int(String(i))!= nil {
sum += Int(String(i))!
}
}
return sum
}
```
if Int(String(i))!= nil { // '=' must have consistent whitespace on both sides
if Int(String(i))!= nil { // 'nil' cannot be assigned to type 'Int'
if Int(String(i))!= nil { // use of '=' in a boolean context, did you mean '=='?
if Int(String(i))!= nil { // cannot assign through '!': function call returns immutable value
func skjkasdkd(lst: [Int]) -> Int {
var max = 0
var sum = 0
for i in lst {
if i > max {
max = i
}
}
var maxString = String(max)
for i in maxString {
if Int(String(i))!= nil {
sum += Int(String(i))!
}
}
return sum
}
```swift
// You are given an array of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// skjkasdkd(lst: [0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3]) == 10
// skjkasdkd(lst: [1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) == 25
// skjkasdkd(lst: [1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3]) == 13
// skjkasdkd(lst: [0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) == 11
// skjkasdkd(lst: [0, 81, 12, 3, 1, 21]) == 3
// skjkasdkd(lst: [0, 8, 1, 2, 1, 7]) == 7
func skjkasdkd(lst: [Int]) -> Int {
var max = 0
var sum = 0
for i in lst {
if i > max {
max = i
}
}
var maxString = String(max)
for i in maxString {
if Int(String(i))!= nil {
sum += Int(String(i))!
}
}
return sum
}
```
if Int(String(i))!= nil { // '=' must have consistent whitespace on both sides
if Int(String(i))!= nil { // 'nil' cannot be assigned to type 'Int'
if Int(String(i))!= nil { // use of '=' in a boolean context, did you mean '=='?
if Int(String(i))!= nil { // cannot assign through '!': function call returns immutable value
func skjkasdkd(lst: [Int]) -> Int {
var max = 0
for i in lst {
if i > max {
max = i
}
}
return max
}
```swift
// You are given an array of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// skjkasdkd(lst: [0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3]) == 10
// skjkasdkd(lst: [1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) == 25
// skjkasdkd(lst: [1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3]) == 13
// skjkasdkd(lst: [0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) == 11
// skjkasdkd(lst: [0, 81, 12, 3, 1, 21]) == 3
// skjkasdkd(lst: [0, 8, 1, 2, 1, 7]) == 7
func skjkasdkd(lst: [Int]) -> Int {
var max = 0
for i in lst {
if i > max {
max = i
}
}
return max
}
```
// XCTAssertTrue failed
func skjkasdkd(lst: [Int]) -> Int {
var max = 0
for i in lst {
if i > max {
max = i
}
}
var maxStr = String(max)
var maxArr = Array(maxStr)
var maxInt = 0
for i in maxArr {
maxInt += Int(String(i))!
}
return maxInt
}
```swift
// You are given an array of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// skjkasdkd(lst: [0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3]) == 10
// skjkasdkd(lst: [1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) == 25
// skjkasdkd(lst: [1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3]) == 13
// skjkasdkd(lst: [0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) == 11
// skjkasdkd(lst: [0, 81, 12, 3, 1, 21]) == 3
// skjkasdkd(lst: [0, 8, 1, 2, 1, 7]) == 7
func skjkasdkd(lst: [Int]) -> Int {
var max = 0
for i in lst {
if i > max {
max = i
}
}
var maxStr = String(max)
var maxArr = Array(maxStr)
var maxInt = 0
for i in maxArr {
maxInt += Int(String(i))!
}
return maxInt
}
```
var maxStr = String(max) // variable 'maxStr' was never mutated; consider changing to 'let' constant
var maxArr = Array(maxStr) // variable 'maxArr' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func skjkasdkd(lst: [Int]) -> Int {
var max = 0
for i in lst {
if i > max {
max = i
}
}
var maxStr = String(max)
var sum = 0
for i in maxStr {
sum += Int(String(i))!
}
return sum
}
```swift
// You are given an array of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// skjkasdkd(lst: [0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3]) == 10
// skjkasdkd(lst: [1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) == 25
// skjkasdkd(lst: [1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3]) == 13
// skjkasdkd(lst: [0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) == 11
// skjkasdkd(lst: [0, 81, 12, 3, 1, 21]) == 3
// skjkasdkd(lst: [0, 8, 1, 2, 1, 7]) == 7
func skjkasdkd(lst: [Int]) -> Int {
var max = 0
for i in lst {
if i > max {
max = i
}
}
var maxStr = String(max)
var sum = 0
for i in maxStr {
sum += Int(String(i))!
}
return sum
}
```
var maxStr = String(max) // variable 'maxStr' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func skjkasdkd(lst: [Int]) -> Int {
var max = 0
for i in lst {
if i > max {
max = i
}
}
return max
}
```swift
// You are given an array of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// skjkasdkd(lst: [0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3]) == 10
// skjkasdkd(lst: [1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) == 25
// skjkasdkd(lst: [1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3]) == 13
// skjkasdkd(lst: [0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) == 11
// skjkasdkd(lst: [0, 81, 12, 3, 1, 21]) == 3
// skjkasdkd(lst: [0, 8, 1, 2, 1, 7]) == 7
func skjkasdkd(lst: [Int]) -> Int {
var max = 0
for i in lst {
if i > max {
max = i
}
}
return max
}
```
// XCTAssertTrue failed
func skjkasdkd(lst: [Int]) -> Int {
var max = 0
for i in lst {
if i > max {
max = i
}
}
var str = String(max)
var sum = 0
for i in str {
sum += Int(String(i))!
}
return sum
}
```swift
// You are given an array of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// skjkasdkd(lst: [0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3]) == 10
// skjkasdkd(lst: [1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) == 25
// skjkasdkd(lst: [1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3]) == 13
// skjkasdkd(lst: [0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) == 11
// skjkasdkd(lst: [0, 81, 12, 3, 1, 21]) == 3
// skjkasdkd(lst: [0, 8, 1, 2, 1, 7]) == 7
func skjkasdkd(lst: [Int]) -> Int {
var max = 0
for i in lst {
if i > max {
max = i
}
}
var str = String(max)
var sum = 0
for i in str {
sum += Int(String(i))!
}
return sum
}
```
var str = String(max) // variable 'str' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func skjkasdkd(lst: [Int]) -> Int {
var max = 0
for i in lst {
if i > max {
max = i
}
}
var maxStr = String(max)
var sum = 0
for i in maxStr {
sum += Int(String(i))!
}
return sum
}
```swift
// You are given an array of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// skjkasdkd(lst: [0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3]) == 10
// skjkasdkd(lst: [1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) == 25
// skjkasdkd(lst: [1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3]) == 13
// skjkasdkd(lst: [0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) == 11
// skjkasdkd(lst: [0, 81, 12, 3, 1, 21]) == 3
// skjkasdkd(lst: [0, 8, 1, 2, 1, 7]) == 7
func skjkasdkd(lst: [Int]) -> Int {
var max = 0
for i in lst {
if i > max {
max = i
}
}
var maxStr = String(max)
var sum = 0
for i in maxStr {
sum += Int(String(i))!
}
return sum
}
```
var maxStr = String(max) // variable 'maxStr' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func skjkasdkd(lst: [Int]) -> Int {
var max = 0
for i in lst {
if i > max {
max = i
}
}
var maxStr = String(max)
var sum = 0
for i in maxStr {
sum += Int(String(i))!
}
return sum
}
```swift
// You are given an array of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// skjkasdkd(lst: [0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3]) == 10
// skjkasdkd(lst: [1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) == 25
// skjkasdkd(lst: [1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3]) == 13
// skjkasdkd(lst: [0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) == 11
// skjkasdkd(lst: [0, 81, 12, 3, 1, 21]) == 3
// skjkasdkd(lst: [0, 8, 1, 2, 1, 7]) == 7
func skjkasdkd(lst: [Int]) -> Int {
var max = 0
for i in lst {
if i > max {
max = i
}
}
var maxStr = String(max)
var sum = 0
for i in maxStr {
sum += Int(String(i))!
}
return sum
}
```
var maxStr = String(max) // variable 'maxStr' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func skjkasdkd(lst: [Int]) -> Int {
var max = 0
for i in lst {
if i > max {
max = i
}
}
var maxString = String(max)
var maxArray = Array(maxString)
var maxArrayInt = [Int]()
for i in maxArray {
maxArrayInt.append(Int(String(i))!)
}
var sum = 0
for i in maxArrayInt {
sum += i
}
return sum
}
```swift
// You are given an array of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// skjkasdkd(lst: [0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3]) == 10
// skjkasdkd(lst: [1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) == 25
// skjkasdkd(lst: [1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3]) == 13
// skjkasdkd(lst: [0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) == 11
// skjkasdkd(lst: [0, 81, 12, 3, 1, 21]) == 3
// skjkasdkd(lst: [0, 8, 1, 2, 1, 7]) == 7
func skjkasdkd(lst: [Int]) -> Int {
var max = 0
for i in lst {
if i > max {
max = i
}
}
var maxString = String(max)
var maxArray = Array(maxString)
var maxArrayInt = [Int]()
for i in maxArray {
maxArrayInt.append(Int(String(i))!)
}
var sum = 0
for i in maxArrayInt {
sum += i
}
return sum
}
```
var maxString = String(max) // variable 'maxString' was never mutated; consider changing to 'let' constant
var maxArray = Array(maxString) // variable 'maxArray' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func countUpTo(n: Int) -> [Int] {
var result = [Int]()
for i in 2...n {
if isPrime(n: i) {
result.append(i)
}
}
return result
}
func isPrime(n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2...n {
if n % i == 0 {
return false
}
}
return true
}
```swift
// Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// countUpTo(n: 5) == [2, 3]
// countUpTo(n: 11) == [2, 3, 5, 7]
// countUpTo(n: 0) == [] as [Int]
// countUpTo(n: 20) == [2, 3, 5, 7, 11, 13, 17, 19]
// countUpTo(n: 1) == [] as [Int]
// countUpTo(n: 18) == [2, 3, 5, 7, 11, 13, 17]
func countUpTo(n: Int) -> [Int] {
var result = [Int]()
for i in 2...n {
if isPrime(n: i) {
result.append(i)
}
}
return result
}
func isPrime(n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2...n {
if n % i == 0 {
return false
}
}
return true
}
```
// XCTAssertTrue failed
func countUpTo(n: Int) -> [Int] {
var result: [Int] = []
for i in 2...n {
if isPrime(n: i) {
result.append(i)
}
}
return result
}
func isPrime(n: Int) -> Bool {
if n == 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```swift
// Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// countUpTo(n: 5) == [2, 3]
// countUpTo(n: 11) == [2, 3, 5, 7]
// countUpTo(n: 0) == [] as [Int]
// countUpTo(n: 20) == [2, 3, 5, 7, 11, 13, 17, 19]
// countUpTo(n: 1) == [] as [Int]
// countUpTo(n: 18) == [2, 3, 5, 7, 11, 13, 17]
func countUpTo(n: Int) -> [Int] {
var result: [Int] = []
for i in 2...n {
if isPrime(n: i) {
result.append(i)
}
}
return result
}
func isPrime(n: Int) -> Bool {
if n == 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```
// XCTAssertTrue failed
func countUpTo(n: Int) -> [Int] {
var result: [Int] = []
for i in 2...n {
if isPrime(n: i) {
result.append(i)
}
}
return result
}
func isPrime(n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```swift
// Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// countUpTo(n: 5) == [2, 3]
// countUpTo(n: 11) == [2, 3, 5, 7]
// countUpTo(n: 0) == [] as [Int]
// countUpTo(n: 20) == [2, 3, 5, 7, 11, 13, 17, 19]
// countUpTo(n: 1) == [] as [Int]
// countUpTo(n: 18) == [2, 3, 5, 7, 11, 13, 17]
func countUpTo(n: Int) -> [Int] {
var result: [Int] = []
for i in 2...n {
if isPrime(n: i) {
result.append(i)
}
}
return result
}
func isPrime(n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```
// XCTAssertTrue failed
func countUpTo(n: Int) -> [Int] {
var primes: [Int] = []
for i in 2...n {
if isPrime(i) {
primes.append(i)
}
}
return primes
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```swift
// Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// countUpTo(n: 5) == [2, 3]
// countUpTo(n: 11) == [2, 3, 5, 7]
// countUpTo(n: 0) == [] as [Int]
// countUpTo(n: 20) == [2, 3, 5, 7, 11, 13, 17, 19]
// countUpTo(n: 1) == [] as [Int]
// countUpTo(n: 18) == [2, 3, 5, 7, 11, 13, 17]
func countUpTo(n: Int) -> [Int] {
var primes: [Int] = []
for i in 2...n {
if isPrime(i) {
primes.append(i)
}
}
return primes
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```
// XCTAssertTrue failed
func countUpTo(n: Int) -> [Int] {
var result: [Int] = []
for i in 1...n {
if isPrime(i) {
result.append(i)
}
}
return result
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```swift
// Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// countUpTo(n: 5) == [2, 3]
// countUpTo(n: 11) == [2, 3, 5, 7]
// countUpTo(n: 0) == [] as [Int]
// countUpTo(n: 20) == [2, 3, 5, 7, 11, 13, 17, 19]
// countUpTo(n: 1) == [] as [Int]
// countUpTo(n: 18) == [2, 3, 5, 7, 11, 13, 17]
func countUpTo(n: Int) -> [Int] {
var result: [Int] = []
for i in 1...n {
if isPrime(i) {
result.append(i)
}
}
return result
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```
// XCTAssertTrue failed
func countUpTo(n: Int) -> [Int] {
var result = [Int]()
for i in 2...n {
if isPrime(i) {
result.append(i)
}
}
return result
}
func isPrime(_ n: Int) -> Bool {
if n == 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```swift
// Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// countUpTo(n: 5) == [2, 3]
// countUpTo(n: 11) == [2, 3, 5, 7]
// countUpTo(n: 0) == [] as [Int]
// countUpTo(n: 20) == [2, 3, 5, 7, 11, 13, 17, 19]
// countUpTo(n: 1) == [] as [Int]
// countUpTo(n: 18) == [2, 3, 5, 7, 11, 13, 17]
func countUpTo(n: Int) -> [Int] {
var result = [Int]()
for i in 2...n {
if isPrime(i) {
result.append(i)
}
}
return result
}
func isPrime(_ n: Int) -> Bool {
if n == 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```
// XCTAssertTrue failed
func countUpTo(n: Int) -> [Int] {
var result: [Int] = []
for i in 2...n {
if isPrime(n: i) {
result.append(i)
}
}
return result
}
func isPrime(n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2...n {
if n % i == 0 {
return false
}
}
return true
}
```swift
// Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// countUpTo(n: 5) == [2, 3]
// countUpTo(n: 11) == [2, 3, 5, 7]
// countUpTo(n: 0) == [] as [Int]
// countUpTo(n: 20) == [2, 3, 5, 7, 11, 13, 17, 19]
// countUpTo(n: 1) == [] as [Int]
// countUpTo(n: 18) == [2, 3, 5, 7, 11, 13, 17]
func countUpTo(n: Int) -> [Int] {
var result: [Int] = []
for i in 2...n {
if isPrime(n: i) {
result.append(i)
}
}
return result
}
func isPrime(n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2...n {
if n % i == 0 {
return false
}
}
return true
}
```
// XCTAssertTrue failed
func countUpTo(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if isPrime(i) {
result.append(i)
}
}
return result
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```swift
// Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// countUpTo(n: 5) == [2, 3]
// countUpTo(n: 11) == [2, 3, 5, 7]
// countUpTo(n: 0) == [] as [Int]
// countUpTo(n: 20) == [2, 3, 5, 7, 11, 13, 17, 19]
// countUpTo(n: 1) == [] as [Int]
// countUpTo(n: 18) == [2, 3, 5, 7, 11, 13, 17]
func countUpTo(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if isPrime(i) {
result.append(i)
}
}
return result
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```
// XCTAssertTrue failed
func countUpTo(n: Int) -> [Int] {
var result = [Int]()
for i in 2...n {
if isPrime(n: i) {
result.append(i)
}
}
return result
}
func isPrime(n: Int) -> Bool {
if n == 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```swift
// Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// countUpTo(n: 5) == [2, 3]
// countUpTo(n: 11) == [2, 3, 5, 7]
// countUpTo(n: 0) == [] as [Int]
// countUpTo(n: 20) == [2, 3, 5, 7, 11, 13, 17, 19]
// countUpTo(n: 1) == [] as [Int]
// countUpTo(n: 18) == [2, 3, 5, 7, 11, 13, 17]
func countUpTo(n: Int) -> [Int] {
var result = [Int]()
for i in 2...n {
if isPrime(n: i) {
result.append(i)
}
}
return result
}
func isPrime(n: Int) -> Bool {
if n == 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```
// XCTAssertTrue failed
func countUpTo(n: Int) -> [Int] {
var result: [Int] = []
for i in 2...n {
if isPrime(n: i) {
result.append(i)
}
}
return result
}
func isPrime(n: Int) -> Bool {
if n == 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```swift
// Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// countUpTo(n: 5) == [2, 3]
// countUpTo(n: 11) == [2, 3, 5, 7]
// countUpTo(n: 0) == [] as [Int]
// countUpTo(n: 20) == [2, 3, 5, 7, 11, 13, 17, 19]
// countUpTo(n: 1) == [] as [Int]
// countUpTo(n: 18) == [2, 3, 5, 7, 11, 13, 17]
func countUpTo(n: Int) -> [Int] {
var result: [Int] = []
for i in 2...n {
if isPrime(n: i) {
result.append(i)
}
}
return result
}
func isPrime(n: Int) -> Bool {
if n == 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```
// XCTAssertTrue failed
func multiply(a: Int, b: Int) -> Int {
return 0
}
```swift
// Complete the function that takes two integers and returns
// the product of their unit digits.
// Assume the input is always valid.
// Examples:
// multiply(a: 148, b: 412) == 16
// multiply(a: 19, b: 28) == 72
// multiply(a: 2020, b: 1851) == 0
// multiply(a: 14, b: -15) == 20
func multiply(a: Int, b: Int) -> Int {
return 0
}
```
// XCTAssertTrue failed
func multiply(a: Int, b: Int) -> Int {
return 0
}
```swift
// Complete the function that takes two integers and returns
// the product of their unit digits.
// Assume the input is always valid.
// Examples:
// multiply(a: 148, b: 412) == 16
// multiply(a: 19, b: 28) == 72
// multiply(a: 2020, b: 1851) == 0
// multiply(a: 14, b: -15) == 20
func multiply(a: Int, b: Int) -> Int {
return 0
}
```
// XCTAssertTrue failed
func multiply(a: Int, b: Int) -> Int {
return 0
}
```swift
// Complete the function that takes two integers and returns
// the product of their unit digits.
// Assume the input is always valid.
// Examples:
// multiply(a: 148, b: 412) == 16
// multiply(a: 19, b: 28) == 72
// multiply(a: 2020, b: 1851) == 0
// multiply(a: 14, b: -15) == 20
func multiply(a: Int, b: Int) -> Int {
return 0
}
```
// XCTAssertTrue failed
func multiply(a: Int, b: Int) -> Int {
return 0
}
```swift
// Complete the function that takes two integers and returns
// the product of their unit digits.
// Assume the input is always valid.
// Examples:
// multiply(a: 148, b: 412) == 16
// multiply(a: 19, b: 28) == 72
// multiply(a: 2020, b: 1851) == 0
// multiply(a: 14, b: -15) == 20
func multiply(a: Int, b: Int) -> Int {
return 0
}
```
// XCTAssertTrue failed
func multiply(a: Int, b: Int) -> Int {
return 0
}
```swift
// Complete the function that takes two integers and returns
// the product of their unit digits.
// Assume the input is always valid.
// Examples:
// multiply(a: 148, b: 412) == 16
// multiply(a: 19, b: 28) == 72
// multiply(a: 2020, b: 1851) == 0
// multiply(a: 14, b: -15) == 20
func multiply(a: Int, b: Int) -> Int {
return 0
}
```
// XCTAssertTrue failed
func multiply(a: Int, b: Int) -> Int {
return 0
}
```swift
// Complete the function that takes two integers and returns
// the product of their unit digits.
// Assume the input is always valid.
// Examples:
// multiply(a: 148, b: 412) == 16
// multiply(a: 19, b: 28) == 72
// multiply(a: 2020, b: 1851) == 0
// multiply(a: 14, b: -15) == 20
func multiply(a: Int, b: Int) -> Int {
return 0
}
```
// XCTAssertTrue failed
func multiply(a: Int, b: Int) -> Int {
return 0
}
```swift
// Complete the function that takes two integers and returns
// the product of their unit digits.
// Assume the input is always valid.
// Examples:
// multiply(a: 148, b: 412) == 16
// multiply(a: 19, b: 28) == 72
// multiply(a: 2020, b: 1851) == 0
// multiply(a: 14, b: -15) == 20
func multiply(a: Int, b: Int) -> Int {
return 0
}
```
// XCTAssertTrue failed
func multiply(a: Int, b: Int) -> Int {
return 0
}
```swift
// Complete the function that takes two integers and returns
// the product of their unit digits.
// Assume the input is always valid.
// Examples:
// multiply(a: 148, b: 412) == 16
// multiply(a: 19, b: 28) == 72
// multiply(a: 2020, b: 1851) == 0
// multiply(a: 14, b: -15) == 20
func multiply(a: Int, b: Int) -> Int {
return 0
}
```
// XCTAssertTrue failed
func multiply(a: Int, b: Int) -> Int {
return 0
}
```swift
// Complete the function that takes two integers and returns
// the product of their unit digits.
// Assume the input is always valid.
// Examples:
// multiply(a: 148, b: 412) == 16
// multiply(a: 19, b: 28) == 72
// multiply(a: 2020, b: 1851) == 0
// multiply(a: 14, b: -15) == 20
func multiply(a: Int, b: Int) -> Int {
return 0
}
```
// XCTAssertTrue failed
func multiply(a: Int, b: Int) -> Int {
return 0
}
```swift
// Complete the function that takes two integers and returns
// the product of their unit digits.
// Assume the input is always valid.
// Examples:
// multiply(a: 148, b: 412) == 16
// multiply(a: 19, b: 28) == 72
// multiply(a: 2020, b: 1851) == 0
// multiply(a: 14, b: -15) == 20
func multiply(a: Int, b: Int) -> Int {
return 0
}
```
// XCTAssertTrue failed
func countUpper(s: String) -> Int {
var count = 0
for (index, char) in s.enumerated() {
if index % 2 == 0 && char.isUppercase {
count += 1
}
}
return count
}
```swift
// Given a string s, count the number of uppercase vowels in even indices.
// For example:
// countUpper(s: "aBCdEf") == 1
// countUpper(s: "abcdefg") == 0
// countUpper(s: "dBBE") == 0
func countUpper(s: String) -> Int {
var count = 0
for (index, char) in s.enumerated() {
if index % 2 == 0 && char.isUppercase {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func countUpper(s: String) -> Int {
var count = 0
for (index, char) in s.enumerated() {
if index % 2 == 0, char.isUppercase {
count += 1
}
}
return count
}
```swift
// Given a string s, count the number of uppercase vowels in even indices.
// For example:
// countUpper(s: "aBCdEf") == 1
// countUpper(s: "abcdefg") == 0
// countUpper(s: "dBBE") == 0
func countUpper(s: String) -> Int {
var count = 0
for (index, char) in s.enumerated() {
if index % 2 == 0, char.isUppercase {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func countUpper(s: String) -> Int {
var count = 0
for (index, char) in s.enumerated() {
if index % 2 == 0, char.isUppercase {
count += 1
}
}
return count
}
```swift
// Given a string s, count the number of uppercase vowels in even indices.
// For example:
// countUpper(s: "aBCdEf") == 1
// countUpper(s: "abcdefg") == 0
// countUpper(s: "dBBE") == 0
func countUpper(s: String) -> Int {
var count = 0
for (index, char) in s.enumerated() {
if index % 2 == 0, char.isUppercase {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func countUpper(s: String) -> Int {
var count = 0
for (i, char) in s.enumerated() {
if i % 2 == 0 && char.isUppercase {
count += 1
}
}
return count
}
```swift
// Given a string s, count the number of uppercase vowels in even indices.
// For example:
// countUpper(s: "aBCdEf") == 1
// countUpper(s: "abcdefg") == 0
// countUpper(s: "dBBE") == 0
func countUpper(s: String) -> Int {
var count = 0
for (i, char) in s.enumerated() {
if i % 2 == 0 && char.isUppercase {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func countUpper(s: String) -> Int {
var count = 0
for (i, c) in s.enumerated() {
if i % 2 == 0, c.isUppercase {
count += 1
}
}
return count
}
```swift
// Given a string s, count the number of uppercase vowels in even indices.
// For example:
// countUpper(s: "aBCdEf") == 1
// countUpper(s: "abcdefg") == 0
// countUpper(s: "dBBE") == 0
func countUpper(s: String) -> Int {
var count = 0
for (i, c) in s.enumerated() {
if i % 2 == 0, c.isUppercase {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func countUpper(s: String) -> Int {
var count = 0
for (index, char) in s.enumerated() {
if index % 2 == 0 && char.isUppercase {
count += 1
}
}
return count
}
```swift
// Given a string s, count the number of uppercase vowels in even indices.
// For example:
// countUpper(s: "aBCdEf") == 1
// countUpper(s: "abcdefg") == 0
// countUpper(s: "dBBE") == 0
func countUpper(s: String) -> Int {
var count = 0
for (index, char) in s.enumerated() {
if index % 2 == 0 && char.isUppercase {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func countUpper(s: String) -> Int {
var count = 0
for (index, char) in s.enumerated() {
if index % 2 == 0, char.isUppercase {
count += 1
}
}
return count
}
```swift
// Given a string s, count the number of uppercase vowels in even indices.
// For example:
// countUpper(s: "aBCdEf") == 1
// countUpper(s: "abcdefg") == 0
// countUpper(s: "dBBE") == 0
func countUpper(s: String) -> Int {
var count = 0
for (index, char) in s.enumerated() {
if index % 2 == 0, char.isUppercase {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func countUpper(s: String) -> Int {
var count = 0
for (index, char) in s.enumerated() {
if index % 2 == 0, char.isUppercase {
count += 1
}
}
return count
}
```swift
// Given a string s, count the number of uppercase vowels in even indices.
// For example:
// countUpper(s: "aBCdEf") == 1
// countUpper(s: "abcdefg") == 0
// countUpper(s: "dBBE") == 0
func countUpper(s: String) -> Int {
var count = 0
for (index, char) in s.enumerated() {
if index % 2 == 0, char.isUppercase {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func countUpper(s: String) -> Int {
var count = 0
for (index, char) in s.enumerated() {
if index % 2 == 0, char.isUppercase {
count += 1
}
}
return count
}
```swift
// Given a string s, count the number of uppercase vowels in even indices.
// For example:
// countUpper(s: "aBCdEf") == 1
// countUpper(s: "abcdefg") == 0
// countUpper(s: "dBBE") == 0
func countUpper(s: String) -> Int {
var count = 0
for (index, char) in s.enumerated() {
if index % 2 == 0, char.isUppercase {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func countUpper(s: String) -> Int {
var count = 0
for (index, char) in s.enumerated() {
if index % 2 == 0, char.isUppercase {
count += 1
}
}
return count
}
```swift
// Given a string s, count the number of uppercase vowels in even indices.
// For example:
// countUpper(s: "aBCdEf") == 1
// countUpper(s: "abcdefg") == 0
// countUpper(s: "dBBE") == 0
func countUpper(s: String) -> Int {
var count = 0
for (index, char) in s.enumerated() {
if index % 2 == 0, char.isUppercase {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func closestInteger(value: String) -> Int {
let doubleValue = Double(value)?? 0.0
let roundedValue = round(doubleValue)
let roundedIntValue = Int(roundedValue)
if roundedValue == doubleValue {
return roundedIntValue
} else {
return roundedIntValue + (roundedValue > doubleValue? 1 : -1)
}
}
```swift
// Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// Note:
// Rounding away from zero means that if the given number is equidistant
// from two integers, the one you should return is the one that is the
// farthest from zero. For example closest_integer("14.5") should
// return 15 and closest_integer("-14.5") should return -15.
// closestInteger(value: "10") == 10
// closestInteger(value: "15.3") == 15
func closestInteger(value: String) -> Int {
let doubleValue = Double(value)?? 0.0
let roundedValue = round(doubleValue)
let roundedIntValue = Int(roundedValue)
if roundedValue == doubleValue {
return roundedIntValue
} else {
return roundedIntValue + (roundedValue > doubleValue? 1 : -1)
}
}
```
let doubleValue = Double(value)?? 0.0 // floating-point literal is unused
let doubleValue = Double(value)?? 0.0 // cannot use optional chaining on non-optional value of type 'Double'
let doubleValue = Double(value)?? 0.0 // consecutive statements on a line must be separated by ';'
return roundedIntValue + (roundedValue > doubleValue? 1 : -1) // value of optional type 'Optional<_>' must be unwrapped to a value of type '_'
return roundedIntValue + (roundedValue > doubleValue? 1 : -1) // expected ',' separator
return roundedIntValue + (roundedValue > doubleValue? 1 : -1) // cannot convert value of type '(Bool, Int)' to expected argument type 'Int'
func closestInteger(value: String) -> Int {
let number = Double(value)?? 0
let rounded = number.rounded()
let roundedInt = Int(rounded)
let roundedDouble = Double(roundedInt)
let diff = abs(number - roundedDouble)
if diff == 0.5 {
return roundedInt
} else if diff < 0.5 {
return roundedInt
} else {
return roundedInt + 1
}
}
```swift
// Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// Note:
// Rounding away from zero means that if the given number is equidistant
// from two integers, the one you should return is the one that is the
// farthest from zero. For example closest_integer("14.5") should
// return 15 and closest_integer("-14.5") should return -15.
// closestInteger(value: "10") == 10
// closestInteger(value: "15.3") == 15
func closestInteger(value: String) -> Int {
let number = Double(value)?? 0
let rounded = number.rounded()
let roundedInt = Int(rounded)
let roundedDouble = Double(roundedInt)
let diff = abs(number - roundedDouble)
if diff == 0.5 {
return roundedInt
} else if diff < 0.5 {
return roundedInt
} else {
return roundedInt + 1
}
}
```
let number = Double(value)?? 0 // integer literal is unused
let number = Double(value)?? 0 // consecutive statements on a line must be separated by ';'
let number = Double(value)?? 0 // cannot use optional chaining on non-optional value of type 'Double'
let diff = abs(number - roundedDouble) // cannot convert value of type 'Duration' to expected argument type 'Int32'
func closestInteger(value: String) -> Int {
let doubleValue = Double(value)
let roundedValue = round(doubleValue!)
return Int(roundedValue)
}
```swift
// Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// Note:
// Rounding away from zero means that if the given number is equidistant
// from two integers, the one you should return is the one that is the
// farthest from zero. For example closest_integer("14.5") should
// return 15 and closest_integer("-14.5") should return -15.
// closestInteger(value: "10") == 10
// closestInteger(value: "15.3") == 15
func closestInteger(value: String) -> Int {
let doubleValue = Double(value)
let roundedValue = round(doubleValue!)
return Int(roundedValue)
}
```
func closestInteger(value: String) -> Int {
let doubleValue = Double(value)?? 0.0
let roundedValue = round(doubleValue)
let roundedIntValue = Int(roundedValue)
if roundedValue - Double(roundedIntValue) < 0.5 {
return roundedIntValue
} else {
return roundedIntValue + 1
}
}
```swift
// Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// Note:
// Rounding away from zero means that if the given number is equidistant
// from two integers, the one you should return is the one that is the
// farthest from zero. For example closest_integer("14.5") should
// return 15 and closest_integer("-14.5") should return -15.
// closestInteger(value: "10") == 10
// closestInteger(value: "15.3") == 15
func closestInteger(value: String) -> Int {
let doubleValue = Double(value)?? 0.0
let roundedValue = round(doubleValue)
let roundedIntValue = Int(roundedValue)
if roundedValue - Double(roundedIntValue) < 0.5 {
return roundedIntValue
} else {
return roundedIntValue + 1
}
}
```
let doubleValue = Double(value)?? 0.0 // consecutive statements on a line must be separated by ';'
let doubleValue = Double(value)?? 0.0 // floating-point literal is unused
let doubleValue = Double(value)?? 0.0 // cannot use optional chaining on non-optional value of type 'Double'
func closestInteger(value: String) -> Int {
let number = Double(value)?? 0
let rounded = Int(round(number))
return rounded
}
```swift
// Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// Note:
// Rounding away from zero means that if the given number is equidistant
// from two integers, the one you should return is the one that is the
// farthest from zero. For example closest_integer("14.5") should
// return 15 and closest_integer("-14.5") should return -15.
// closestInteger(value: "10") == 10
// closestInteger(value: "15.3") == 15
func closestInteger(value: String) -> Int {
let number = Double(value)?? 0
let rounded = Int(round(number))
return rounded
}
```
let number = Double(value)?? 0 // integer literal is unused
let number = Double(value)?? 0 // consecutive statements on a line must be separated by ';'
let number = Double(value)?? 0 // cannot use optional chaining on non-optional value of type 'Double'
func closestInteger(value: String) -> Int {
let doubleValue = Double(value)?? 0
let roundedValue = round(doubleValue)
return Int(roundedValue)
}
```swift
// Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// Note:
// Rounding away from zero means that if the given number is equidistant
// from two integers, the one you should return is the one that is the
// farthest from zero. For example closest_integer("14.5") should
// return 15 and closest_integer("-14.5") should return -15.
// closestInteger(value: "10") == 10
// closestInteger(value: "15.3") == 15
func closestInteger(value: String) -> Int {
let doubleValue = Double(value)?? 0
let roundedValue = round(doubleValue)
return Int(roundedValue)
}
```
let doubleValue = Double(value)?? 0 // cannot use optional chaining on non-optional value of type 'Double'
let doubleValue = Double(value)?? 0 // integer literal is unused
let doubleValue = Double(value)?? 0 // consecutive statements on a line must be separated by ';'
func closestInteger(value: String) -> Int {
let doubleValue = Double(value)?? 0.0
let roundedValue = round(doubleValue)
return Int(roundedValue)
}
```swift
// Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// Note:
// Rounding away from zero means that if the given number is equidistant
// from two integers, the one you should return is the one that is the
// farthest from zero. For example closest_integer("14.5") should
// return 15 and closest_integer("-14.5") should return -15.
// closestInteger(value: "10") == 10
// closestInteger(value: "15.3") == 15
func closestInteger(value: String) -> Int {
let doubleValue = Double(value)?? 0.0
let roundedValue = round(doubleValue)
return Int(roundedValue)
}
```
let doubleValue = Double(value)?? 0.0 // consecutive statements on a line must be separated by ';'
let doubleValue = Double(value)?? 0.0 // floating-point literal is unused
let doubleValue = Double(value)?? 0.0 // cannot use optional chaining on non-optional value of type 'Double'
func closestInteger(value: String) -> Int {
let number = Double(value)?? 0
let rounded = number.rounded(.awayFromZero)
return Int(rounded)
}
```swift
// Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// Note:
// Rounding away from zero means that if the given number is equidistant
// from two integers, the one you should return is the one that is the
// farthest from zero. For example closest_integer("14.5") should
// return 15 and closest_integer("-14.5") should return -15.
// closestInteger(value: "10") == 10
// closestInteger(value: "15.3") == 15
func closestInteger(value: String) -> Int {
let number = Double(value)?? 0
let rounded = number.rounded(.awayFromZero)
return Int(rounded)
}
```
let number = Double(value)?? 0 // integer literal is unused
let number = Double(value)?? 0 // consecutive statements on a line must be separated by ';'
let number = Double(value)?? 0 // cannot use optional chaining on non-optional value of type 'Double'
let rounded = number.rounded(.awayFromZero) // cannot infer contextual base in reference to member 'awayFromZero'
func closestInteger(value: String) -> Int {
let doubleValue = Double(value)
let roundedValue = round(doubleValue!)
return Int(roundedValue)
}
```swift
// Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// Note:
// Rounding away from zero means that if the given number is equidistant
// from two integers, the one you should return is the one that is the
// farthest from zero. For example closest_integer("14.5") should
// return 15 and closest_integer("-14.5") should return -15.
// closestInteger(value: "10") == 10
// closestInteger(value: "15.3") == 15
func closestInteger(value: String) -> Int {
let doubleValue = Double(value)
let roundedValue = round(doubleValue!)
return Int(roundedValue)
}
```
func closestInteger(value: String) -> Int {
let doubleValue = Double(value)?? 0
let roundedValue = round(doubleValue)
let roundedIntValue = Int(roundedValue)
if abs(doubleValue - Double(roundedIntValue)) < abs(doubleValue - Double(roundedIntValue + 1)) {
return roundedIntValue
} else {
return roundedIntValue + 1
}
}
```swift
// Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// Note:
// Rounding away from zero means that if the given number is equidistant
// from two integers, the one you should return is the one that is the
// farthest from zero. For example closest_integer("14.5") should
// return 15 and closest_integer("-14.5") should return -15.
// closestInteger(value: "10") == 10
// closestInteger(value: "15.3") == 15
func closestInteger(value: String) -> Int {
let doubleValue = Double(value)?? 0
let roundedValue = round(doubleValue)
let roundedIntValue = Int(roundedValue)
if abs(doubleValue - Double(roundedIntValue)) < abs(doubleValue - Double(roundedIntValue + 1)) {
return roundedIntValue
} else {
return roundedIntValue + 1
}
}
```
let doubleValue = Double(value)?? 0 // cannot use optional chaining on non-optional value of type 'Double'
let doubleValue = Double(value)?? 0 // integer literal is unused
let doubleValue = Double(value)?? 0 // consecutive statements on a line must be separated by ';'
func makeAPile(n: Int) -> [Int] {
var pile = [Int]()
var level = 1
var stones = n
while stones > 0 {
pile.append(stones)
if level % 2 == 0 {
stones -= 2
} else {
stones -= 1
}
level += 1
}
return pile
}
```swift
// Given a positive integer n, you have to make a pile of n levels of stones.
// The first level has n stones.
// The number of stones in the next level is:
// - the next odd number if n is odd.
// - the next even number if n is even.
// Return the number of stones in each level in an array, where element at index
// i represents the number of stones in the level (i+1).
// Examples:
// makeAPile(n: 3) == [3, 5, 7]
func makeAPile(n: Int) -> [Int] {
var pile = [Int]()
var level = 1
var stones = n
while stones > 0 {
pile.append(stones)
if level % 2 == 0 {
stones -= 2
} else {
stones -= 1
}
level += 1
}
return pile
}
```
// XCTAssertTrue failed
func makeAPile(n: Int) -> [Int] {
var pile = [Int]()
var stones = n
for _ in 1...n {
pile.append(stones)
stones = stones % 2 == 0? stones + 2 : stones + 1
}
return pile
}
```swift
// Given a positive integer n, you have to make a pile of n levels of stones.
// The first level has n stones.
// The number of stones in the next level is:
// - the next odd number if n is odd.
// - the next even number if n is even.
// Return the number of stones in each level in an array, where element at index
// i represents the number of stones in the level (i+1).
// Examples:
// makeAPile(n: 3) == [3, 5, 7]
func makeAPile(n: Int) -> [Int] {
var pile = [Int]()
var stones = n
for _ in 1...n {
pile.append(stones)
stones = stones % 2 == 0? stones + 2 : stones + 1
}
return pile
}
```
stones = stones % 2 == 0? stones + 2 : stones + 1 // consecutive statements on a line must be separated by ';'
stones = stones % 2 == 0? stones + 2 : stones + 1 // expected expression
stones = stones % 2 == 0? stones + 2 : stones + 1 // cannot assign value of type 'Bool' to type 'Int'
stones = stones % 2 == 0? stones + 2 : stones + 1 // result of operator '+' is unused
stones = stones % 2 == 0? stones + 2 : stones + 1 // cannot use optional chaining on non-optional value of type 'Int'
stones = stones % 2 == 0? stones + 2 : stones + 1 // consecutive statements on a line must be separated by ';'
func makeAPile(n: Int) -> [Int] {
var pile = [Int]()
var stones = n
for _ in 1...n {
pile.append(stones)
stones = stones % 2 == 0? stones + 2 : stones + 1
}
return pile
}
```swift
// Given a positive integer n, you have to make a pile of n levels of stones.
// The first level has n stones.
// The number of stones in the next level is:
// - the next odd number if n is odd.
// - the next even number if n is even.
// Return the number of stones in each level in an array, where element at index
// i represents the number of stones in the level (i+1).
// Examples:
// makeAPile(n: 3) == [3, 5, 7]
func makeAPile(n: Int) -> [Int] {
var pile = [Int]()
var stones = n
for _ in 1...n {
pile.append(stones)
stones = stones % 2 == 0? stones + 2 : stones + 1
}
return pile
}
```
stones = stones % 2 == 0? stones + 2 : stones + 1 // consecutive statements on a line must be separated by ';'
stones = stones % 2 == 0? stones + 2 : stones + 1 // expected expression
stones = stones % 2 == 0? stones + 2 : stones + 1 // cannot assign value of type 'Bool' to type 'Int'
stones = stones % 2 == 0? stones + 2 : stones + 1 // result of operator '+' is unused
stones = stones % 2 == 0? stones + 2 : stones + 1 // cannot use optional chaining on non-optional value of type 'Int'
stones = stones % 2 == 0? stones + 2 : stones + 1 // consecutive statements on a line must be separated by ';'
func makeAPile(n: Int) -> [Int] {
var pile = [Int]()
var stones = n
for _ in 1...n {
pile.append(stones)
stones += stones % 2
}
return pile
}
```swift
// Given a positive integer n, you have to make a pile of n levels of stones.
// The first level has n stones.
// The number of stones in the next level is:
// - the next odd number if n is odd.
// - the next even number if n is even.
// Return the number of stones in each level in an array, where element at index
// i represents the number of stones in the level (i+1).
// Examples:
// makeAPile(n: 3) == [3, 5, 7]
func makeAPile(n: Int) -> [Int] {
var pile = [Int]()
var stones = n
for _ in 1...n {
pile.append(stones)
stones += stones % 2
}
return pile
}
```
// XCTAssertTrue failed
func makeAPile(n: Int) -> [Int] {
var pile = [Int]()
var stones = n
for _ in 1...n {
pile.append(stones)
if stones % 2 == 0 {
stones += 1
} else {
stones += 2
}
}
return pile
}
```swift
// Given a positive integer n, you have to make a pile of n levels of stones.
// The first level has n stones.
// The number of stones in the next level is:
// - the next odd number if n is odd.
// - the next even number if n is even.
// Return the number of stones in each level in an array, where element at index
// i represents the number of stones in the level (i+1).
// Examples:
// makeAPile(n: 3) == [3, 5, 7]
func makeAPile(n: Int) -> [Int] {
var pile = [Int]()
var stones = n
for _ in 1...n {
pile.append(stones)
if stones % 2 == 0 {
stones += 1
} else {
stones += 2
}
}
return pile
}
```
// XCTAssertTrue failed
func makeAPile(n: Int) -> [Int] {
var pile = [Int]()
var level = n
for _ in 1...n {
pile.append(level)
level = level % 2 == 0? level + 2 : level + 1
}
return pile
}
```swift
// Given a positive integer n, you have to make a pile of n levels of stones.
// The first level has n stones.
// The number of stones in the next level is:
// - the next odd number if n is odd.
// - the next even number if n is even.
// Return the number of stones in each level in an array, where element at index
// i represents the number of stones in the level (i+1).
// Examples:
// makeAPile(n: 3) == [3, 5, 7]
func makeAPile(n: Int) -> [Int] {
var pile = [Int]()
var level = n
for _ in 1...n {
pile.append(level)
level = level % 2 == 0? level + 2 : level + 1
}
return pile
}
```
level = level % 2 == 0? level + 2 : level + 1 // expected expression
level = level % 2 == 0? level + 2 : level + 1 // result of operator '+' is unused
level = level % 2 == 0? level + 2 : level + 1 // cannot use optional chaining on non-optional value of type 'Int'
level = level % 2 == 0? level + 2 : level + 1 // cannot assign value of type 'Bool' to type 'Int'
level = level % 2 == 0? level + 2 : level + 1 // consecutive statements on a line must be separated by ';'
level = level % 2 == 0? level + 2 : level + 1 // consecutive statements on a line must be separated by ';'
func makeAPile(n: Int) -> [Int] {
var pile = [Int]()
for i in 1...n {
if i % 2 == 0 {
pile.append(i + 1)
} else {
pile.append(i * 2)
}
}
return pile
}
```swift
// Given a positive integer n, you have to make a pile of n levels of stones.
// The first level has n stones.
// The number of stones in the next level is:
// - the next odd number if n is odd.
// - the next even number if n is even.
// Return the number of stones in each level in an array, where element at index
// i represents the number of stones in the level (i+1).
// Examples:
// makeAPile(n: 3) == [3, 5, 7]
func makeAPile(n: Int) -> [Int] {
var pile = [Int]()
for i in 1...n {
if i % 2 == 0 {
pile.append(i + 1)
} else {
pile.append(i * 2)
}
}
return pile
}
```
// XCTAssertTrue failed
func makeAPile(n: Int) -> [Int] {
var pile = [Int]()
var stones = n
for _ in 0..<n {
pile.append(stones)
stones += 1
if stones % 2 == 0 {
stones += 1
}
}
return pile
}
```swift
// Given a positive integer n, you have to make a pile of n levels of stones.
// The first level has n stones.
// The number of stones in the next level is:
// - the next odd number if n is odd.
// - the next even number if n is even.
// Return the number of stones in each level in an array, where element at index
// i represents the number of stones in the level (i+1).
// Examples:
// makeAPile(n: 3) == [3, 5, 7]
func makeAPile(n: Int) -> [Int] {
var pile = [Int]()
var stones = n
for _ in 0..<n {
pile.append(stones)
stones += 1
if stones % 2 == 0 {
stones += 1
}
}
return pile
}
```
// XCTAssertTrue failed
func makeAPile(n: Int) -> [Int] {
var pile = [Int]()
for i in 1...n {
if i % 2 == 0 {
pile.append(i + 1)
} else {
pile.append(i * 2 + 1)
}
}
return pile
}
```swift
// Given a positive integer n, you have to make a pile of n levels of stones.
// The first level has n stones.
// The number of stones in the next level is:
// - the next odd number if n is odd.
// - the next even number if n is even.
// Return the number of stones in each level in an array, where element at index
// i represents the number of stones in the level (i+1).
// Examples:
// makeAPile(n: 3) == [3, 5, 7]
func makeAPile(n: Int) -> [Int] {
var pile = [Int]()
for i in 1...n {
if i % 2 == 0 {
pile.append(i + 1)
} else {
pile.append(i * 2 + 1)
}
}
return pile
}
```
// XCTAssertTrue failed
func makeAPile(n: Int) -> [Int] {
var pile = [Int]()
var level = 1
var stones = n
while stones > 0 {
pile.append(stones)
if level % 2 == 0 {
stones -= 2
} else {
stones -= 1
}
level += 1
}
return pile
}
```swift
// Given a positive integer n, you have to make a pile of n levels of stones.
// The first level has n stones.
// The number of stones in the next level is:
// - the next odd number if n is odd.
// - the next even number if n is even.
// Return the number of stones in each level in an array, where element at index
// i represents the number of stones in the level (i+1).
// Examples:
// makeAPile(n: 3) == [3, 5, 7]
func makeAPile(n: Int) -> [Int] {
var pile = [Int]()
var level = 1
var stones = n
while stones > 0 {
pile.append(stones)
if level % 2 == 0 {
stones -= 2
} else {
stones -= 1
}
level += 1
}
return pile
}
```
// XCTAssertTrue failed
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ", ")
}
```swift
// You will be given a string of words separated by commas or spaces. Your task is
// to split the string into words and return an array of the words.
// For example:
// wordsString(s: "Hi, my name is John") == ["Hi", "my", "name", "is", "John"]
// wordsString(s: "One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ", ")
}
```
// XCTAssertTrue failed
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ",")
}
```swift
// You will be given a string of words separated by commas or spaces. Your task is
// to split the string into words and return an array of the words.
// For example:
// wordsString(s: "Hi, my name is John") == ["Hi", "my", "name", "is", "John"]
// wordsString(s: "One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ",")
}
```
// XCTAssertTrue failed
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ", ")
}
```swift
// You will be given a string of words separated by commas or spaces. Your task is
// to split the string into words and return an array of the words.
// For example:
// wordsString(s: "Hi, my name is John") == ["Hi", "my", "name", "is", "John"]
// wordsString(s: "One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ", ")
}
```
// XCTAssertTrue failed
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ", ")
}
```swift
// You will be given a string of words separated by commas or spaces. Your task is
// to split the string into words and return an array of the words.
// For example:
// wordsString(s: "Hi, my name is John") == ["Hi", "my", "name", "is", "John"]
// wordsString(s: "One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ", ")
}
```
// XCTAssertTrue failed
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ",")
}
```swift
// You will be given a string of words separated by commas or spaces. Your task is
// to split the string into words and return an array of the words.
// For example:
// wordsString(s: "Hi, my name is John") == ["Hi", "my", "name", "is", "John"]
// wordsString(s: "One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ",")
}
```
// XCTAssertTrue failed
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ", ")
}
```swift
// You will be given a string of words separated by commas or spaces. Your task is
// to split the string into words and return an array of the words.
// For example:
// wordsString(s: "Hi, my name is John") == ["Hi", "my", "name", "is", "John"]
// wordsString(s: "One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ", ")
}
```
// XCTAssertTrue failed
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ",")
}
```swift
// You will be given a string of words separated by commas or spaces. Your task is
// to split the string into words and return an array of the words.
// For example:
// wordsString(s: "Hi, my name is John") == ["Hi", "my", "name", "is", "John"]
// wordsString(s: "One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ",")
}
```
// XCTAssertTrue failed
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ", ")
}
```swift
// You will be given a string of words separated by commas or spaces. Your task is
// to split the string into words and return an array of the words.
// For example:
// wordsString(s: "Hi, my name is John") == ["Hi", "my", "name", "is", "John"]
// wordsString(s: "One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ", ")
}
```
// XCTAssertTrue failed
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ", ")
}
```swift
// You will be given a string of words separated by commas or spaces. Your task is
// to split the string into words and return an array of the words.
// For example:
// wordsString(s: "Hi, my name is John") == ["Hi", "my", "name", "is", "John"]
// wordsString(s: "One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ", ")
}
```
// XCTAssertTrue failed
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ", ")
}
```swift
// You will be given a string of words separated by commas or spaces. Your task is
// to split the string into words and return an array of the words.
// For example:
// wordsString(s: "Hi, my name is John") == ["Hi", "my", "name", "is", "John"]
// wordsString(s: "One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ", ")
}
```
// XCTAssertTrue failed
func chooseNum(x: Int, y: Int) -> Int {
// Your code here
}
```swift
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// chooseNum(x: 12, y: 15) == 14
// chooseNum(x: 13, y: 12) == -1
func chooseNum(x: Int, y: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func chooseNum(x: Int, y: Int) -> Int {
// Your code here
}
```swift
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// chooseNum(x: 12, y: 15) == 14
// chooseNum(x: 13, y: 12) == -1
func chooseNum(x: Int, y: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func chooseNum(x: Int, y: Int) -> Int {
// Your code here
}
```swift
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// chooseNum(x: 12, y: 15) == 14
// chooseNum(x: 13, y: 12) == -1
func chooseNum(x: Int, y: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func chooseNum(x: Int, y: Int) -> Int {
// your code here
}
```swift
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// chooseNum(x: 12, y: 15) == 14
// chooseNum(x: 13, y: 12) == -1
func chooseNum(x: Int, y: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func chooseNum(x: Int, y: Int) -> Int {
// Your code here
}
```swift
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// chooseNum(x: 12, y: 15) == 14
// chooseNum(x: 13, y: 12) == -1
func chooseNum(x: Int, y: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func chooseNum(x: Int, y: Int) -> Int {
// your code here
}
```swift
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// chooseNum(x: 12, y: 15) == 14
// chooseNum(x: 13, y: 12) == -1
func chooseNum(x: Int, y: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func chooseNum(x: Int, y: Int) -> Int {
// Your code here
}
```swift
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// chooseNum(x: 12, y: 15) == 14
// chooseNum(x: 13, y: 12) == -1
func chooseNum(x: Int, y: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func chooseNum(x: Int, y: Int) -> Int {
// Your code here
}
```swift
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// chooseNum(x: 12, y: 15) == 14
// chooseNum(x: 13, y: 12) == -1
func chooseNum(x: Int, y: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func chooseNum(x: Int, y: Int) -> Int {
// your code here
}
```swift
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// chooseNum(x: 12, y: 15) == 14
// chooseNum(x: 13, y: 12) == -1
func chooseNum(x: Int, y: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func chooseNum(x: Int, y: Int) -> Int {
// your code here
}
```swift
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// chooseNum(x: 12, y: 15) == 14
// chooseNum(x: 13, y: 12) == -1
func chooseNum(x: Int, y: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
extension Int: Error {
}
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
if n > m {
return.failure(n)
}
let sum = (n + m) * (m - n + 1) / 2
let binary = String(sum, radix: 2)
return.success(binary)
}
```swift
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
if n > m {
return.failure(n)
}
let sum = (n + m) * (m - n + 1) / 2
let binary = String(sum, radix: 2)
return.success(binary)
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n + m) * (m - n + 1) / 2
let result = String(sum, radix: 2)
return.success(result)
}
```swift
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n + m) * (m - n + 1) / 2
let result = String(sum, radix: 2)
return.success(result)
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n...m).reduce(0, +)
let avg = sum / (m - n + 1)
return.success(String(avg, radix: 2))
}
```swift
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n...m).reduce(0, +)
let avg = sum / (m - n + 1)
return.success(String(avg, radix: 2))
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n + m) * (m - n + 1) / 2
let binary = String(sum, radix: 2)
return.success(binary)
}
```swift
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n + m) * (m - n + 1) / 2
let binary = String(sum, radix: 2)
return.success(binary)
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n + m) * (m - n + 1) / 2
let binary = String(sum, radix: 2)
return.success(binary)
}
```swift
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n + m) * (m - n + 1) / 2
let binary = String(sum, radix: 2)
return.success(binary)
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n...m).reduce(0, +)
let avg = sum / (m - n + 1)
return.success(String(avg, radix: 2))
}
```swift
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n...m).reduce(0, +)
let avg = sum / (m - n + 1)
return.success(String(avg, radix: 2))
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n...m).reduce(0, +)
let avg = sum / (m - n + 1)
return.success(String(avg, radix: 2))
}
```swift
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n...m).reduce(0, +)
let avg = sum / (m - n + 1)
return.success(String(avg, radix: 2))
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n...m).reduce(0, +)
let avg = sum / (m - n + 1)
let binary = String(avg, radix: 2)
return.success(binary)
}
```swift
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n...m).reduce(0, +)
let avg = sum / (m - n + 1)
let binary = String(avg, radix: 2)
return.success(binary)
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n...m).reduce(0, +)
let avg = sum / (m - n + 1)
return.success(String(avg, radix: 2))
}
```swift
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n...m).reduce(0, +)
let avg = sum / (m - n + 1)
return.success(String(avg, radix: 2))
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n + m) * (m - n + 1) / 2
let binary = String(sum, radix: 2)
return.success(binary)
}
```swift
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n + m) * (m - n + 1) / 2
let binary = String(sum, radix: 2)
return.success(binary)
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
func uniqueDigits(x: [Int]) -> [Int] {
// your code here
}
```swift
// Given an array of positive integers x. return a sorted array of all
// elements that hasn't any even digit.
// Note: Returned array should be sorted in increasing order.
// For example:
// uniqueDigits(x: [15, 33, 1422, 1]) == [1, 15, 33]
// uniqueDigits(x: [152, 323, 1422, 10]) == [] as [Int]
func uniqueDigits(x: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func uniqueDigits(x: [Int]) -> [Int] {
// Write your code here
}
```swift
// Given an array of positive integers x. return a sorted array of all
// elements that hasn't any even digit.
// Note: Returned array should be sorted in increasing order.
// For example:
// uniqueDigits(x: [15, 33, 1422, 1]) == [1, 15, 33]
// uniqueDigits(x: [152, 323, 1422, 10]) == [] as [Int]
func uniqueDigits(x: [Int]) -> [Int] {
// Write your code here
}
```
} // missing return in global function expected to return '[Int]'
func uniqueDigits(x: [Int]) -> [Int] {
// your code here
}
```swift
// Given an array of positive integers x. return a sorted array of all
// elements that hasn't any even digit.
// Note: Returned array should be sorted in increasing order.
// For example:
// uniqueDigits(x: [15, 33, 1422, 1]) == [1, 15, 33]
// uniqueDigits(x: [152, 323, 1422, 10]) == [] as [Int]
func uniqueDigits(x: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func uniqueDigits(x: [Int]) -> [Int] {
var result = [Int]()
for num in x {
var num = num
var isUnique = true
while num > 0 {
let digit = num % 10
if digit % 2 == 0 {
isUnique = false
break
}
num /= 10
}
if isUnique {
result.append(x[i])
}
}
return result
}
```swift
// Given an array of positive integers x. return a sorted array of all
// elements that hasn't any even digit.
// Note: Returned array should be sorted in increasing order.
// For example:
// uniqueDigits(x: [15, 33, 1422, 1]) == [1, 15, 33]
// uniqueDigits(x: [152, 323, 1422, 10]) == [] as [Int]
func uniqueDigits(x: [Int]) -> [Int] {
var result = [Int]()
for num in x {
var num = num
var isUnique = true
while num > 0 {
let digit = num % 10
if digit % 2 == 0 {
isUnique = false
break
}
num /= 10
}
if isUnique {
result.append(x[i])
}
}
return result
}
```
result.append(x[i]) // cannot find 'i' in scope
func uniqueDigits(x: [Int]) -> [Int] {
// Your code here
}
```swift
// Given an array of positive integers x. return a sorted array of all
// elements that hasn't any even digit.
// Note: Returned array should be sorted in increasing order.
// For example:
// uniqueDigits(x: [15, 33, 1422, 1]) == [1, 15, 33]
// uniqueDigits(x: [152, 323, 1422, 10]) == [] as [Int]
func uniqueDigits(x: [Int]) -> [Int] {
// Your code here
}
```
} // missing return in global function expected to return '[Int]'
func uniqueDigits(x: [Int]) -> [Int] {
var result = [Int]()
for i in x {
var num = i
var isUnique = true
while num > 0 {
if num % 10 % 2 == 0 {
isUnique = false
break
}
num /= 10
}
if isUnique {
result.append(i)
}
}
return result
}
```swift
// Given an array of positive integers x. return a sorted array of all
// elements that hasn't any even digit.
// Note: Returned array should be sorted in increasing order.
// For example:
// uniqueDigits(x: [15, 33, 1422, 1]) == [1, 15, 33]
// uniqueDigits(x: [152, 323, 1422, 10]) == [] as [Int]
func uniqueDigits(x: [Int]) -> [Int] {
var result = [Int]()
for i in x {
var num = i
var isUnique = true
while num > 0 {
if num % 10 % 2 == 0 {
isUnique = false
break
}
num /= 10
}
if isUnique {
result.append(i)
}
}
return result
}
```
// XCTAssertTrue failed
func uniqueDigits(x: [Int]) -> [Int] {
// your code here
}
```swift
// Given an array of positive integers x. return a sorted array of all
// elements that hasn't any even digit.
// Note: Returned array should be sorted in increasing order.
// For example:
// uniqueDigits(x: [15, 33, 1422, 1]) == [1, 15, 33]
// uniqueDigits(x: [152, 323, 1422, 10]) == [] as [Int]
func uniqueDigits(x: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func uniqueDigits(x: [Int]) -> [Int] {
var result = [Int]()
for i in x {
var temp = i
var count = 0
while temp > 0 {
if temp % 10 % 2 == 0 {
count += 1
}
temp /= 10
}
if count == 0 {
result.append(i)
}
}
return result
}
```swift
// Given an array of positive integers x. return a sorted array of all
// elements that hasn't any even digit.
// Note: Returned array should be sorted in increasing order.
// For example:
// uniqueDigits(x: [15, 33, 1422, 1]) == [1, 15, 33]
// uniqueDigits(x: [152, 323, 1422, 10]) == [] as [Int]
func uniqueDigits(x: [Int]) -> [Int] {
var result = [Int]()
for i in x {
var temp = i
var count = 0
while temp > 0 {
if temp % 10 % 2 == 0 {
count += 1
}
temp /= 10
}
if count == 0 {
result.append(i)
}
}
return result
}
```
// XCTAssertTrue failed
func uniqueDigits(x: [Int]) -> [Int] {
// your code here
}
```swift
// Given an array of positive integers x. return a sorted array of all
// elements that hasn't any even digit.
// Note: Returned array should be sorted in increasing order.
// For example:
// uniqueDigits(x: [15, 33, 1422, 1]) == [1, 15, 33]
// uniqueDigits(x: [152, 323, 1422, 10]) == [] as [Int]
func uniqueDigits(x: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func uniqueDigits(x: [Int]) -> [Int] {
var result: [Int] = []
for i in x {
var temp = i
var isUnique = true
while temp > 0 {
if temp % 10 % 2 == 0 {
isUnique = false
break
}
temp /= 10
}
if isUnique {
result.append(i)
}
}
return result
}
```swift
// Given an array of positive integers x. return a sorted array of all
// elements that hasn't any even digit.
// Note: Returned array should be sorted in increasing order.
// For example:
// uniqueDigits(x: [15, 33, 1422, 1]) == [1, 15, 33]
// uniqueDigits(x: [152, 323, 1422, 10]) == [] as [Int]
func uniqueDigits(x: [Int]) -> [Int] {
var result: [Int] = []
for i in x {
var temp = i
var isUnique = true
while temp > 0 {
if temp % 10 % 2 == 0 {
isUnique = false
break
}
temp /= 10
}
if isUnique {
result.append(i)
}
}
return result
}
```
// XCTAssertTrue failed
func byLength(arr: [Int]) -> [String] {
// your code here
}
```swift
// Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// If the array is empty, return an empty array:
// If the array has any strange number ignore it:
// byLength(arr: [2, 1, 1, 4, 5, 8, 2, 3]) == ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// byLength(arr: [] as [Int]) == [] as [String]
// byLength(arr: [1, -1, 55]) == ["One"]
func byLength(arr: [Int]) -> [String] {
// your code here
}
```
} // missing return in global function expected to return '[String]'
func byLength(arr: [Int]) -> [String] {
// Your code here
}
```swift
// Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// If the array is empty, return an empty array:
// If the array has any strange number ignore it:
// byLength(arr: [2, 1, 1, 4, 5, 8, 2, 3]) == ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// byLength(arr: [] as [Int]) == [] as [String]
// byLength(arr: [1, -1, 55]) == ["One"]
func byLength(arr: [Int]) -> [String] {
// Your code here
}
```
} // missing return in global function expected to return '[String]'
func byLength(arr: [Int]) -> [String] {
var result = [String]()
for i in arr {
if i > 0 && i <= 9 {
result.append(String(i))
}
}
result.sort(by: >)
result.reverse()
for i in 0..<result.count {
switch result[i] {
case "1":
result[i] = "One"
case "2":
result[i] = "Two"
case "3":
result[i] = "Three"
case "4":
result[i] = "Four"
case "5":
result[i] = "Five"
case "6":
result[i] = "Six"
case "7":
result[i] = "Seven"
case "8":
result[i] = "Eight"
case "9":
result[i] = "Nine"
default:
break
}
}
return result
}
```swift
// Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// If the array is empty, return an empty array:
// If the array has any strange number ignore it:
// byLength(arr: [2, 1, 1, 4, 5, 8, 2, 3]) == ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// byLength(arr: [] as [Int]) == [] as [String]
// byLength(arr: [1, -1, 55]) == ["One"]
func byLength(arr: [Int]) -> [String] {
var result = [String]()
for i in arr {
if i > 0 && i <= 9 {
result.append(String(i))
}
}
result.sort(by: >)
result.reverse()
for i in 0..<result.count {
switch result[i] {
case "1":
result[i] = "One"
case "2":
result[i] = "Two"
case "3":
result[i] = "Three"
case "4":
result[i] = "Four"
case "5":
result[i] = "Five"
case "6":
result[i] = "Six"
case "7":
result[i] = "Seven"
case "8":
result[i] = "Eight"
case "9":
result[i] = "Nine"
default:
break
}
}
return result
}
```
// XCTAssertTrue failed
func byLength(arr: [Int]) -> [String] {
var result: [String] = []
for i in arr {
if i >= 1 && i <= 9 {
result.append(String(i))
}
}
result.reverse()
for i in 0..<result.count {
switch result[i] {
case "1":
result[i] = "One"
case "2":
result[i] = "Two"
case "3":
result[i] = "Three"
case "4":
result[i] = "Four"
case "5":
result[i] = "Five"
case "6":
result[i] = "Six"
case "7":
result[i] = "Seven"
case "8":
result[i] = "Eight"
case "9":
result[i] = "Nine"
default:
break
}
}
return result
}
```swift
// Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// If the array is empty, return an empty array:
// If the array has any strange number ignore it:
// byLength(arr: [2, 1, 1, 4, 5, 8, 2, 3]) == ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// byLength(arr: [] as [Int]) == [] as [String]
// byLength(arr: [1, -1, 55]) == ["One"]
func byLength(arr: [Int]) -> [String] {
var result: [String] = []
for i in arr {
if i >= 1 && i <= 9 {
result.append(String(i))
}
}
result.reverse()
for i in 0..<result.count {
switch result[i] {
case "1":
result[i] = "One"
case "2":
result[i] = "Two"
case "3":
result[i] = "Three"
case "4":
result[i] = "Four"
case "5":
result[i] = "Five"
case "6":
result[i] = "Six"
case "7":
result[i] = "Seven"
case "8":
result[i] = "Eight"
case "9":
result[i] = "Nine"
default:
break
}
}
return result
}
```
// XCTAssertTrue failed
func byLength(arr: [Int]) -> [String] {
// Your code here
}
```swift
// Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// If the array is empty, return an empty array:
// If the array has any strange number ignore it:
// byLength(arr: [2, 1, 1, 4, 5, 8, 2, 3]) == ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// byLength(arr: [] as [Int]) == [] as [String]
// byLength(arr: [1, -1, 55]) == ["One"]
func byLength(arr: [Int]) -> [String] {
// Your code here
}
```
} // missing return in global function expected to return '[String]'
func byLength(arr: [Int]) -> [String] {
return []
}
```swift
// Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// If the array is empty, return an empty array:
// If the array has any strange number ignore it:
// byLength(arr: [2, 1, 1, 4, 5, 8, 2, 3]) == ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// byLength(arr: [] as [Int]) == [] as [String]
// byLength(arr: [1, -1, 55]) == ["One"]
func byLength(arr: [Int]) -> [String] {
return []
}
```
// XCTAssertTrue failed
func byLength(arr: [Int]) -> [String] {
let names = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"]
var result = [String]()
for i in arr {
if i > 0 && i <= 9 {
result.append(names[i - 1])
}
}
return result.reversed()
}
```swift
// Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// If the array is empty, return an empty array:
// If the array has any strange number ignore it:
// byLength(arr: [2, 1, 1, 4, 5, 8, 2, 3]) == ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// byLength(arr: [] as [Int]) == [] as [String]
// byLength(arr: [1, -1, 55]) == ["One"]
func byLength(arr: [Int]) -> [String] {
let names = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"]
var result = [String]()
for i in arr {
if i > 0 && i <= 9 {
result.append(names[i - 1])
}
}
return result.reversed()
}
```
// XCTAssertTrue failed
func byLength(arr: [Int]) -> [String] {
var result = [String]()
for i in arr {
if i >= 1 && i <= 9 {
result.append(String(i))
}
}
result.sort()
result.reverse()
for i in 0..<result.count {
switch result[i] {
case "1":
result[i] = "One"
case "2":
result[i] = "Two"
case "3":
result[i] = "Three"
case "4":
result[i] = "Four"
case "5":
result[i] = "Five"
case "6":
result[i] = "Six"
case "7":
result[i] = "Seven"
case "8":
result[i] = "Eight"
case "9":
result[i] = "Nine"
default:
break
}
}
return result
}
```swift
// Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// If the array is empty, return an empty array:
// If the array has any strange number ignore it:
// byLength(arr: [2, 1, 1, 4, 5, 8, 2, 3]) == ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// byLength(arr: [] as [Int]) == [] as [String]
// byLength(arr: [1, -1, 55]) == ["One"]
func byLength(arr: [Int]) -> [String] {
var result = [String]()
for i in arr {
if i >= 1 && i <= 9 {
result.append(String(i))
}
}
result.sort()
result.reverse()
for i in 0..<result.count {
switch result[i] {
case "1":
result[i] = "One"
case "2":
result[i] = "Two"
case "3":
result[i] = "Three"
case "4":
result[i] = "Four"
case "5":
result[i] = "Five"
case "6":
result[i] = "Six"
case "7":
result[i] = "Seven"
case "8":
result[i] = "Eight"
case "9":
result[i] = "Nine"
default:
break
}
}
return result
}
```
func byLength(arr: [Int]) -> [String] {
return []
}
```swift
// Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// If the array is empty, return an empty array:
// If the array has any strange number ignore it:
// byLength(arr: [2, 1, 1, 4, 5, 8, 2, 3]) == ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// byLength(arr: [] as [Int]) == [] as [String]
// byLength(arr: [1, -1, 55]) == ["One"]
func byLength(arr: [Int]) -> [String] {
return []
}
```
// XCTAssertTrue failed
func byLength(arr: [Int]) -> [String] {
return []
}
```swift
// Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// If the array is empty, return an empty array:
// If the array has any strange number ignore it:
// byLength(arr: [2, 1, 1, 4, 5, 8, 2, 3]) == ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// byLength(arr: [] as [Int]) == [] as [String]
// byLength(arr: [1, -1, 55]) == ["One"]
func byLength(arr: [Int]) -> [String] {
return []
}
```
// XCTAssertTrue failed
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(1...i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
return (1...n).reduce(1, *)
}
func sum(_ range: Range<Int>) -> Int {
return range.reduce(0, +)
}
```swift
// Implement the function f that takes n as a parameter,
// and returns an array of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// f(n: 5) == [1, 2, 6, 24, 15]
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(1...i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
return (1...n).reduce(1, *)
}
func sum(_ range: Range<Int>) -> Int {
return range.reduce(0, +)
}
```
result.append(sum(1...i)) // cannot convert value of type 'ClosedRange<Int>' to expected argument type 'Range<Int>'
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(from: 1, to: i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
if n == 0 {
return 1
}
return n * factorial(n - 1)
}
func sum(from: Int, to: Int) -> Int {
var sum = 0
for i in from...to {
sum += i
}
return sum
}
```swift
// Implement the function f that takes n as a parameter,
// and returns an array of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// f(n: 5) == [1, 2, 6, 24, 15]
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(from: 1, to: i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
if n == 0 {
return 1
}
return n * factorial(n - 1)
}
func sum(from: Int, to: Int) -> Int {
var sum = 0
for i in from...to {
sum += i
}
return sum
}
```
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(from: 1, to: i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
func sum(from: Int, to: Int) -> Int {
var result = 0
for i in from...to {
result += i
}
return result
}
```swift
// Implement the function f that takes n as a parameter,
// and returns an array of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// f(n: 5) == [1, 2, 6, 24, 15]
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(from: 1, to: i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
func sum(from: Int, to: Int) -> Int {
var result = 0
for i in from...to {
result += i
}
return result
}
```
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(from: 1, to: i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
func sum(from start: Int, to end: Int) -> Int {
var result = 0
for i in start...end {
result += i
}
return result
}
```swift
// Implement the function f that takes n as a parameter,
// and returns an array of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// f(n: 5) == [1, 2, 6, 24, 15]
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(from: 1, to: i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
func sum(from start: Int, to end: Int) -> Int {
var result = 0
for i in start...end {
result += i
}
return result
}
```
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(from: 1, to: i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
func sum(from start: Int, to end: Int) -> Int {
var result = 0
for i in start...end {
result += i
}
return result
}
```swift
// Implement the function f that takes n as a parameter,
// and returns an array of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// f(n: 5) == [1, 2, 6, 24, 15]
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(from: 1, to: i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
func sum(from start: Int, to end: Int) -> Int {
var result = 0
for i in start...end {
result += i
}
return result
}
```
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(from: 1, to: i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
func sum(from start: Int, to end: Int) -> Int {
var result = 0
for i in start...end {
result += i
}
return result
}
```swift
// Implement the function f that takes n as a parameter,
// and returns an array of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// f(n: 5) == [1, 2, 6, 24, 15]
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(from: 1, to: i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
func sum(from start: Int, to end: Int) -> Int {
var result = 0
for i in start...end {
result += i
}
return result
}
```
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(from: 1, to: i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
return (1...n).reduce(1, *)
}
func sum(from start: Int, to end: Int) -> Int {
return (start...end).reduce(0, +)
}
```swift
// Implement the function f that takes n as a parameter,
// and returns an array of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// f(n: 5) == [1, 2, 6, 24, 15]
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(from: 1, to: i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
return (1...n).reduce(1, *)
}
func sum(from start: Int, to end: Int) -> Int {
return (start...end).reduce(0, +)
}
```
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(from: 1, to: i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
func sum(from start: Int, to end: Int) -> Int {
var result = 0
for i in start...end {
result += i
}
return result
}
```swift
// Implement the function f that takes n as a parameter,
// and returns an array of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// f(n: 5) == [1, 2, 6, 24, 15]
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(from: 1, to: i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
func sum(from start: Int, to end: Int) -> Int {
var result = 0
for i in start...end {
result += i
}
return result
}
```
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(from: 1, to: i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
return (1...n).reduce(1, *)
}
func sum(from: Int, to: Int) -> Int {
return (from...to).reduce(0, +)
}
```swift
// Implement the function f that takes n as a parameter,
// and returns an array of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// f(n: 5) == [1, 2, 6, 24, 15]
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(from: 1, to: i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
return (1...n).reduce(1, *)
}
func sum(from: Int, to: Int) -> Int {
return (from...to).reduce(0, +)
}
```
func f(n: Int) -> [Int] {
var result: [Int] = []
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(from: 1, to: i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
func sum(from start: Int, to end: Int) -> Int {
var result = 0
for i in start...end {
result += i
}
return result
}
```swift
// Implement the function f that takes n as a parameter,
// and returns an array of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// f(n: 5) == [1, 2, 6, 24, 15]
func f(n: Int) -> [Int] {
var result: [Int] = []
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(from: 1, to: i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
func sum(from start: Int, to end: Int) -> Int {
var result = 0
for i in start...end {
result += i
}
return result
}
```
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
let str = String(i)
if str == String(str.reversed()) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
```swift
// Given a positive integer n, return a tuple that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned tuple has the number of even and odd integer palindromes respectively.
// evenOddPalindrome(n: 3) == (1, 2)
// evenOddPalindrome(n: 12) == (4, 6)
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
let str = String(i)
if str == String(str.reversed()) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
```
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
let s = String(i)
let r = String(s.reversed())
if s == r {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
```swift
// Given a positive integer n, return a tuple that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned tuple has the number of even and odd integer palindromes respectively.
// evenOddPalindrome(n: 3) == (1, 2)
// evenOddPalindrome(n: 12) == (4, 6)
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
let s = String(i)
let r = String(s.reversed())
if s == r {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
```
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var num = n
var reversed = 0
while num > 0 {
reversed = reversed * 10 + num % 10
num /= 10
}
return n == reversed
}
```swift
// Given a positive integer n, return a tuple that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned tuple has the number of even and odd integer palindromes respectively.
// evenOddPalindrome(n: 3) == (1, 2)
// evenOddPalindrome(n: 12) == (4, 6)
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var num = n
var reversed = 0
while num > 0 {
reversed = reversed * 10 + num % 10
num /= 10
}
return n == reversed
}
```
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
let str = String(i)
if str == String(str.reversed()) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
```swift
// Given a positive integer n, return a tuple that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned tuple has the number of even and odd integer palindromes respectively.
// evenOddPalindrome(n: 3) == (1, 2)
// evenOddPalindrome(n: 12) == (4, 6)
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
let str = String(i)
if str == String(str.reversed()) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
```
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
let str = String(i)
let reversed = String(str.reversed())
if str == reversed {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
```swift
// Given a positive integer n, return a tuple that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned tuple has the number of even and odd integer palindromes respectively.
// evenOddPalindrome(n: 3) == (1, 2)
// evenOddPalindrome(n: 12) == (4, 6)
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
let str = String(i)
let reversed = String(str.reversed())
if str == reversed {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
```
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
let str = String(i)
if str == String(str.reversed()) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
```swift
// Given a positive integer n, return a tuple that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned tuple has the number of even and odd integer palindromes respectively.
// evenOddPalindrome(n: 3) == (1, 2)
// evenOddPalindrome(n: 12) == (4, 6)
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
let str = String(i)
if str == String(str.reversed()) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
```
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var num = n
var reverse = 0
while num > 0 {
reverse = reverse * 10 + num % 10
num /= 10
}
return n == reverse
}
```swift
// Given a positive integer n, return a tuple that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned tuple has the number of even and odd integer palindromes respectively.
// evenOddPalindrome(n: 3) == (1, 2)
// evenOddPalindrome(n: 12) == (4, 6)
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var num = n
var reverse = 0
while num > 0 {
reverse = reverse * 10 + num % 10
num /= 10
}
return n == reverse
}
```
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var n = n
var reversed = 0
while n > 0 {
reversed = reversed * 10 + n % 10
n /= 10
}
return reversed == n
}
```swift
// Given a positive integer n, return a tuple that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned tuple has the number of even and odd integer palindromes respectively.
// evenOddPalindrome(n: 3) == (1, 2)
// evenOddPalindrome(n: 12) == (4, 6)
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var n = n
var reversed = 0
while n > 0 {
reversed = reversed * 10 + n % 10
n /= 10
}
return reversed == n
}
```
// XCTAssertTrue failed
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
let str = String(i)
if str == String(str.reversed()) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
```swift
// Given a positive integer n, return a tuple that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned tuple has the number of even and odd integer palindromes respectively.
// evenOddPalindrome(n: 3) == (1, 2)
// evenOddPalindrome(n: 12) == (4, 6)
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
let str = String(i)
if str == String(str.reversed()) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
```
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
let s = String(i)
if s == String(s.reversed()) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
```swift
// Given a positive integer n, return a tuple that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned tuple has the number of even and odd integer palindromes respectively.
// evenOddPalindrome(n: 3) == (1, 2)
// evenOddPalindrome(n: 12) == (4, 6)
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
let s = String(i)
if s == String(s.reversed()) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
```
func countNums(arr: [Int]) -> Int {
var count = 0
for num in arr {
var sum = 0
var num = num
while num!= 0 {
sum += num % 10
num /= 10
}
if sum > 0 {
count += 1
}
}
return count
}
```swift
// Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// countNums(arr: [] as [Int]) == 0
// countNums(arr: [-1, 11, -11]) == 1
// countNums(arr: [1, 1, 2]) == 3
func countNums(arr: [Int]) -> Int {
var count = 0
for num in arr {
var sum = 0
var num = num
while num!= 0 {
sum += num % 10
num /= 10
}
if sum > 0 {
count += 1
}
}
return count
}
```
while num!= 0 { // '=' must have consistent whitespace on both sides
while num!= 0 { // cannot force unwrap value of non-optional type 'Int'
while num!= 0 { // use of '=' in a boolean context, did you mean '=='?
func countNums(arr: [Int]) -> Int {
var count = 0
for num in arr {
if num > 0 {
count += 1
}
}
return count
}
```swift
// Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// countNums(arr: [] as [Int]) == 0
// countNums(arr: [-1, 11, -11]) == 1
// countNums(arr: [1, 1, 2]) == 3
func countNums(arr: [Int]) -> Int {
var count = 0
for num in arr {
if num > 0 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func countNums(arr: [Int]) -> Int {
var count = 0
for num in arr {
if num > 0 {
count += 1
}
}
return count
}
```swift
// Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// countNums(arr: [] as [Int]) == 0
// countNums(arr: [-1, 11, -11]) == 1
// countNums(arr: [1, 1, 2]) == 3
func countNums(arr: [Int]) -> Int {
var count = 0
for num in arr {
if num > 0 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func countNums(arr: [Int]) -> Int {
return 0
}
```swift
// Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// countNums(arr: [] as [Int]) == 0
// countNums(arr: [-1, 11, -11]) == 1
// countNums(arr: [1, 1, 2]) == 3
func countNums(arr: [Int]) -> Int {
return 0
}
```
// XCTAssertTrue failed
func countNums(arr: [Int]) -> Int {
return 0
}
```swift
// Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// countNums(arr: [] as [Int]) == 0
// countNums(arr: [-1, 11, -11]) == 1
// countNums(arr: [1, 1, 2]) == 3
func countNums(arr: [Int]) -> Int {
return 0
}
```
// XCTAssertTrue failed
func countNums(arr: [Int]) -> Int {
// your code here
}
```swift
// Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// countNums(arr: [] as [Int]) == 0
// countNums(arr: [-1, 11, -11]) == 1
// countNums(arr: [1, 1, 2]) == 3
func countNums(arr: [Int]) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func countNums(arr: [Int]) -> Int {
return arr.filter { $0 > 0 }.reduce(0) { $0 + 1 }
}
```swift
// Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// countNums(arr: [] as [Int]) == 0
// countNums(arr: [-1, 11, -11]) == 1
// countNums(arr: [1, 1, 2]) == 3
func countNums(arr: [Int]) -> Int {
return arr.filter { $0 > 0 }.reduce(0) { $0 + 1 }
}
```
return arr.filter { $0 > 0 }.reduce(0) { $0 + 1 } // contextual closure type '(Int, Int) throws -> Int' expects 2 arguments, but 1 was used in closure body
func countNums(arr: [Int]) -> Int {
return 0
}
```swift
// Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// countNums(arr: [] as [Int]) == 0
// countNums(arr: [-1, 11, -11]) == 1
// countNums(arr: [1, 1, 2]) == 3
func countNums(arr: [Int]) -> Int {
return 0
}
```
// XCTAssertTrue failed
func countNums(arr: [Int]) -> Int {
// your code here
}
```swift
// Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// countNums(arr: [] as [Int]) == 0
// countNums(arr: [-1, 11, -11]) == 1
// countNums(arr: [1, 1, 2]) == 3
func countNums(arr: [Int]) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func countNums(arr: [Int]) -> Int {
return 0
}
```swift
// Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// countNums(arr: [] as [Int]) == 0
// countNums(arr: [-1, 11, -11]) == 1
// countNums(arr: [1, 1, 2]) == 3
func countNums(arr: [Int]) -> Int {
return 0
}
```
// XCTAssertTrue failed
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here
}
```swift
// We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array will be randomly ordered. Your task is to determine if
// it is possible to get an array sorted in non-decreasing order by performing
// the following operation on the given array:
// You are allowed to perform right shift operation any number of times.
// One right shift operation means shifting all elements of the array by one
// position in the right direction. The last element of the array will be moved to
// the starting position in the array i.e. 0th index.
// If it is possible to obtain the sorted array by performing the above operation
// then return true else return false.
// If the given array is empty then return true.
// Note: The given array is guaranteed to have unique elements.
// For Example:
// Explanation: By performin 2 right shift operations, non-decreasing order can
// be achieved for the given array.
// Explanation:It is not possible to get non-decreasing order for the given
// array by performing any number of right shift operations.
// moveOneBall(arr: [3, 4, 5, 1, 2]) == true
// moveOneBall(arr: [3, 5, 4, 1, 2]) == false
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here
}
```swift
// We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array will be randomly ordered. Your task is to determine if
// it is possible to get an array sorted in non-decreasing order by performing
// the following operation on the given array:
// You are allowed to perform right shift operation any number of times.
// One right shift operation means shifting all elements of the array by one
// position in the right direction. The last element of the array will be moved to
// the starting position in the array i.e. 0th index.
// If it is possible to obtain the sorted array by performing the above operation
// then return true else return false.
// If the given array is empty then return true.
// Note: The given array is guaranteed to have unique elements.
// For Example:
// Explanation: By performin 2 right shift operations, non-decreasing order can
// be achieved for the given array.
// Explanation:It is not possible to get non-decreasing order for the given
// array by performing any number of right shift operations.
// moveOneBall(arr: [3, 4, 5, 1, 2]) == true
// moveOneBall(arr: [3, 5, 4, 1, 2]) == false
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here
}
```swift
// We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array will be randomly ordered. Your task is to determine if
// it is possible to get an array sorted in non-decreasing order by performing
// the following operation on the given array:
// You are allowed to perform right shift operation any number of times.
// One right shift operation means shifting all elements of the array by one
// position in the right direction. The last element of the array will be moved to
// the starting position in the array i.e. 0th index.
// If it is possible to obtain the sorted array by performing the above operation
// then return true else return false.
// If the given array is empty then return true.
// Note: The given array is guaranteed to have unique elements.
// For Example:
// Explanation: By performin 2 right shift operations, non-decreasing order can
// be achieved for the given array.
// Explanation:It is not possible to get non-decreasing order for the given
// array by performing any number of right shift operations.
// moveOneBall(arr: [3, 4, 5, 1, 2]) == true
// moveOneBall(arr: [3, 5, 4, 1, 2]) == false
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here.
}
```swift
// We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array will be randomly ordered. Your task is to determine if
// it is possible to get an array sorted in non-decreasing order by performing
// the following operation on the given array:
// You are allowed to perform right shift operation any number of times.
// One right shift operation means shifting all elements of the array by one
// position in the right direction. The last element of the array will be moved to
// the starting position in the array i.e. 0th index.
// If it is possible to obtain the sorted array by performing the above operation
// then return true else return false.
// If the given array is empty then return true.
// Note: The given array is guaranteed to have unique elements.
// For Example:
// Explanation: By performin 2 right shift operations, non-decreasing order can
// be achieved for the given array.
// Explanation:It is not possible to get non-decreasing order for the given
// array by performing any number of right shift operations.
// moveOneBall(arr: [3, 4, 5, 1, 2]) == true
// moveOneBall(arr: [3, 5, 4, 1, 2]) == false
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here.
}
```
} // missing return in global function expected to return 'Bool'
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here
}
```swift
// We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array will be randomly ordered. Your task is to determine if
// it is possible to get an array sorted in non-decreasing order by performing
// the following operation on the given array:
// You are allowed to perform right shift operation any number of times.
// One right shift operation means shifting all elements of the array by one
// position in the right direction. The last element of the array will be moved to
// the starting position in the array i.e. 0th index.
// If it is possible to obtain the sorted array by performing the above operation
// then return true else return false.
// If the given array is empty then return true.
// Note: The given array is guaranteed to have unique elements.
// For Example:
// Explanation: By performin 2 right shift operations, non-decreasing order can
// be achieved for the given array.
// Explanation:It is not possible to get non-decreasing order for the given
// array by performing any number of right shift operations.
// moveOneBall(arr: [3, 4, 5, 1, 2]) == true
// moveOneBall(arr: [3, 5, 4, 1, 2]) == false
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here.
}
```swift
// We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array will be randomly ordered. Your task is to determine if
// it is possible to get an array sorted in non-decreasing order by performing
// the following operation on the given array:
// You are allowed to perform right shift operation any number of times.
// One right shift operation means shifting all elements of the array by one
// position in the right direction. The last element of the array will be moved to
// the starting position in the array i.e. 0th index.
// If it is possible to obtain the sorted array by performing the above operation
// then return true else return false.
// If the given array is empty then return true.
// Note: The given array is guaranteed to have unique elements.
// For Example:
// Explanation: By performin 2 right shift operations, non-decreasing order can
// be achieved for the given array.
// Explanation:It is not possible to get non-decreasing order for the given
// array by performing any number of right shift operations.
// moveOneBall(arr: [3, 4, 5, 1, 2]) == true
// moveOneBall(arr: [3, 5, 4, 1, 2]) == false
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here.
}
```
} // missing return in global function expected to return 'Bool'
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here
}
```swift
// We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array will be randomly ordered. Your task is to determine if
// it is possible to get an array sorted in non-decreasing order by performing
// the following operation on the given array:
// You are allowed to perform right shift operation any number of times.
// One right shift operation means shifting all elements of the array by one
// position in the right direction. The last element of the array will be moved to
// the starting position in the array i.e. 0th index.
// If it is possible to obtain the sorted array by performing the above operation
// then return true else return false.
// If the given array is empty then return true.
// Note: The given array is guaranteed to have unique elements.
// For Example:
// Explanation: By performin 2 right shift operations, non-decreasing order can
// be achieved for the given array.
// Explanation:It is not possible to get non-decreasing order for the given
// array by performing any number of right shift operations.
// moveOneBall(arr: [3, 4, 5, 1, 2]) == true
// moveOneBall(arr: [3, 5, 4, 1, 2]) == false
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here.
}
```swift
// We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array will be randomly ordered. Your task is to determine if
// it is possible to get an array sorted in non-decreasing order by performing
// the following operation on the given array:
// You are allowed to perform right shift operation any number of times.
// One right shift operation means shifting all elements of the array by one
// position in the right direction. The last element of the array will be moved to
// the starting position in the array i.e. 0th index.
// If it is possible to obtain the sorted array by performing the above operation
// then return true else return false.
// If the given array is empty then return true.
// Note: The given array is guaranteed to have unique elements.
// For Example:
// Explanation: By performin 2 right shift operations, non-decreasing order can
// be achieved for the given array.
// Explanation:It is not possible to get non-decreasing order for the given
// array by performing any number of right shift operations.
// moveOneBall(arr: [3, 4, 5, 1, 2]) == true
// moveOneBall(arr: [3, 5, 4, 1, 2]) == false
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here.
}
```
} // missing return in global function expected to return 'Bool'
func moveOneBall(arr: [Int]) -> Bool {
return true
}
```swift
// We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array will be randomly ordered. Your task is to determine if
// it is possible to get an array sorted in non-decreasing order by performing
// the following operation on the given array:
// You are allowed to perform right shift operation any number of times.
// One right shift operation means shifting all elements of the array by one
// position in the right direction. The last element of the array will be moved to
// the starting position in the array i.e. 0th index.
// If it is possible to obtain the sorted array by performing the above operation
// then return true else return false.
// If the given array is empty then return true.
// Note: The given array is guaranteed to have unique elements.
// For Example:
// Explanation: By performin 2 right shift operations, non-decreasing order can
// be achieved for the given array.
// Explanation:It is not possible to get non-decreasing order for the given
// array by performing any number of right shift operations.
// moveOneBall(arr: [3, 4, 5, 1, 2]) == true
// moveOneBall(arr: [3, 5, 4, 1, 2]) == false
func moveOneBall(arr: [Int]) -> Bool {
return true
}
```
// XCTAssertTrue failed
func moveOneBall(arr: [Int]) -> Bool {
var arr = arr
var count = 0
while arr.count > 1 {
var i = 0
while i < arr.count - 1 {
if arr[i] > arr[i + 1] {
arr.swapAt(i, i + 1)
count += 1
}
i += 1
}
}
return count % 2 == 0
}
```swift
// We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array will be randomly ordered. Your task is to determine if
// it is possible to get an array sorted in non-decreasing order by performing
// the following operation on the given array:
// You are allowed to perform right shift operation any number of times.
// One right shift operation means shifting all elements of the array by one
// position in the right direction. The last element of the array will be moved to
// the starting position in the array i.e. 0th index.
// If it is possible to obtain the sorted array by performing the above operation
// then return true else return false.
// If the given array is empty then return true.
// Note: The given array is guaranteed to have unique elements.
// For Example:
// Explanation: By performin 2 right shift operations, non-decreasing order can
// be achieved for the given array.
// Explanation:It is not possible to get non-decreasing order for the given
// array by performing any number of right shift operations.
// moveOneBall(arr: [3, 4, 5, 1, 2]) == true
// moveOneBall(arr: [3, 5, 4, 1, 2]) == false
func moveOneBall(arr: [Int]) -> Bool {
var arr = arr
var count = 0
while arr.count > 1 {
var i = 0
while i < arr.count - 1 {
if arr[i] > arr[i + 1] {
arr.swapAt(i, i + 1)
count += 1
}
i += 1
}
}
return count % 2 == 0
}
```
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var count = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 0 {
count += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
count -= 1
}
}
if count == 0 {
return "YES"
} else {
return "NO"
}
}
```swift
// In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// It is assumed that the input arrays will be non-empty.
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 2, 3, 4]) == "YES"
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 5, 3, 4]) == "NO"
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var count = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 0 {
count += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
count -= 1
}
}
if count == 0 {
return "YES"
} else {
return "NO"
}
}
```
var lst1 = lst1 // variable 'lst1' was never mutated; consider changing to 'let' constant
var lst2 = lst2 // variable 'lst2' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var count = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 1 {
count += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 1 {
count -= 1
}
}
if count == 0 {
return "YES"
}
return "NO"
}
```swift
// In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// It is assumed that the input arrays will be non-empty.
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 2, 3, 4]) == "YES"
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 5, 3, 4]) == "NO"
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var count = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 1 {
count += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 1 {
count -= 1
}
}
if count == 0 {
return "YES"
}
return "NO"
}
```
var lst1 = lst1 // variable 'lst1' was never mutated; consider changing to 'let' constant
var lst2 = lst2 // variable 'lst2' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var count = 0
var temp = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 1 {
count += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 1 {
count -= 1
}
}
if count > 0 {
return "NO"
}
for i in 0..<lst1.count {
if lst1[i] % 2 == 1 {
for j in 0..<lst2.count {
if lst2[j] % 2 == 0 {
temp = lst1[i]
lst1[i] = lst2[j]
lst2[j] = temp
break
}
}
}
}
for i in 0..<lst1.count {
if lst1[i] % 2 == 1 {
return "NO"
}
}
return "YES"
}
```swift
// In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// It is assumed that the input arrays will be non-empty.
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 2, 3, 4]) == "YES"
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 5, 3, 4]) == "NO"
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var count = 0
var temp = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 1 {
count += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 1 {
count -= 1
}
}
if count > 0 {
return "NO"
}
for i in 0..<lst1.count {
if lst1[i] % 2 == 1 {
for j in 0..<lst2.count {
if lst2[j] % 2 == 0 {
temp = lst1[i]
lst1[i] = lst2[j]
lst2[j] = temp
break
}
}
}
}
for i in 0..<lst1.count {
if lst1[i] % 2 == 1 {
return "NO"
}
}
return "YES"
}
```
// XCTAssertTrue failed
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var result = "NO"
for i in 0..<lst1.count {
if lst1[i] % 2 == 0 {
continue
}
for j in 0..<lst2.count {
if lst2[j] % 2 == 0 {
continue
}
lst1[i] = lst2[j]
lst2[j] = lst1[i]
result = "YES"
break
}
}
return result
}
```swift
// In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// It is assumed that the input arrays will be non-empty.
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 2, 3, 4]) == "YES"
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 5, 3, 4]) == "NO"
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var result = "NO"
for i in 0..<lst1.count {
if lst1[i] % 2 == 0 {
continue
}
for j in 0..<lst2.count {
if lst2[j] % 2 == 0 {
continue
}
lst1[i] = lst2[j]
lst2[j] = lst1[i]
result = "YES"
break
}
}
return result
}
```
// XCTAssertTrue failed
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var count = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 1 {
count += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 1 {
count -= 1
}
}
if count > 0 {
return "NO"
} else {
return "YES"
}
}
```swift
// In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// It is assumed that the input arrays will be non-empty.
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 2, 3, 4]) == "YES"
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 5, 3, 4]) == "NO"
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var count = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 1 {
count += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 1 {
count -= 1
}
}
if count > 0 {
return "NO"
} else {
return "YES"
}
}
```
var lst1 = lst1 // variable 'lst1' was never mutated; consider changing to 'let' constant
var lst2 = lst2 // variable 'lst2' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var evenCount = 0
var oddCount = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
if evenCount == lst1.count && oddCount == lst2.count {
return "YES"
} else {
return "NO"
}
}
```swift
// In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// It is assumed that the input arrays will be non-empty.
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 2, 3, 4]) == "YES"
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 5, 3, 4]) == "NO"
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var evenCount = 0
var oddCount = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
if evenCount == lst1.count && oddCount == lst2.count {
return "YES"
} else {
return "NO"
}
}
```
var lst1 = lst1 // variable 'lst1' was never mutated; consider changing to 'let' constant
var lst2 = lst2 // variable 'lst2' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var count = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 1 {
count += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 1 {
count += 1
}
}
if count % 2 == 0 {
return "YES"
} else {
return "NO"
}
}
```swift
// In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// It is assumed that the input arrays will be non-empty.
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 2, 3, 4]) == "YES"
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 5, 3, 4]) == "NO"
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var count = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 1 {
count += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 1 {
count += 1
}
}
if count % 2 == 0 {
return "YES"
} else {
return "NO"
}
}
```
var lst1 = lst1 // variable 'lst1' was never mutated; consider changing to 'let' constant
var lst2 = lst2 // variable 'lst2' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var count = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 0 {
count += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
count -= 1
}
}
if count == 0 {
return "YES"
} else {
return "NO"
}
}
```swift
// In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// It is assumed that the input arrays will be non-empty.
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 2, 3, 4]) == "YES"
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 5, 3, 4]) == "NO"
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var count = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 0 {
count += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
count -= 1
}
}
if count == 0 {
return "YES"
} else {
return "NO"
}
}
```
var lst1 = lst1 // variable 'lst1' was never mutated; consider changing to 'let' constant
var lst2 = lst2 // variable 'lst2' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var count = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 0 {
count += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
count -= 1
}
}
if count == 0 {
return "YES"
} else {
return "NO"
}
}
```swift
// In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// It is assumed that the input arrays will be non-empty.
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 2, 3, 4]) == "YES"
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 5, 3, 4]) == "NO"
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var count = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 0 {
count += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
count -= 1
}
}
if count == 0 {
return "YES"
} else {
return "NO"
}
}
```
var lst1 = lst1 // variable 'lst1' was never mutated; consider changing to 'let' constant
var lst2 = lst2 // variable 'lst2' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var count = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 0 {
count += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
count -= 1
}
}
if count == 0 {
return "YES"
} else {
return "NO"
}
}
```swift
// In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// It is assumed that the input arrays will be non-empty.
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 2, 3, 4]) == "YES"
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 5, 3, 4]) == "NO"
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var count = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 0 {
count += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
count -= 1
}
}
if count == 0 {
return "YES"
} else {
return "NO"
}
}
```
var lst1 = lst1 // variable 'lst1' was never mutated; consider changing to 'let' constant
var lst2 = lst2 // variable 'lst2' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func histogram(test: String) -> [String : Int] {
var result = [String : Int]()
let words = test.components(separatedBy: " ")
for word in words {
if result[word] == nil {
result[word] = 1
} else {
result[word]! += 1
}
}
return result
}
```swift
// Given a string representing a space separated lowercase letters, return a dictionary
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// histogram(test: "a b c") == ["a" : 1, "b" : 1, "c" : 1]
// histogram(test: "a b b a") == ["a" : 2, "b" : 2]
// histogram(test: "a b c a b") == ["a" : 2, "b" : 2]
// histogram(test: "b b b b a") == ["b" : 4]
// histogram(test: "") == [:] as [String : Int]
func histogram(test: String) -> [String : Int] {
var result = [String : Int]()
let words = test.components(separatedBy: " ")
for word in words {
if result[word] == nil {
result[word] = 1
} else {
result[word]! += 1
}
}
return result
}
```
// XCTAssertTrue failed
func histogram(test: String) -> [String : Int] {
var result = [String : Int]()
let words = test.components(separatedBy: " ")
for word in words {
if result[word] == nil {
result[word] = 1
} else {
result[word]! += 1
}
}
return result
}
```swift
// Given a string representing a space separated lowercase letters, return a dictionary
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// histogram(test: "a b c") == ["a" : 1, "b" : 1, "c" : 1]
// histogram(test: "a b b a") == ["a" : 2, "b" : 2]
// histogram(test: "a b c a b") == ["a" : 2, "b" : 2]
// histogram(test: "b b b b a") == ["b" : 4]
// histogram(test: "") == [:] as [String : Int]
func histogram(test: String) -> [String : Int] {
var result = [String : Int]()
let words = test.components(separatedBy: " ")
for word in words {
if result[word] == nil {
result[word] = 1
} else {
result[word]! += 1
}
}
return result
}
```
// XCTAssertTrue failed
func histogram(test: String) -> [String : Int] {
var result = [String : Int]()
var max = 0
var maxLetters = [String]()
let letters = test.components(separatedBy: " ")
for letter in letters {
if let count = result[letter] {
result[letter] = count + 1
} else {
result[letter] = 1
}
if result[letter]! > max {
max = result[letter]!
maxLetters = [letter]
} else if result[letter]! == max {
maxLetters.append(letter)
}
}
var resultDict = [String : Int]()
for letter in maxLetters {
resultDict[letter] = max
}
return resultDict
}
```swift
// Given a string representing a space separated lowercase letters, return a dictionary
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// histogram(test: "a b c") == ["a" : 1, "b" : 1, "c" : 1]
// histogram(test: "a b b a") == ["a" : 2, "b" : 2]
// histogram(test: "a b c a b") == ["a" : 2, "b" : 2]
// histogram(test: "b b b b a") == ["b" : 4]
// histogram(test: "") == [:] as [String : Int]
func histogram(test: String) -> [String : Int] {
var result = [String : Int]()
var max = 0
var maxLetters = [String]()
let letters = test.components(separatedBy: " ")
for letter in letters {
if let count = result[letter] {
result[letter] = count + 1
} else {
result[letter] = 1
}
if result[letter]! > max {
max = result[letter]!
maxLetters = [letter]
} else if result[letter]! == max {
maxLetters.append(letter)
}
}
var resultDict = [String : Int]()
for letter in maxLetters {
resultDict[letter] = max
}
return resultDict
}
```
// XCTAssertTrue failed
func histogram(test: String) -> [String : Int] {
var result = [String : Int]()
let words = test.components(separatedBy: " ")
for word in words {
if let count = result[word] {
result[word] = count + 1
} else {
result[word] = 1
}
}
return result
}
```swift
// Given a string representing a space separated lowercase letters, return a dictionary
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// histogram(test: "a b c") == ["a" : 1, "b" : 1, "c" : 1]
// histogram(test: "a b b a") == ["a" : 2, "b" : 2]
// histogram(test: "a b c a b") == ["a" : 2, "b" : 2]
// histogram(test: "b b b b a") == ["b" : 4]
// histogram(test: "") == [:] as [String : Int]
func histogram(test: String) -> [String : Int] {
var result = [String : Int]()
let words = test.components(separatedBy: " ")
for word in words {
if let count = result[word] {
result[word] = count + 1
} else {
result[word] = 1
}
}
return result
}
```
// XCTAssertTrue failed
func histogram(test: String) -> [String : Int] {
var result = [String : Int]()
let words = test.components(separatedBy: " ")
for word in words {
if let count = result[word] {
result[word] = count + 1
} else {
result[word] = 1
}
}
return result
}
```swift
// Given a string representing a space separated lowercase letters, return a dictionary
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// histogram(test: "a b c") == ["a" : 1, "b" : 1, "c" : 1]
// histogram(test: "a b b a") == ["a" : 2, "b" : 2]
// histogram(test: "a b c a b") == ["a" : 2, "b" : 2]
// histogram(test: "b b b b a") == ["b" : 4]
// histogram(test: "") == [:] as [String : Int]
func histogram(test: String) -> [String : Int] {
var result = [String : Int]()
let words = test.components(separatedBy: " ")
for word in words {
if let count = result[word] {
result[word] = count + 1
} else {
result[word] = 1
}
}
return result
}
```
// XCTAssertTrue failed
func histogram(test: String) -> [String : Int] {
var result = [String : Int]()
let words = test.components(separatedBy: " ")
for word in words {
if let count = result[word] {
result[word] = count + 1
} else {
result[word] = 1
}
}
return result
}
```swift
// Given a string representing a space separated lowercase letters, return a dictionary
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// histogram(test: "a b c") == ["a" : 1, "b" : 1, "c" : 1]
// histogram(test: "a b b a") == ["a" : 2, "b" : 2]
// histogram(test: "a b c a b") == ["a" : 2, "b" : 2]
// histogram(test: "b b b b a") == ["b" : 4]
// histogram(test: "") == [:] as [String : Int]
func histogram(test: String) -> [String : Int] {
var result = [String : Int]()
let words = test.components(separatedBy: " ")
for word in words {
if let count = result[word] {
result[word] = count + 1
} else {
result[word] = 1
}
}
return result
}
```
// XCTAssertTrue failed
func histogram(test: String) -> [String : Int] {
var result = [String : Int]()
let words = test.components(separatedBy: " ")
for word in words {
if let count = result[word] {
result[word] = count + 1
} else {
result[word] = 1
}
}
return result
}
```swift
// Given a string representing a space separated lowercase letters, return a dictionary
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// histogram(test: "a b c") == ["a" : 1, "b" : 1, "c" : 1]
// histogram(test: "a b b a") == ["a" : 2, "b" : 2]
// histogram(test: "a b c a b") == ["a" : 2, "b" : 2]
// histogram(test: "b b b b a") == ["b" : 4]
// histogram(test: "") == [:] as [String : Int]
func histogram(test: String) -> [String : Int] {
var result = [String : Int]()
let words = test.components(separatedBy: " ")
for word in words {
if let count = result[word] {
result[word] = count + 1
} else {
result[word] = 1
}
}
return result
}
```
// XCTAssertTrue failed
func histogram(test: String) -> [String : Int] {
var result = [String : Int]()
let words = test.components(separatedBy: " ")
for word in words {
if let count = result[word] {
result[word] = count + 1
} else {
result[word] = 1
}
}
return result
}
```swift
// Given a string representing a space separated lowercase letters, return a dictionary
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// histogram(test: "a b c") == ["a" : 1, "b" : 1, "c" : 1]
// histogram(test: "a b b a") == ["a" : 2, "b" : 2]
// histogram(test: "a b c a b") == ["a" : 2, "b" : 2]
// histogram(test: "b b b b a") == ["b" : 4]
// histogram(test: "") == [:] as [String : Int]
func histogram(test: String) -> [String : Int] {
var result = [String : Int]()
let words = test.components(separatedBy: " ")
for word in words {
if let count = result[word] {
result[word] = count + 1
} else {
result[word] = 1
}
}
return result
}
```
// XCTAssertTrue failed
func histogram(test: String) -> [String : Int] {
var result = [String : Int]()
let words = test.components(separatedBy: " ")
for word in words {
if result[word] == nil {
result[word] = 1
} else {
result[word]! += 1
}
}
return result
}
```swift
// Given a string representing a space separated lowercase letters, return a dictionary
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// histogram(test: "a b c") == ["a" : 1, "b" : 1, "c" : 1]
// histogram(test: "a b b a") == ["a" : 2, "b" : 2]
// histogram(test: "a b c a b") == ["a" : 2, "b" : 2]
// histogram(test: "b b b b a") == ["b" : 4]
// histogram(test: "") == [:] as [String : Int]
func histogram(test: String) -> [String : Int] {
var result = [String : Int]()
let words = test.components(separatedBy: " ")
for word in words {
if result[word] == nil {
result[word] = 1
} else {
result[word]! += 1
}
}
return result
}
```
// XCTAssertTrue failed
func histogram(test: String) -> [String : Int] {
var result = [String : Int]()
var words = test.components(separatedBy: " ")
for word in words {
if result[word] == nil {
result[word] = 1
} else {
result[word]! += 1
}
}
return result
}
```swift
// Given a string representing a space separated lowercase letters, return a dictionary
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// histogram(test: "a b c") == ["a" : 1, "b" : 1, "c" : 1]
// histogram(test: "a b b a") == ["a" : 2, "b" : 2]
// histogram(test: "a b c a b") == ["a" : 2, "b" : 2]
// histogram(test: "b b b b a") == ["b" : 4]
// histogram(test: "") == [:] as [String : Int]
func histogram(test: String) -> [String : Int] {
var result = [String : Int]()
var words = test.components(separatedBy: " ")
for word in words {
if result[word] == nil {
result[word] = 1
} else {
result[word]! += 1
}
}
return result
}
```
var words = test.components(separatedBy: " ") // variable 'words' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var set = Set(c)
for char in s {
if!set.contains(char) {
result.append(char)
}
}
return (result, result == String(result.reversed()))
}
```swift
// Task
// We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
// then check if the result string is palindrome.
// A string is called palindrome if it reads the same backward as forward.
// You should return a tuple containing the result string and true/false for the check.
// Example
// reverseDelete(s: "abcde", c: "ae") == ("bcd", false)
// reverseDelete(s: "abcdef", c: "b") == ("acdef", false)
// reverseDelete(s: "abcdedcba", c: "ab") == ("cdedc", true)
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var set = Set(c)
for char in s {
if!set.contains(char) {
result.append(char)
}
}
return (result, result == String(result.reversed()))
}
```
if!set.contains(char) { // expected expression, var, or let in 'if' condition
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var isPalindrome = false
var s = s
var c = c
for char in s {
if c.contains(char) {
continue
}
result.append(char)
}
if result.reversed() == result {
isPalindrome = true
}
return (result, isPalindrome)
}
```swift
// Task
// We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
// then check if the result string is palindrome.
// A string is called palindrome if it reads the same backward as forward.
// You should return a tuple containing the result string and true/false for the check.
// Example
// reverseDelete(s: "abcde", c: "ae") == ("bcd", false)
// reverseDelete(s: "abcdef", c: "b") == ("acdef", false)
// reverseDelete(s: "abcdedcba", c: "ab") == ("cdedc", true)
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var isPalindrome = false
var s = s
var c = c
for char in s {
if c.contains(char) {
continue
}
result.append(char)
}
if result.reversed() == result {
isPalindrome = true
}
return (result, isPalindrome)
}
```
if result.reversed() == result { // binary operator '==' cannot be applied to operands of type '[String.Element]' (aka 'Array<Character>') and 'String'
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var isPalindrome = false
for char in s {
if c.contains(char) {
continue
}
result.append(char)
}
if result.reversed() == result {
isPalindrome = true
}
return (result, isPalindrome)
}
```swift
// Task
// We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
// then check if the result string is palindrome.
// A string is called palindrome if it reads the same backward as forward.
// You should return a tuple containing the result string and true/false for the check.
// Example
// reverseDelete(s: "abcde", c: "ae") == ("bcd", false)
// reverseDelete(s: "abcdef", c: "b") == ("acdef", false)
// reverseDelete(s: "abcdedcba", c: "ab") == ("cdedc", true)
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var isPalindrome = false
for char in s {
if c.contains(char) {
continue
}
result.append(char)
}
if result.reversed() == result {
isPalindrome = true
}
return (result, isPalindrome)
}
```
if result.reversed() == result { // binary operator '==' cannot be applied to operands of type '[String.Element]' (aka 'Array<Character>') and 'String'
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var isPalindrome = false
for char in s {
if!c.contains(char) {
result.append(char)
}
}
if result.reversed() == result {
isPalindrome = true
}
return (result, isPalindrome)
}
```swift
// Task
// We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
// then check if the result string is palindrome.
// A string is called palindrome if it reads the same backward as forward.
// You should return a tuple containing the result string and true/false for the check.
// Example
// reverseDelete(s: "abcde", c: "ae") == ("bcd", false)
// reverseDelete(s: "abcdef", c: "b") == ("acdef", false)
// reverseDelete(s: "abcdedcba", c: "ab") == ("cdedc", true)
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var isPalindrome = false
for char in s {
if!c.contains(char) {
result.append(char)
}
}
if result.reversed() == result {
isPalindrome = true
}
return (result, isPalindrome)
}
```
if!c.contains(char) { // expected expression, var, or let in 'if' condition
if result.reversed() == result { // binary operator '==' cannot be applied to operands of type '[String.Element]' (aka 'Array<Character>') and 'String'
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var c = c
for char in s {
if c.contains(char) {
c.remove(at: c.firstIndex(of: char)!)
} else {
result.append(char)
}
}
return (result, result.reversed() == result)
}
```swift
// Task
// We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
// then check if the result string is palindrome.
// A string is called palindrome if it reads the same backward as forward.
// You should return a tuple containing the result string and true/false for the check.
// Example
// reverseDelete(s: "abcde", c: "ae") == ("bcd", false)
// reverseDelete(s: "abcdef", c: "b") == ("acdef", false)
// reverseDelete(s: "abcdedcba", c: "ab") == ("cdedc", true)
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var c = c
for char in s {
if c.contains(char) {
c.remove(at: c.firstIndex(of: char)!)
} else {
result.append(char)
}
}
return (result, result.reversed() == result)
}
```
return (result, result.reversed() == result) // binary operator '==' cannot be applied to operands of type '[String.Element]' (aka 'Array<Character>') and 'String'
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var isPalindrome = true
for char in s {
if c.contains(char) {
continue
}
result.append(char)
if result.count > 1 {
if result.first!= result.last {
isPalindrome = false
}
}
}
return (result, isPalindrome)
}
```swift
// Task
// We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
// then check if the result string is palindrome.
// A string is called palindrome if it reads the same backward as forward.
// You should return a tuple containing the result string and true/false for the check.
// Example
// reverseDelete(s: "abcde", c: "ae") == ("bcd", false)
// reverseDelete(s: "abcdef", c: "b") == ("acdef", false)
// reverseDelete(s: "abcdedcba", c: "ab") == ("cdedc", true)
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var isPalindrome = true
for char in s {
if c.contains(char) {
continue
}
result.append(char)
if result.count > 1 {
if result.first!= result.last {
isPalindrome = false
}
}
}
return (result, isPalindrome)
}
```
if result.first!= result.last { // value of optional type 'String.Element?' (aka 'Optional<Character>') must be unwrapped to a value of type 'String.Element' (aka 'Character')
if result.first!= result.last { // cannot assign through '!': 'first' is a get-only property
if result.first!= result.last { // '=' must have consistent whitespace on both sides
if result.first!= result.last { // use of '=' in a boolean context, did you mean '=='?
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var isPalindrome = true
for char in s {
if c.contains(char) {
continue
}
result.append(char)
if result.count > 1 && result.last!= result.first {
isPalindrome = false
}
}
return (result, isPalindrome)
}
```swift
// Task
// We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
// then check if the result string is palindrome.
// A string is called palindrome if it reads the same backward as forward.
// You should return a tuple containing the result string and true/false for the check.
// Example
// reverseDelete(s: "abcde", c: "ae") == ("bcd", false)
// reverseDelete(s: "abcdef", c: "b") == ("acdef", false)
// reverseDelete(s: "abcdedcba", c: "ab") == ("cdedc", true)
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var isPalindrome = true
for char in s {
if c.contains(char) {
continue
}
result.append(char)
if result.count > 1 && result.last!= result.first {
isPalindrome = false
}
}
return (result, isPalindrome)
}
```
if result.count > 1 && result.last!= result.first { // expression is not assignable: '&&' returns immutable value
if result.count > 1 && result.last!= result.first { // use of '=' in a boolean context, did you mean '=='?
if result.count > 1 && result.last!= result.first { // '=' must have consistent whitespace on both sides
if result.count > 1 && result.last!= result.first { // cannot convert value of type 'String.Element' (aka 'Character') to expected argument type 'Bool'
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var set = Set(c)
for char in s {
if!set.contains(char) {
result.append(char)
}
}
return (result, result.reversed() == result)
}
```swift
// Task
// We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
// then check if the result string is palindrome.
// A string is called palindrome if it reads the same backward as forward.
// You should return a tuple containing the result string and true/false for the check.
// Example
// reverseDelete(s: "abcde", c: "ae") == ("bcd", false)
// reverseDelete(s: "abcdef", c: "b") == ("acdef", false)
// reverseDelete(s: "abcdedcba", c: "ab") == ("cdedc", true)
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var set = Set(c)
for char in s {
if!set.contains(char) {
result.append(char)
}
}
return (result, result.reversed() == result)
}
```
if!set.contains(char) { // expected expression, var, or let in 'if' condition
return (result, result.reversed() == result) // binary operator '==' cannot be applied to operands of type '[String.Element]' (aka 'Array<Character>') and 'String'
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var cSet = Set(c)
for char in s {
if!cSet.contains(char) {
result.append(char)
}
}
return (result, result == String(result.reversed()))
}
```swift
// Task
// We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
// then check if the result string is palindrome.
// A string is called palindrome if it reads the same backward as forward.
// You should return a tuple containing the result string and true/false for the check.
// Example
// reverseDelete(s: "abcde", c: "ae") == ("bcd", false)
// reverseDelete(s: "abcdef", c: "b") == ("acdef", false)
// reverseDelete(s: "abcdedcba", c: "ab") == ("cdedc", true)
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var cSet = Set(c)
for char in s {
if!cSet.contains(char) {
result.append(char)
}
}
return (result, result == String(result.reversed()))
}
```
if!cSet.contains(char) { // expected expression, var, or let in 'if' condition
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var isPalindrome = true
for char in s {
if!c.contains(char) {
result.append(char)
} else {
isPalindrome = false
}
}
return (result, isPalindrome)
}
```swift
// Task
// We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
// then check if the result string is palindrome.
// A string is called palindrome if it reads the same backward as forward.
// You should return a tuple containing the result string and true/false for the check.
// Example
// reverseDelete(s: "abcde", c: "ae") == ("bcd", false)
// reverseDelete(s: "abcdef", c: "b") == ("acdef", false)
// reverseDelete(s: "abcdedcba", c: "ab") == ("cdedc", true)
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var isPalindrome = true
for char in s {
if!c.contains(char) {
result.append(char)
} else {
isPalindrome = false
}
}
return (result, isPalindrome)
}
reverseDelete(s: "abcde", c: "ae")
reverseDelete(s: "abcdef", c: "b")
reverseDelete(s: "abcdedcba", c: "ab")
```
if!c.contains(char) { // expected expression, var, or let in 'if' condition
func oddCount(lst: [String]) -> [String] {
var result: [String] = []
for (index, item) in lst.enumerated() {
let count = item.filter { $0.isMultiple(of: 2) }.count
result.append("the number of odd elements \(count)n the str\(index)ng \(index) of the \(index)nput.")
}
return result
}
```swift
// Given an array of strings, where each string consists of only digits, return an array.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// oddCount(lst: ["1234567"]) == ["the number of odd elements 4n the str4ng 4 of the 4nput."]
// oddCount(lst: ["3", "11111111"]) == ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]
func oddCount(lst: [String]) -> [String] {
var result: [String] = []
for (index, item) in lst.enumerated() {
let count = item.filter { $0.isMultiple(of: 2) }.count
result.append("the number of odd elements \(count)n the str\(index)ng \(index) of the \(index)nput.")
}
return result
}
```
let count = item.filter { $0.isMultiple(of: 2) }.count // value of type 'String.Element' (aka 'Character') has no member 'isMultiple'
func oddCount(lst: [String]) -> [String] {
var result: [String] = []
for (index, item) in lst.enumerated() {
let count = item.filter { $0.isMultiple(of: 2) }.count
result.append("the number of odd elements \(count)n the str\(index)ng \(index) of the \(index)nput.")
}
return result
}
```swift
// Given an array of strings, where each string consists of only digits, return an array.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// oddCount(lst: ["1234567"]) == ["the number of odd elements 4n the str4ng 4 of the 4nput."]
// oddCount(lst: ["3", "11111111"]) == ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]
func oddCount(lst: [String]) -> [String] {
var result: [String] = []
for (index, item) in lst.enumerated() {
let count = item.filter { $0.isMultiple(of: 2) }.count
result.append("the number of odd elements \(count)n the str\(index)ng \(index) of the \(index)nput.")
}
return result
}
```
let count = item.filter { $0.isMultiple(of: 2) }.count // value of type 'String.Element' (aka 'Character') has no member 'isMultiple'
func oddCount(lst: [String]) -> [String] {
var result: [String] = []
for (index, str) in lst.enumerated() {
let count = str.filter { $0.isMultiple(of: 2) }.count
result.append("the number of odd elements \(count)n the str\(index)ng \(index) of the \(index)nput.")
}
return result
}
```swift
// Given an array of strings, where each string consists of only digits, return an array.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// oddCount(lst: ["1234567"]) == ["the number of odd elements 4n the str4ng 4 of the 4nput."]
// oddCount(lst: ["3", "11111111"]) == ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]
func oddCount(lst: [String]) -> [String] {
var result: [String] = []
for (index, str) in lst.enumerated() {
let count = str.filter { $0.isMultiple(of: 2) }.count
result.append("the number of odd elements \(count)n the str\(index)ng \(index) of the \(index)nput.")
}
return result
}
// oddCount(lst: ["1234567"])
// oddCount(lst: ["3", "11111111"])
```
let count = str.filter { $0.isMultiple(of: 2) }.count // value of type 'String.Element' (aka 'Character') has no member 'isMultiple'
func oddCount(lst: [String]) -> [String] {
var result: [String] = []
for (index, string) in lst.enumerated() {
let count = string.filter { $0.isMultiple(of: 2) }.count
result.append("the number of odd elements \(count)n the str\(index)ng \(index) of the \(index)nput.")
}
return result
}
```swift
// Given an array of strings, where each string consists of only digits, return an array.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// oddCount(lst: ["1234567"]) == ["the number of odd elements 4n the str4ng 4 of the 4nput."]
// oddCount(lst: ["3", "11111111"]) == ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]
func oddCount(lst: [String]) -> [String] {
var result: [String] = []
for (index, string) in lst.enumerated() {
let count = string.filter { $0.isMultiple(of: 2) }.count
result.append("the number of odd elements \(count)n the str\(index)ng \(index) of the \(index)nput.")
}
return result
}
```
let count = string.filter { $0.isMultiple(of: 2) }.count // value of type 'String.Element' (aka 'Character') has no member 'isMultiple'
func oddCount(lst: [String]) -> [String] {
var result: [String] = []
for (index, value) in lst.enumerated() {
let count = value.filter { $0.isMultiple(of: 2) }.count
result.append("the number of odd elements \(count)n the str\(index)ng \(index) of the \(index)nput.")
}
return result
}
```swift
// Given an array of strings, where each string consists of only digits, return an array.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// oddCount(lst: ["1234567"]) == ["the number of odd elements 4n the str4ng 4 of the 4nput."]
// oddCount(lst: ["3", "11111111"]) == ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]
func oddCount(lst: [String]) -> [String] {
var result: [String] = []
for (index, value) in lst.enumerated() {
let count = value.filter { $0.isMultiple(of: 2) }.count
result.append("the number of odd elements \(count)n the str\(index)ng \(index) of the \(index)nput.")
}
return result
}
```
let count = value.filter { $0.isMultiple(of: 2) }.count // value of type 'String.Element' (aka 'Character') has no member 'isMultiple'
func oddCount(lst: [String]) -> [String] {
return lst.map {
let count = $0.filter { $0.isMultiple(of: 2) }.count
return "the number of odd elements \(count)n the str\(count)ng \(count) of the \(count)nput."
}
}
```swift
// Given an array of strings, where each string consists of only digits, return an array.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// oddCount(lst: ["1234567"]) == ["the number of odd elements 4n the str4ng 4 of the 4nput."]
// oddCount(lst: ["3", "11111111"]) == ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]
func oddCount(lst: [String]) -> [String] {
return lst.map {
let count = $0.filter { $0.isMultiple(of: 2) }.count
return "the number of odd elements \(count)n the str\(count)ng \(count) of the \(count)nput."
}
}
```
let count = $0.filter { $0.isMultiple(of: 2) }.count // value of type 'String.Element' (aka 'Character') has no member 'isMultiple'
func oddCount(lst: [String]) -> [String] {
return lst.map {
let count = $0.filter { $0.isNumber }.count
return "the number of odd elements \(count)n the str\(count)ng \(count) of the \(count)nput."
}
}
```swift
// Given an array of strings, where each string consists of only digits, return an array.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// oddCount(lst: ["1234567"]) == ["the number of odd elements 4n the str4ng 4 of the 4nput."]
// oddCount(lst: ["3", "11111111"]) == ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]
func oddCount(lst: [String]) -> [String] {
return lst.map {
let count = $0.filter { $0.isNumber }.count
return "the number of odd elements \(count)n the str\(count)ng \(count) of the \(count)nput."
}
}
```
// XCTAssertTrue failed
func oddCount(lst: [String]) -> [String] {
var result = [String]()
for (index, string) in lst.enumerated() {
let count = string.filter { $0.isMultiple(of: 2) }.count
result.append("the number of odd elements \(count)n the str\(index)ng \(index) of the \(index)nput.")
}
return result
}
```swift
// Given an array of strings, where each string consists of only digits, return an array.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// oddCount(lst: ["1234567"]) == ["the number of odd elements 4n the str4ng 4 of the 4nput."]
// oddCount(lst: ["3", "11111111"]) == ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]
func oddCount(lst: [String]) -> [String] {
var result = [String]()
for (index, string) in lst.enumerated() {
let count = string.filter { $0.isMultiple(of: 2) }.count
result.append("the number of odd elements \(count)n the str\(index)ng \(index) of the \(index)nput.")
}
return result
}
```
let count = string.filter { $0.isMultiple(of: 2) }.count // value of type 'String.Element' (aka 'Character') has no member 'isMultiple'
func oddCount(lst: [String]) -> [String] {
var result: [String] = []
for (index, str) in lst.enumerated() {
var count = 0
for char in str {
if Int(String(char))! % 2 == 1 {
count += 1
}
}
result.append("the number of odd elements \(count)n the str\(index)ng \(index) of the \(index)nput.")
}
return result
}
```swift
// Given an array of strings, where each string consists of only digits, return an array.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// oddCount(lst: ["1234567"]) == ["the number of odd elements 4n the str4ng 4 of the 4nput."]
// oddCount(lst: ["3", "11111111"]) == ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]
func oddCount(lst: [String]) -> [String] {
var result: [String] = []
for (index, str) in lst.enumerated() {
var count = 0
for char in str {
if Int(String(char))! % 2 == 1 {
count += 1
}
}
result.append("the number of odd elements \(count)n the str\(index)ng \(index) of the \(index)nput.")
}
return result
}
```
// XCTAssertTrue failed
func oddCount(lst: [String]) -> [String] {
return lst.map { (str: String) -> String in
let count = str.filter { (char: Character) -> Bool in
return Int(String(char))! % 2 == 1
}.count
return "the number of odd elements \(count)n the str\(str)ng \(str.count) of the \(str.count)nput."
}
}
```swift
// Given an array of strings, where each string consists of only digits, return an array.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// oddCount(lst: ["1234567"]) == ["the number of odd elements 4n the str4ng 4 of the 4nput."]
// oddCount(lst: ["3", "11111111"]) == ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]
func oddCount(lst: [String]) -> [String] {
return lst.map { (str: String) -> String in
let count = str.filter { (char: Character) -> Bool in
return Int(String(char))! % 2 == 1
}.count
return "the number of odd elements \(count)n the str\(str)ng \(str.count) of the \(str.count)nput."
}
}
oddCount(lst: ["1234567"])
oddCount(lst: ["3", "11111111"])
```
// XCTAssertTrue failed
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var sum = 0
for num in nums {
sum += num
minSum = min(minSum, sum)
if sum < 0 {
sum = 0
}
}
return minSum
}
```swift
// Given an array of integers nums, find the minimum sum of any non-empty sub-array
// of nums.
// Example
// minSubArraySum(nums: [2, 3, 4, 1, 2, 4]) == 1
// minSubArraySum(nums: [-1, -2, -3]) == -6
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var sum = 0
for num in nums {
sum += num
minSum = min(minSum, sum)
if sum < 0 {
sum = 0
}
}
return minSum
}
```
// XCTAssertTrue failed
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var sum = 0
for num in nums {
sum += num
if sum < minSum {
minSum = sum
}
}
return minSum
}
```swift
// Given an array of integers nums, find the minimum sum of any non-empty sub-array
// of nums.
// Example
// minSubArraySum(nums: [2, 3, 4, 1, 2, 4]) == 1
// minSubArraySum(nums: [-1, -2, -3]) == -6
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var sum = 0
for num in nums {
sum += num
if sum < minSum {
minSum = sum
}
}
return minSum
}
```
// XCTAssertTrue failed
func minSubArraySum(nums: [Int]) -> Int {
var min = Int.max
var sum = 0
for num in nums {
sum += num
min = min < sum? min : sum
}
return min
}
```swift
// Given an array of integers nums, find the minimum sum of any non-empty sub-array
// of nums.
// Example
// minSubArraySum(nums: [2, 3, 4, 1, 2, 4]) == 1
// minSubArraySum(nums: [-1, -2, -3]) == -6
func minSubArraySum(nums: [Int]) -> Int {
var min = Int.max
var sum = 0
for num in nums {
sum += num
min = min < sum? min : sum
}
return min
}
```
min = min < sum? min : sum // consecutive statements on a line must be separated by ';'
min = min < sum? min : sum // expected expression
min = min < sum? min : sum // cannot use optional chaining on non-optional value of type 'Int'
min = min < sum? min : sum // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
min = min < sum? min : sum // consecutive statements on a line must be separated by ';'
min = min < sum? min : sum // cannot assign value of type 'Bool' to type 'Int'
min = min < sum? min : sum // variable is unused
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
for num in nums {
currentSum += num
if currentSum < minSum {
minSum = currentSum
}
}
return minSum
}
```swift
// Given an array of integers nums, find the minimum sum of any non-empty sub-array
// of nums.
// Example
// minSubArraySum(nums: [2, 3, 4, 1, 2, 4]) == 1
// minSubArraySum(nums: [-1, -2, -3]) == -6
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
for num in nums {
currentSum += num
if currentSum < minSum {
minSum = currentSum
}
}
return minSum
}
```
// XCTAssertTrue failed
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var sum = 0
for num in nums {
sum += num
if sum < minSum {
minSum = sum
}
}
return minSum
}
```swift
// Given an array of integers nums, find the minimum sum of any non-empty sub-array
// of nums.
// Example
// minSubArraySum(nums: [2, 3, 4, 1, 2, 4]) == 1
// minSubArraySum(nums: [-1, -2, -3]) == -6
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var sum = 0
for num in nums {
sum += num
if sum < minSum {
minSum = sum
}
}
return minSum
}
```
// XCTAssertTrue failed
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var sum = 0
for num in nums {
sum += num
minSum = min(minSum, sum)
if sum < 0 {
sum = 0
}
}
return minSum
}
```swift
// Given an array of integers nums, find the minimum sum of any non-empty sub-array
// of nums.
// Example
// minSubArraySum(nums: [2, 3, 4, 1, 2, 4]) == 1
// minSubArraySum(nums: [-1, -2, -3]) == -6
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var sum = 0
for num in nums {
sum += num
minSum = min(minSum, sum)
if sum < 0 {
sum = 0
}
}
return minSum
}
```
// XCTAssertTrue failed
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var sum = 0
for num in nums {
sum += num
if sum < minSum {
minSum = sum
}
}
return minSum
}
```swift
// Given an array of integers nums, find the minimum sum of any non-empty sub-array
// of nums.
// Example
// minSubArraySum(nums: [2, 3, 4, 1, 2, 4]) == 1
// minSubArraySum(nums: [-1, -2, -3]) == -6
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var sum = 0
for num in nums {
sum += num
if sum < minSum {
minSum = sum
}
}
return minSum
}
```
// XCTAssertTrue failed
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var sum = 0
for num in nums {
sum += num
if sum < minSum {
minSum = sum
}
}
return minSum
}
```swift
// Given an array of integers nums, find the minimum sum of any non-empty sub-array
// of nums.
// Example
// minSubArraySum(nums: [2, 3, 4, 1, 2, 4]) == 1
// minSubArraySum(nums: [-1, -2, -3]) == -6
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var sum = 0
for num in nums {
sum += num
if sum < minSum {
minSum = sum
}
}
return minSum
}
```
// XCTAssertTrue failed
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var sum = 0
for num in nums {
sum += num
if sum < minSum {
minSum = sum
}
}
return minSum
}
```swift
// Given an array of integers nums, find the minimum sum of any non-empty sub-array
// of nums.
// Example
// minSubArraySum(nums: [2, 3, 4, 1, 2, 4]) == 1
// minSubArraySum(nums: [-1, -2, -3]) == -6
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var sum = 0
for num in nums {
sum += num
if sum < minSum {
minSum = sum
}
}
return minSum
}
```
// XCTAssertTrue failed
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
for num in nums {
currentSum += num
minSum = min(minSum, currentSum)
if currentSum < 0 {
currentSum = 0
}
}
return minSum
}
```swift
// Given an array of integers nums, find the minimum sum of any non-empty sub-array
// of nums.
// Example
// minSubArraySum(nums: [2, 3, 4, 1, 2, 4]) == 1
// minSubArraySum(nums: [-1, -2, -3]) == -6
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
for num in nums {
currentSum += num
minSum = min(minSum, currentSum)
if currentSum < 0 {
currentSum = 0
}
}
return minSum
}
```
// XCTAssertTrue failed
func maxFill(grid: [[Int]], capacity: Int) -> Int {
// Write your code here
}
```swift
// You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// Example 2:
// Example 3:
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
// maxFill(grid: [[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], capacity: 1) == 6
// maxFill(grid: [[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], capacity: 2) == 5
// maxFill(grid: [[0, 0, 0], [0, 0, 0]], capacity: 5) == 0
func maxFill(grid: [[Int]], capacity: Int) -> Int {
// Write your code here
}
```
} // missing return in global function expected to return 'Int'
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var count = 0
var capacity = capacity
var grid = grid
while!grid.isEmpty {
var row = grid.removeFirst()
var i = 0
while i < row.count {
if row[i] == 1 {
if capacity > 0 {
row[i] = 0
capacity -= 1
} else {
break
}
}
i += 1
}
if!row.isEmpty {
grid.append(row)
}
count += 1
}
return count
}
```swift
// You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// Example 2:
// Example 3:
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
// maxFill(grid: [[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], capacity: 1) == 6
// maxFill(grid: [[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], capacity: 2) == 5
// maxFill(grid: [[0, 0, 0], [0, 0, 0]], capacity: 5) == 0
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var count = 0
var capacity = capacity
var grid = grid
while!grid.isEmpty {
var row = grid.removeFirst()
var i = 0
while i < row.count {
if row[i] == 1 {
if capacity > 0 {
row[i] = 0
capacity -= 1
} else {
break
}
}
i += 1
}
if!row.isEmpty {
grid.append(row)
}
count += 1
}
return count
}
```
while!grid.isEmpty { // expected expression, var, or let in 'while' condition
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var count = 0
var grid = grid
while!grid.isEmpty {
var row = grid.removeFirst()
var capacity = capacity
while!row.isEmpty {
if row.first == 1 {
row.removeFirst()
capacity -= 1
} else {
break
}
}
if capacity < 0 {
count += 1
capacity = capacity + 1
}
}
return count
}
```swift
// You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// Example 2:
// Example 3:
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
// maxFill(grid: [[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], capacity: 1) == 6
// maxFill(grid: [[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], capacity: 2) == 5
// maxFill(grid: [[0, 0, 0], [0, 0, 0]], capacity: 5) == 0
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var count = 0
var grid = grid
while!grid.isEmpty {
var row = grid.removeFirst()
var capacity = capacity
while!row.isEmpty {
if row.first == 1 {
row.removeFirst()
capacity -= 1
} else {
break
}
}
if capacity < 0 {
count += 1
capacity = capacity + 1
}
}
return count
}
```
while!grid.isEmpty { // expected expression, var, or let in 'while' condition
func maxFill(grid: [[Int]], capacity: Int) -> Int {
// Write your code here.
}
```swift
// You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// Example 2:
// Example 3:
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
// maxFill(grid: [[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], capacity: 1) == 6
// maxFill(grid: [[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], capacity: 2) == 5
// maxFill(grid: [[0, 0, 0], [0, 0, 0]], capacity: 5) == 0
func maxFill(grid: [[Int]], capacity: Int) -> Int {
// Write your code here.
}
```
} // missing return in global function expected to return 'Int'
func maxFill(grid: [[Int]], capacity: Int) -> Int {
// Write your code here
}
```swift
// You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// Example 2:
// Example 3:
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
// maxFill(grid: [[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], capacity: 1) == 6
// maxFill(grid: [[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], capacity: 2) == 5
// maxFill(grid: [[0, 0, 0], [0, 0, 0]], capacity: 5) == 0
func maxFill(grid: [[Int]], capacity: Int) -> Int {
// Write your code here
}
```
} // missing return in global function expected to return 'Int'
func maxFill(grid: [[Int]], capacity: Int) -> Int {
// Write your code here
}
```swift
// You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// Example 2:
// Example 3:
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
// maxFill(grid: [[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], capacity: 1) == 6
// maxFill(grid: [[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], capacity: 2) == 5
// maxFill(grid: [[0, 0, 0], [0, 0, 0]], capacity: 5) == 0
func maxFill(grid: [[Int]], capacity: Int) -> Int {
// Write your code here
}
```
} // missing return in global function expected to return 'Int'
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var result = 0
var grid = grid
var capacity = capacity
while!grid.isEmpty {
var row = grid.removeFirst()
var capacity = capacity
while!row.isEmpty {
if row.removeFirst() == 1 {
capacity -= 1
}
}
if capacity < 0 {
result += 1
capacity = capacity
}
}
return result
}
```swift
// You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// Example 2:
// Example 3:
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
// maxFill(grid: [[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], capacity: 1) == 6
// maxFill(grid: [[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], capacity: 2) == 5
// maxFill(grid: [[0, 0, 0], [0, 0, 0]], capacity: 5) == 0
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var result = 0
var grid = grid
var capacity = capacity
while!grid.isEmpty {
var row = grid.removeFirst()
var capacity = capacity
while!row.isEmpty {
if row.removeFirst() == 1 {
capacity -= 1
}
}
if capacity < 0 {
result += 1
capacity = capacity
}
}
return result
}
```
while!grid.isEmpty { // expected expression, var, or let in 'while' condition
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var count = 0
var capacity = capacity
var grid = grid
while capacity > 0 {
for i in 0..<grid.count {
for j in 0..<grid[i].count {
if grid[i][j] == 1 {
grid[i][j] = 0
capacity -= 1
if capacity == 0 {
return count
}
}
}
}
count += 1
}
return count
}
```swift
// You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// Example 2:
// Example 3:
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
// maxFill(grid: [[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], capacity: 1) == 6
// maxFill(grid: [[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], capacity: 2) == 5
// maxFill(grid: [[0, 0, 0], [0, 0, 0]], capacity: 5) == 0
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var count = 0
var capacity = capacity
var grid = grid
while capacity > 0 {
for i in 0..<grid.count {
for j in 0..<grid[i].count {
if grid[i][j] == 1 {
grid[i][j] = 0
capacity -= 1
if capacity == 0 {
return count
}
}
}
}
count += 1
}
return count
}
```
// XCTAssertTrue failed
func maxFill(grid: [[Int]], capacity: Int) -> Int {
// Write your code here
}
```swift
// You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// Example 2:
// Example 3:
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
// maxFill(grid: [[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], capacity: 1) == 6
// maxFill(grid: [[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], capacity: 2) == 5
// maxFill(grid: [[0, 0, 0], [0, 0, 0]], capacity: 5) == 0
func maxFill(grid: [[Int]], capacity: Int) -> Int {
// Write your code here
}
```
} // missing return in global function expected to return 'Int'
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var count = 0
var capacity = capacity
var grid = grid
while!grid.isEmpty {
var row = grid.removeFirst()
var rowCapacity = capacity
while!row.isEmpty {
if row.removeFirst() == 1 {
rowCapacity -= 1
}
}
if rowCapacity > 0 {
count += 1
capacity = rowCapacity
}
}
return count
}
```swift
// You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// Example 2:
// Example 3:
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
// maxFill(grid: [[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], capacity: 1) == 6
// maxFill(grid: [[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], capacity: 2) == 5
// maxFill(grid: [[0, 0, 0], [0, 0, 0]], capacity: 5) == 0
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var count = 0
var capacity = capacity
var grid = grid
while!grid.isEmpty {
var row = grid.removeFirst()
var rowCapacity = capacity
while!row.isEmpty {
if row.removeFirst() == 1 {
rowCapacity -= 1
}
}
if rowCapacity > 0 {
count += 1
capacity = rowCapacity
}
}
return count
}
```
while!grid.isEmpty { // expected expression, var, or let in 'while' condition
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted { (lhs, rhs) -> Bool in
let lhsOnes = String(lhs, radix: 2).filter { $0 == "1" }.count
let rhsOnes = String(rhs, radix: 2).filter { $0 == "1" }.count
if lhsOnes!= rhsOnes {
return lhsOnes < rhsOnes
} else {
return lhs < rhs
}
}
}
```swift
// In this Kata, you have to sort an array of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// sortArray(arr: [1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]
// sortArray(arr: [-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]
// sortArray(arr: [1, 0, 2, 3, 4]) == [0, 1, 2, 3, 4]
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted { (lhs, rhs) -> Bool in
let lhsOnes = String(lhs, radix: 2).filter { $0 == "1" }.count
let rhsOnes = String(rhs, radix: 2).filter { $0 == "1" }.count
if lhsOnes!= rhsOnes {
return lhsOnes < rhsOnes
} else {
return lhs < rhs
}
}
}
```
if lhsOnes!= rhsOnes { // '=' must have consistent whitespace on both sides
if lhsOnes!= rhsOnes { // use of '=' in a boolean context, did you mean '=='?
if lhsOnes!= rhsOnes { // cannot force unwrap value of non-optional type 'Int'
func sortArray(arr: [Int]) -> [Int] {
// your code here
return []
}
```swift
// In this Kata, you have to sort an array of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// sortArray(arr: [1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]
// sortArray(arr: [-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]
// sortArray(arr: [1, 0, 2, 3, 4]) == [0, 1, 2, 3, 4]
func sortArray(arr: [Int]) -> [Int] {
// your code here
return []
}
```
// XCTAssertTrue failed
func sortArray(arr: [Int]) -> [Int] {
let sorted = arr.sorted { (lhs, rhs) -> Bool in
let lhsCount = String(lhs, radix: 2).components(separatedBy: "1").count
let rhsCount = String(rhs, radix: 2).components(separatedBy: "1").count
if lhsCount == rhsCount {
return lhs < rhs
}
return lhsCount < rhsCount
}
return sorted
}
```swift
// In this Kata, you have to sort an array of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// sortArray(arr: [1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]
// sortArray(arr: [-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]
// sortArray(arr: [1, 0, 2, 3, 4]) == [0, 1, 2, 3, 4]
func sortArray(arr: [Int]) -> [Int] {
let sorted = arr.sorted { (lhs, rhs) -> Bool in
let lhsCount = String(lhs, radix: 2).components(separatedBy: "1").count
let rhsCount = String(rhs, radix: 2).components(separatedBy: "1").count
if lhsCount == rhsCount {
return lhs < rhs
}
return lhsCount < rhsCount
}
return sorted
}
```
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = String($0, radix: 2).components(separatedBy: "1").count
let b = String($1, radix: 2).components(separatedBy: "1").count
return a == b? $0 < $1 : a < b
}
}
```swift
// In this Kata, you have to sort an array of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// sortArray(arr: [1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]
// sortArray(arr: [-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]
// sortArray(arr: [1, 0, 2, 3, 4]) == [0, 1, 2, 3, 4]
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = String($0, radix: 2).components(separatedBy: "1").count
let b = String($1, radix: 2).components(separatedBy: "1").count
return a == b? $0 < $1 : a < b
}
}
```
return a == b? $0 < $1 : a < b // cannot use optional chaining on non-optional value of type 'Int'
return a == b? $0 < $1 : a < b // consecutive statements on a line must be separated by ';'
return a == b? $0 < $1 : a < b // expected expression
return a == b? $0 < $1 : a < b // consecutive statements on a line must be separated by ';'
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = String($0, radix: 2).components(separatedBy: "1").count
let b = String($1, radix: 2).components(separatedBy: "1").count
if a == b {
return $0 < $1
} else {
return a < b
}
}
}
```swift
// In this Kata, you have to sort an array of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// sortArray(arr: [1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]
// sortArray(arr: [-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]
// sortArray(arr: [1, 0, 2, 3, 4]) == [0, 1, 2, 3, 4]
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = String($0, radix: 2).components(separatedBy: "1").count
let b = String($1, radix: 2).components(separatedBy: "1").count
if a == b {
return $0 < $1
} else {
return a < b
}
}
}
```
func sortArray(arr: [Int]) -> [Int] {
// your code here
return []
}
```swift
// In this Kata, you have to sort an array of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// sortArray(arr: [1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]
// sortArray(arr: [-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]
// sortArray(arr: [1, 0, 2, 3, 4]) == [0, 1, 2, 3, 4]
func sortArray(arr: [Int]) -> [Int] {
// your code here
return []
}
```
// XCTAssertTrue failed
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let (a, b) = ($0, $1)
let aOnes = a.nonzeroBitCount
let bOnes = b.nonzeroBitCount
if aOnes == bOnes {
return a < b
}
return aOnes < bOnes
}
}
```swift
// In this Kata, you have to sort an array of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// sortArray(arr: [1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]
// sortArray(arr: [-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]
// sortArray(arr: [1, 0, 2, 3, 4]) == [0, 1, 2, 3, 4]
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let (a, b) = ($0, $1)
let aOnes = a.nonzeroBitCount
let bOnes = b.nonzeroBitCount
if aOnes == bOnes {
return a < b
}
return aOnes < bOnes
}
}
```
// XCTAssertTrue failed
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = String($0, radix: 2).components(separatedBy: "1").count
let b = String($1, radix: 2).components(separatedBy: "1").count
return a < b || (a == b && $0 < $1)
}
}
```swift
// In this Kata, you have to sort an array of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// sortArray(arr: [1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]
// sortArray(arr: [-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]
// sortArray(arr: [1, 0, 2, 3, 4]) == [0, 1, 2, 3, 4]
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = String($0, radix: 2).components(separatedBy: "1").count
let b = String($1, radix: 2).components(separatedBy: "1").count
return a < b || (a == b && $0 < $1)
}
}
```
func sortArray(arr: [Int]) -> [Int] {
let sorted = arr.sorted { (a, b) -> Bool in
let aBinary = String(a, radix: 2)
let bBinary = String(b, radix: 2)
let aOnes = aBinary.filter { $0 == "1" }.count
let bOnes = bBinary.filter { $0 == "1" }.count
if aOnes == bOnes {
return a < b
} else {
return aOnes < bOnes
}
}
return sorted
}
```swift
// In this Kata, you have to sort an array of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// sortArray(arr: [1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]
// sortArray(arr: [-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]
// sortArray(arr: [1, 0, 2, 3, 4]) == [0, 1, 2, 3, 4]
func sortArray(arr: [Int]) -> [Int] {
let sorted = arr.sorted { (a, b) -> Bool in
let aBinary = String(a, radix: 2)
let bBinary = String(b, radix: 2)
let aOnes = aBinary.filter { $0 == "1" }.count
let bOnes = bBinary.filter { $0 == "1" }.count
if aOnes == bOnes {
return a < b
} else {
return aOnes < bOnes
}
}
return sorted
}
```
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = $0.countSetBits()
let b = $1.countSetBits()
if a == b {
return $0 < $1
} else {
return a < b
}
}
}
extension Int {
func countSetBits() -> Int {
var count = 0
var n = self
while n > 0 {
if n & 1 == 1 {
count += 1
}
n >>= 1
}
return count
}
}
```swift
// In this Kata, you have to sort an array of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// sortArray(arr: [1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]
// sortArray(arr: [-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]
// sortArray(arr: [1, 0, 2, 3, 4]) == [0, 1, 2, 3, 4]
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = $0.countSetBits()
let b = $1.countSetBits()
if a == b {
return $0 < $1
} else {
return a < b
}
}
}
extension Int {
func countSetBits() -> Int {
var count = 0
var n = self
while n > 0 {
if n & 1 == 1 {
count += 1
}
n >>= 1
}
return count
}
}
```
// XCTAssertTrue failed
func selectWords(s: String, n: Int) -> [String] {
let vowels = "aeiou"
let words = s.components(separatedBy: " ")
var result = [String]()
for word in words {
var consonants = 0
for char in word {
if!vowels.contains(char) {
consonants += 1
}
}
if consonants == n {
result.append(word)
}
}
return result
}
```swift
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array of all words from string s that contain exactly
// n consonants, in order these words appear in the string s.
// If the string s is empty then the function should return an empty array.
// Note: you may assume the input string contains only letters and spaces.
// Examples:
// selectWords(s: "Mary had a little lamb", n: 4) == ["little"]
// selectWords(s: "Mary had a little lamb", n: 3) == ["Mary", "lamb"]
// selectWords(s: "simple white space", n: 2) == [] as [String]
// selectWords(s: "Hello world", n: 4) == ["world"]
// selectWords(s: "Uncle sam", n: 3) == ["Uncle"]
func selectWords(s: String, n: Int) -> [String] {
let vowels = "aeiou"
let words = s.components(separatedBy: " ")
var result = [String]()
for word in words {
var consonants = 0
for char in word {
if!vowels.contains(char) {
consonants += 1
}
}
if consonants == n {
result.append(word)
}
}
return result
}
```
if!vowels.contains(char) { // expected expression, var, or let in 'if' condition
func selectWords(s: String, n: Int) -> [String] {
var result: [String] = []
let words = s.components(separatedBy: " ")
for word in words {
if word.filter({ $0.isVowel() }).count == n {
result.append(word)
}
}
return result
}
```swift
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array of all words from string s that contain exactly
// n consonants, in order these words appear in the string s.
// If the string s is empty then the function should return an empty array.
// Note: you may assume the input string contains only letters and spaces.
// Examples:
// selectWords(s: "Mary had a little lamb", n: 4) == ["little"]
// selectWords(s: "Mary had a little lamb", n: 3) == ["Mary", "lamb"]
// selectWords(s: "simple white space", n: 2) == [] as [String]
// selectWords(s: "Hello world", n: 4) == ["world"]
// selectWords(s: "Uncle sam", n: 3) == ["Uncle"]
func selectWords(s: String, n: Int) -> [String] {
var result: [String] = []
let words = s.components(separatedBy: " ")
for word in words {
if word.filter({ $0.isVowel() }).count == n {
result.append(word)
}
}
return result
}
```
if word.filter({ $0.isVowel() }).count == n { // value of type 'String.Element' (aka 'Character') has no member 'isVowel'
func selectWords(s: String, n: Int) -> [String] {
let vowels = ["a", "e", "i", "o", "u"]
var words = [String]()
let wordsArray = s.components(separatedBy: " ")
for word in wordsArray {
var consonants = 0
for letter in word {
if!vowels.contains(String(letter)) {
consonants += 1
}
}
if consonants == n {
words.append(word)
}
}
return words
}
```swift
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array of all words from string s that contain exactly
// n consonants, in order these words appear in the string s.
// If the string s is empty then the function should return an empty array.
// Note: you may assume the input string contains only letters and spaces.
// Examples:
// selectWords(s: "Mary had a little lamb", n: 4) == ["little"]
// selectWords(s: "Mary had a little lamb", n: 3) == ["Mary", "lamb"]
// selectWords(s: "simple white space", n: 2) == [] as [String]
// selectWords(s: "Hello world", n: 4) == ["world"]
// selectWords(s: "Uncle sam", n: 3) == ["Uncle"]
func selectWords(s: String, n: Int) -> [String] {
let vowels = ["a", "e", "i", "o", "u"]
var words = [String]()
let wordsArray = s.components(separatedBy: " ")
for word in wordsArray {
var consonants = 0
for letter in word {
if!vowels.contains(String(letter)) {
consonants += 1
}
}
if consonants == n {
words.append(word)
}
}
return words
}
```
if!vowels.contains(String(letter)) { // expected expression, var, or let in 'if' condition
func selectWords(s: String, n: Int) -> [String] {
let vowels = "aeiou"
var words = [String]()
var word = ""
for char in s {
if vowels.contains(char) {
word = ""
} else {
word.append(char)
}
if word.count == n {
words.append(word)
}
}
return words
}
```swift
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array of all words from string s that contain exactly
// n consonants, in order these words appear in the string s.
// If the string s is empty then the function should return an empty array.
// Note: you may assume the input string contains only letters and spaces.
// Examples:
// selectWords(s: "Mary had a little lamb", n: 4) == ["little"]
// selectWords(s: "Mary had a little lamb", n: 3) == ["Mary", "lamb"]
// selectWords(s: "simple white space", n: 2) == [] as [String]
// selectWords(s: "Hello world", n: 4) == ["world"]
// selectWords(s: "Uncle sam", n: 3) == ["Uncle"]
func selectWords(s: String, n: Int) -> [String] {
let vowels = "aeiou"
var words = [String]()
var word = ""
for char in s {
if vowels.contains(char) {
word = ""
} else {
word.append(char)
}
if word.count == n {
words.append(word)
}
}
return words
}
```
// XCTAssertTrue failed
func selectWords(s: String, n: Int) -> [String] {
// your code here
}
```swift
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array of all words from string s that contain exactly
// n consonants, in order these words appear in the string s.
// If the string s is empty then the function should return an empty array.
// Note: you may assume the input string contains only letters and spaces.
// Examples:
// selectWords(s: "Mary had a little lamb", n: 4) == ["little"]
// selectWords(s: "Mary had a little lamb", n: 3) == ["Mary", "lamb"]
// selectWords(s: "simple white space", n: 2) == [] as [String]
// selectWords(s: "Hello world", n: 4) == ["world"]
// selectWords(s: "Uncle sam", n: 3) == ["Uncle"]
func selectWords(s: String, n: Int) -> [String] {
// your code here
}
```
} // missing return in global function expected to return '[String]'
func selectWords(s: String, n: Int) -> [String] {
var result = [String]()
let words = s.components(separatedBy: " ")
for word in words {
var consonants = 0
for char in word {
if char.isLetter &&!char.isVowel() {
consonants += 1
}
}
if consonants == n {
result.append(word)
}
}
return result
}
```swift
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array of all words from string s that contain exactly
// n consonants, in order these words appear in the string s.
// If the string s is empty then the function should return an empty array.
// Note: you may assume the input string contains only letters and spaces.
// Examples:
// selectWords(s: "Mary had a little lamb", n: 4) == ["little"]
// selectWords(s: "Mary had a little lamb", n: 3) == ["Mary", "lamb"]
// selectWords(s: "simple white space", n: 2) == [] as [String]
// selectWords(s: "Hello world", n: 4) == ["world"]
// selectWords(s: "Uncle sam", n: 3) == ["Uncle"]
func selectWords(s: String, n: Int) -> [String] {
var result = [String]()
let words = s.components(separatedBy: " ")
for word in words {
var consonants = 0
for char in word {
if char.isLetter &&!char.isVowel() {
consonants += 1
}
}
if consonants == n {
result.append(word)
}
}
return result
}
```
if char.isLetter &&!char.isVowel() { // expected '{' after 'if' condition
func selectWords(s: String, n: Int) -> [String] {
let vowels = "aeiou"
let words = s.components(separatedBy: " ")
var result = [String]()
for word in words {
var consonants = 0
for char in word {
if!vowels.contains(char) {
consonants += 1
}
}
if consonants == n {
result.append(word)
}
}
return result
}
```swift
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array of all words from string s that contain exactly
// n consonants, in order these words appear in the string s.
// If the string s is empty then the function should return an empty array.
// Note: you may assume the input string contains only letters and spaces.
// Examples:
// selectWords(s: "Mary had a little lamb", n: 4) == ["little"]
// selectWords(s: "Mary had a little lamb", n: 3) == ["Mary", "lamb"]
// selectWords(s: "simple white space", n: 2) == [] as [String]
// selectWords(s: "Hello world", n: 4) == ["world"]
// selectWords(s: "Uncle sam", n: 3) == ["Uncle"]
func selectWords(s: String, n: Int) -> [String] {
let vowels = "aeiou"
let words = s.components(separatedBy: " ")
var result = [String]()
for word in words {
var consonants = 0
for char in word {
if!vowels.contains(char) {
consonants += 1
}
}
if consonants == n {
result.append(word)
}
}
return result
}
```
if!vowels.contains(char) { // expected expression, var, or let in 'if' condition
func selectWords(s: String, n: Int) -> [String] {
var result = [String]()
let words = s.components(separatedBy: " ")
for word in words {
if word.filter({ $0.isVowel }).count == n {
result.append(word)
}
}
return result
}
```swift
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array of all words from string s that contain exactly
// n consonants, in order these words appear in the string s.
// If the string s is empty then the function should return an empty array.
// Note: you may assume the input string contains only letters and spaces.
// Examples:
// selectWords(s: "Mary had a little lamb", n: 4) == ["little"]
// selectWords(s: "Mary had a little lamb", n: 3) == ["Mary", "lamb"]
// selectWords(s: "simple white space", n: 2) == [] as [String]
// selectWords(s: "Hello world", n: 4) == ["world"]
// selectWords(s: "Uncle sam", n: 3) == ["Uncle"]
func selectWords(s: String, n: Int) -> [String] {
var result = [String]()
let words = s.components(separatedBy: " ")
for word in words {
if word.filter({ $0.isVowel }).count == n {
result.append(word)
}
}
return result
}
```
if word.filter({ $0.isVowel }).count == n { // value of type 'String.Element' (aka 'Character') has no member 'isVowel'
func selectWords(s: String, n: Int) -> [String] {
let vowels = "aeiou"
let consonants = "bcdfghjklmnpqrstvwxyz"
let words = s.components(separatedBy: " ")
var result = [String]()
for word in words {
var consonantCount = 0
var vowelCount = 0
for char in word {
if consonants.contains(char) {
consonantCount += 1
}
if vowels.contains(char) {
vowelCount += 1
}
}
if consonantCount == n {
result.append(word)
}
}
return result
}
```swift
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array of all words from string s that contain exactly
// n consonants, in order these words appear in the string s.
// If the string s is empty then the function should return an empty array.
// Note: you may assume the input string contains only letters and spaces.
// Examples:
// selectWords(s: "Mary had a little lamb", n: 4) == ["little"]
// selectWords(s: "Mary had a little lamb", n: 3) == ["Mary", "lamb"]
// selectWords(s: "simple white space", n: 2) == [] as [String]
// selectWords(s: "Hello world", n: 4) == ["world"]
// selectWords(s: "Uncle sam", n: 3) == ["Uncle"]
func selectWords(s: String, n: Int) -> [String] {
let vowels = "aeiou"
let consonants = "bcdfghjklmnpqrstvwxyz"
let words = s.components(separatedBy: " ")
var result = [String]()
for word in words {
var consonantCount = 0
var vowelCount = 0
for char in word {
if consonants.contains(char) {
consonantCount += 1
}
if vowels.contains(char) {
vowelCount += 1
}
}
if consonantCount == n {
result.append(word)
}
}
return result
}
```
// XCTAssertTrue failed
func selectWords(s: String, n: Int) -> [String] {
let vowels = "aeiou"
let words = s.components(separatedBy: " ")
let consonants = words.filter { word in
word.filter {!vowels.contains($0) }.count == n
}
return consonants
}
```swift
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array of all words from string s that contain exactly
// n consonants, in order these words appear in the string s.
// If the string s is empty then the function should return an empty array.
// Note: you may assume the input string contains only letters and spaces.
// Examples:
// selectWords(s: "Mary had a little lamb", n: 4) == ["little"]
// selectWords(s: "Mary had a little lamb", n: 3) == ["Mary", "lamb"]
// selectWords(s: "simple white space", n: 2) == [] as [String]
// selectWords(s: "Hello world", n: 4) == ["world"]
// selectWords(s: "Uncle sam", n: 3) == ["Uncle"]
func selectWords(s: String, n: Int) -> [String] {
let vowels = "aeiou"
let words = s.components(separatedBy: " ")
let consonants = words.filter { word in
word.filter {!vowels.contains($0) }.count == n
}
return consonants
}
```
// XCTAssertTrue failed
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u"]
var closestVowel: String?
for (index, letter) in word.reversed().enumerated() {
if vowels.contains(String(letter)) {
closestVowel = String(letter)
break
}
}
return closestVowel?? ""
}
```swift
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// getClosestVowel(word: "yogurt") == "u"
// getClosestVowel(word: "FULL") == "U"
// getClosestVowel(word: "quick") == ""
// getClosestVowel(word: "ab") == ""
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u"]
var closestVowel: String?
for (index, letter) in word.reversed().enumerated() {
if vowels.contains(String(letter)) {
closestVowel = String(letter)
break
}
}
return closestVowel?? ""
}
```
return closestVowel?? "" // consecutive statements on a line must be separated by ';'
return closestVowel?? "" // cannot use optional chaining on non-optional value of type 'String'
return closestVowel?? "" // string literal is unused
func getClosestVowel(word: String) -> String {
let vowels = "aeiou"
var closestVowel: String = ""
var closestVowelIndex: Int = 0
var closestVowelDistance: Int = 0
for (index, char) in word.enumerated() {
if vowels.contains(char) {
let distance = word.distance(from: index, to: word.endIndex)
if closestVowelDistance == 0 || distance < closestVowelDistance {
closestVowel = String(char)
closestVowelDistance = distance
closestVowelIndex = index
}
}
}
if closestVowelDistance == 0 {
return ""
}
return closestVowel
}
```swift
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// getClosestVowel(word: "yogurt") == "u"
// getClosestVowel(word: "FULL") == "U"
// getClosestVowel(word: "quick") == ""
// getClosestVowel(word: "ab") == ""
func getClosestVowel(word: String) -> String {
let vowels = "aeiou"
var closestVowel: String = ""
var closestVowelIndex: Int = 0
var closestVowelDistance: Int = 0
for (index, char) in word.enumerated() {
if vowels.contains(char) {
let distance = word.distance(from: index, to: word.endIndex)
if closestVowelDistance == 0 || distance < closestVowelDistance {
closestVowel = String(char)
closestVowelDistance = distance
closestVowelIndex = index
}
}
}
if closestVowelDistance == 0 {
return ""
}
return closestVowel
}
```
let distance = word.distance(from: index, to: word.endIndex) // cannot convert value of type 'Int' to expected argument type 'String.Index'
func getClosestVowel(word: String) -> String {
var vowels = ["a", "e", "i", "o", "u"]
var result = ""
var index = 0
for char in word.characters {
if vowels.contains(String(char)) {
result = String(char)
break
}
index += 1
}
if result == "" {
return ""
}
var i = index
while i >= 0 {
if vowels.contains(String(word[word.index(word.startIndex, offsetBy: i)])) {
return String(word[word.index(word.startIndex, offsetBy: i)])
}
i -= 1
}
return ""
}
```swift
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// getClosestVowel(word: "yogurt") == "u"
// getClosestVowel(word: "FULL") == "U"
// getClosestVowel(word: "quick") == ""
// getClosestVowel(word: "ab") == ""
func getClosestVowel(word: String) -> String {
var vowels = ["a", "e", "i", "o", "u"]
var result = ""
var index = 0
for char in word.characters {
if vowels.contains(String(char)) {
result = String(char)
break
}
index += 1
}
if result == "" {
return ""
}
var i = index
while i >= 0 {
if vowels.contains(String(word[word.index(word.startIndex, offsetBy: i)])) {
return String(word[word.index(word.startIndex, offsetBy: i)])
}
i -= 1
}
return ""
}
```
var vowels = ["a", "e", "i", "o", "u"] // variable 'vowels' was never mutated; consider changing to 'let' constant
for char in word.characters { // 'characters' is unavailable: Please use String directly
func getClosestVowel(word: String) -> String {
let vowels: [Character] = ["a", "e", "i", "o", "u"]
var closestVowel: Character?
var closestDistance = Int.max
for (index, character) in word.enumerated() {
if vowels.contains(character) {
let distance = word.distance(from: index, to: word.endIndex)
if distance < closestDistance {
closestDistance = distance
closestVowel = character
}
}
}
return String(closestVowel?? "")
}
```swift
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// getClosestVowel(word: "yogurt") == "u"
// getClosestVowel(word: "FULL") == "U"
// getClosestVowel(word: "quick") == ""
// getClosestVowel(word: "ab") == ""
func getClosestVowel(word: String) -> String {
let vowels: [Character] = ["a", "e", "i", "o", "u"]
var closestVowel: Character?
var closestDistance = Int.max
for (index, character) in word.enumerated() {
if vowels.contains(character) {
let distance = word.distance(from: index, to: word.endIndex)
if distance < closestDistance {
closestDistance = distance
closestVowel = character
}
}
}
return String(closestVowel?? "")
}
```
let distance = word.distance(from: index, to: word.endIndex) // cannot convert value of type 'Int' to expected argument type 'String.Index'
return String(closestVowel?? "") // expected ',' separator
return String(closestVowel?? "") // initializer 'init(bytes:encoding:)' requires that 'Character?' conform to 'Sequence'
return String(closestVowel?? "") // cannot use optional chaining on non-optional value of type 'Character'
return String(closestVowel?? "") // value of optional type 'String?' must be unwrapped to a value of type 'String'
return String(closestVowel?? "") // missing argument labels 'bytes:encoding:' in call
return String(closestVowel?? "") // cannot convert value of type 'String' to expected argument type 'String.Encoding'
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u"]
let word = word.lowercased()
var closestVowel = ""
var closestVowelDistance = Int.max
for (index, letter) in word.enumerated() {
if vowels.contains(String(letter)) {
let distance = word.distance(from: index, to: word.endIndex)
if distance < closestVowelDistance {
closestVowel = String(letter)
closestVowelDistance = distance
}
}
}
return closestVowel
}
```swift
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// getClosestVowel(word: "yogurt") == "u"
// getClosestVowel(word: "FULL") == "U"
// getClosestVowel(word: "quick") == ""
// getClosestVowel(word: "ab") == ""
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u"]
let word = word.lowercased()
var closestVowel = ""
var closestVowelDistance = Int.max
for (index, letter) in word.enumerated() {
if vowels.contains(String(letter)) {
let distance = word.distance(from: index, to: word.endIndex)
if distance < closestVowelDistance {
closestVowel = String(letter)
closestVowelDistance = distance
}
}
}
return closestVowel
}
```
let distance = word.distance(from: index, to: word.endIndex) // cannot convert value of type 'Int' to expected argument type 'String.Index'
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u"]
var closestVowel = ""
var closestVowelIndex = 0
var closestVowelDistance = 0
var vowelIndex = 0
var vowelDistance = 0
var consonantIndex = 0
var consonantDistance = 0
var consonant = ""
var vowel = ""
for letter in word {
if vowels.contains(String(letter)) {
vowel = String(letter)
vowelIndex = word.distance(of: vowel)
vowelDistance = word.distance(of: closestVowel)
if vowelIndex > closestVowelIndex {
closestVowel = vowel
closestVowelIndex = vowelIndex
closestVowelDistance = vowelDistance
}
} else {
consonant = String(letter)
consonantIndex = word.distance(of: consonant)
consonantDistance = word.distance(of: closestVowel)
if consonantIndex > closestVowelIndex {
closestVowel = consonant
closestVowelIndex = consonantIndex
closestVowelDistance = consonantDistance
}
}
}
if closestVowelDistance == 0 {
return ""
} else {
return closestVowel
}
}
```swift
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// getClosestVowel(word: "yogurt") == "u"
// getClosestVowel(word: "FULL") == "U"
// getClosestVowel(word: "quick") == ""
// getClosestVowel(word: "ab") == ""
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u"]
var closestVowel = ""
var closestVowelIndex = 0
var closestVowelDistance = 0
var vowelIndex = 0
var vowelDistance = 0
var consonantIndex = 0
var consonantDistance = 0
var consonant = ""
var vowel = ""
for letter in word {
if vowels.contains(String(letter)) {
vowel = String(letter)
vowelIndex = word.distance(of: vowel)
vowelDistance = word.distance(of: closestVowel)
if vowelIndex > closestVowelIndex {
closestVowel = vowel
closestVowelIndex = vowelIndex
closestVowelDistance = vowelDistance
}
} else {
consonant = String(letter)
consonantIndex = word.distance(of: consonant)
consonantDistance = word.distance(of: closestVowel)
if consonantIndex > closestVowelIndex {
closestVowel = consonant
closestVowelIndex = consonantIndex
closestVowelDistance = consonantDistance
}
}
}
if closestVowelDistance == 0 {
return ""
} else {
return closestVowel
}
}
```
vowelIndex = word.distance(of: vowel) // no exact matches in call to instance method 'distance'
vowelDistance = word.distance(of: closestVowel) // no exact matches in call to instance method 'distance'
consonantIndex = word.distance(of: consonant) // no exact matches in call to instance method 'distance'
consonantDistance = word.distance(of: closestVowel) // no exact matches in call to instance method 'distance'
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u"]
var closestVowel = ""
var closestVowelDistance = Int.max
for (index, character) in word.enumerated() {
if vowels.contains(String(character)) {
let distance = word.distance(from: index, to: word.endIndex)
if distance < closestVowelDistance {
closestVowelDistance = distance
closestVowel = String(character)
}
}
}
return closestVowel
}
```swift
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// getClosestVowel(word: "yogurt") == "u"
// getClosestVowel(word: "FULL") == "U"
// getClosestVowel(word: "quick") == ""
// getClosestVowel(word: "ab") == ""
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u"]
var closestVowel = ""
var closestVowelDistance = Int.max
for (index, character) in word.enumerated() {
if vowels.contains(String(character)) {
let distance = word.distance(from: index, to: word.endIndex)
if distance < closestVowelDistance {
closestVowelDistance = distance
closestVowel = String(character)
}
}
}
return closestVowel
}
```
let distance = word.distance(from: index, to: word.endIndex) // cannot convert value of type 'Int' to expected argument type 'String.Index'
```swift
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// getClosestVowel(word: "yogurt") == "u"
// getClosestVowel(word: "FULL") == "U"
// getClosestVowel(word: "quick") == ""
// getClosestVowel(word: "ab") == ""
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u"]
var closestVowel = ""
var closestVowelIndex = 0
var closestVowelDistance = 0
var currentVowelDistance = 0
var currentVowelIndex = 0
var currentConsonantIndex = 0
var currentConsonantDistance = 0
var currentVowel = ""
var currentConsonant = ""
var previousConsonant = ""
var previousVowel = ""
var previousConsonantIndex = 0
var previousVowelIndex = 0
var previousVowelDistance = 0
var previousConsonantDistance = 0
var previousVowel = ""
var previousConsonant = ""
var previousPreviousConsonant = ""
var previousPreviousVowel = ""
var previousPreviousConsonantIndex = 0
var previousPreviousVowelIndex = 0
var previousPreviousVowelDistance = 0
var previousPreviousConsonantDistance = 0
var previousPreviousVowel = ""
var previousPreviousConsonant = ""
var previousPreviousPreviousConsonant = ""
var previousPreviousPreviousVowel = ""
var previousPreviousPreviousConsonantIndex = 0
var previousPreviousPreviousVowelIndex = 0
var previousPreviousPreviousVowelDistance = 0
var previousPreviousPreviousConsonantDistance = 0
var previousPreviousPreviousVowel = ""
var previousPreviousPreviousConsonant = ""
var previousPreviousPreviousPreviousConsonant = ""
var previousPreviousPreviousPreviousVowel = ""
var previousPreviousPreviousPreviousConsonantIndex = 0
var previousPreviousPreviousPreviousVowelIndex = 0
var previousPreviousPreviousPreviousVowelDistance = 0
var previousPreviousPreviousPreviousConsonantDistance = 0
var previousPreviousPreviousPreviousVowel = ""
var previousPreviousPreviousPreviousConsonant = ""
var previousPreviousPreviousPreviousPreviousConsonant = ""
var previousPreviousPreviousPreviousPreviousVowel = ""
var previousPreviousPreviousPreviousPreviousConsonantIndex = 0
var previousPreviousPreviousPreviousPreviousVowelIndex = 0
var previousPreviousPreviousPreviousPreviousVowelDistance = 0
var previousPreviousPreviousPreviousPreviousConsonantDistance = 0
var previousPreviousPreviousPreviousPreviousVowel = ""
var previousPreviousPreviousPreviousPreviousConsonant = ""
var previousPreviousPreviousPreviousPreviousPreviousConsonant = ""
var previousPreviousPreviousPreviousPreviousPreviousVowel = ""
var previousPreviousPreviousPreviousPreviousPreviousConsonantIndex = 0
var previousPreviousPreviousPreviousPreviousPreviousVowelIndex = 0
var previousPreviousPreviousPreviousPreviousPreviousVowelDistance = 0
var previousPreviousPreviousPreviousPreviousPreviousConsonantDistance = 0
var previousPreviousPreviousPreviousPreviousPreviousVowel = ""
var previousPreviousPreviousPreviousPreviousPreviousConsonant = ""
var previousPreviousPreviousPreviousPreviousPreviousPreviousConsonant = ""
var previousPreviousPreviousPreviousPreviousPreviousPreviousVowel = ""
var previousPreviousPreviousPreviousPreviousPreviousPreviousConsonantIndex = 0
var previousPreviousPreviousPreviousPreviousPreviousPreviousVowelIndex = 0
var previousPreviousPreviousPreviousPreviousPreviousPreviousVowelDistance = 0
var previousPreviousPreviousPreviousPreviousPreviousPreviousConsonantDistance = 0
var previousPreviousPreviousPreviousPreviousPreviousPreviousVowel = ""
var previousPreviousPreviousPreviousPreviousPreviousPreviousConsonant = ""
var previousPreviousPreviousPreviousPreviousPreviousPreviousPreviousConsonant = ""
var previousPreviousPreviousPreviousPreviousPreviousPreviousPreviousVowel = ""
var previousPreviousPreviousPreviousPreviousPreviousPreviousPreviousConsonantIndex = 0
var previousPreviousPreviousPreviousPreviousPreviousPreviousPreviousVowelIndex = 0
var previousPreviousPreviousPreviousPreviousPreviousPreviousPreviousVowelDistance = 0
var previousPreviousPreviousPreviousPreviousPreviousPreviousPreviousConsonantDistance = 0
var previousPreviousPreviousPreviousPreviousPreviousPreviousPreviousVowel = ""
var previousPreviousPreviousPreviousPreviousPreviousPreviousPreviousConsonant = ""
var previousPreviousPreviousPreviousPreviousPreviousPreviousPreviousPreviousConsonant = ""
var previousPreviousPreviousPreviousPreviousPreviousPreviousPreviousPreviousVowel = ""
var previousPreviousPreviousPreviousPreviousPreviousPreviousPreviousPreviousConsonantIndex = 0
var previousPreviousPreviousPreviousPreviousPreviousPreviousPreviousPreviousVowelIndex = 0
var previousPreviousPreviousPreviousPreviousPreviousPreviousPreviousPreviousVowelDistance = 0
var previousPreviousPreviousPreviousPreviousPreviousPreviousPreviousPreviousConsonantDistance = 0
var previousPreviousPreviousPreviousPreviousPreviousPreviousPreviousPreviousVowel = ""
var previousPreviousPreviousPreviousPreviousPreviousPreviousPreviousPreviousConsonant = ""
var previousPreviousPreviousPreviousPreviousPreviousPreviousPreviousPreviousPreviousConsonant = ""
var previousPreviousPreviousPreviousPreviousPrevious
XCTAssertTrue(getClosestVowel(word: "yogurt") == "u") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "full") == "u") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "easy") == "") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "eAsy") == "") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "ali") == "") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "bad") == "a") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "most") == "o") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "ab") == "") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "ba") == "") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "quick") == "") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "anime") == "i") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "Asia") == "") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "Above") == "o") // cannot find 'getClosestVowel' in scope
```swift
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// getClosestVowel(word: "yogurt") == "u"
// getClosestVowel(word: "FULL") == "U"
// getClosestVowel(word: "quick") == ""
// getClosestVowel(word: "ab") == ""
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u"]
var closestVowel: String = ""
var closestVowelIndex: Int = 0
var closestVowelDistance: Int = 0
var currentVowelDistance: Int = 0
var currentVowelIndex: Int = 0
var currentVowel: String = ""
var currentConsonant: String = ""
var currentConsonantIndex: Int = 0
var currentConsonantDistance: Int = 0
var consonants: [String] = []
var vowelsFound: [String] = []
var consonantsFound: [String] = []
var vowelsFoundIndexes: [Int] = []
var consonantsFoundIndexes: [Int] = []
var vowelsFoundDistances: [Int] = []
var consonantsFoundDistances: [Int] = []
var vowelsFoundDistancesSorted: [Int] = []
var consonantsFoundDistancesSorted: [Int] = []
var vowelsFoundIndexesSorted: [Int] = []
var consonantsFoundIndexesSorted: [Int] = []
var vowelsFound: [String] = []
var consonantsFound: [String] = []
var vowelsFoundIndexes: [Int] = []
var consonantsFoundIndexes: [Int] = []
var vowelsFoundDistances: [Int] = []
var consonantsFoundDistances: [Int] = []
var vowelsFoundDistancesSorted: [Int] = []
var consonantsFoundDistancesSorted: [Int] = []
var vowelsFoundIndexesSorted: [Int] = []
var consonantsFoundIndexesSorted: [Int] = []
var vowelsFound: [String] = []
var consonantsFound: [String] = []
var vowelsFoundIndexes: [Int] = []
var consonantsFoundIndexes: [Int] = []
var vowelsFoundDistances: [Int] = []
var consonantsFoundDistances: [Int] = []
var vowelsFoundDistancesSorted: [Int] = []
var consonantsFoundDistancesSorted: [Int] = []
var vowelsFoundIndexesSorted: [Int] = []
var consonantsFoundIndexesSorted: [Int] = []
var vowelsFound: [String] = []
var consonantsFound: [String] = []
var vowelsFoundIndexes: [Int] = []
var consonantsFoundIndexes: [Int] = []
var vowelsFoundDistances: [Int] = []
var consonantsFoundDistances: [Int] = []
var vowelsFoundDistancesSorted: [Int] = []
var consonantsFoundDistancesSorted: [Int] = []
var vowelsFoundIndexesSorted: [Int] = []
var consonantsFoundIndexesSorted: [Int] = []
var vowelsFound: [String] = []
var consonantsFound: [String] = []
var vowelsFoundIndexes: [Int] = []
var consonantsFoundIndexes: [Int] = []
var vowelsFoundDistances: [Int] = []
var consonantsFoundDistances: [Int] = []
var vowelsFoundDistancesSorted: [Int] = []
var consonantsFoundDistancesSorted: [Int] = []
var vowelsFoundIndexesSorted: [Int] = []
var consonantsFoundIndexesSorted: [Int] = []
var vowelsFound: [String] = []
var consonantsFound: [String] = []
var vowelsFoundIndexes: [Int] = []
var consonantsFoundIndexes: [Int] = []
var vowelsFoundDistances: [Int] = []
var consonantsFoundDistances: [Int] = []
var vowelsFoundDistancesSorted: [Int] = []
var consonantsFoundDistancesSorted: [Int] = []
var vowelsFoundIndexesSorted: [Int] = []
var consonantsFoundIndexesSorted: [Int] = []
var vowelsFound: [String] = []
var consonantsFound: [String] = []
var vowelsFoundIndexes: [Int] = []
var consonantsFoundIndexes: [Int] = []
var vowelsFoundDistances: [Int] = []
var consonantsFoundDistances: [Int] = []
var
XCTAssertTrue(getClosestVowel(word: "yogurt") == "u") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "full") == "u") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "easy") == "") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "eAsy") == "") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "ali") == "") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "bad") == "a") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "most") == "o") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "ab") == "") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "ba") == "") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "quick") == "") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "anime") == "i") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "Asia") == "") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "Above") == "o") // cannot find 'getClosestVowel' in scope
func getClosestVowel(word: String) -> String {
var vowels = ["a", "e", "i", "o", "u"]
var result = ""
var index = 0
for i in word.characters.reversed() {
if vowels.contains(String(i)) {
result = String(i)
break
}
index += 1
}
if result == "" {
return ""
}
var result2 = ""
for i in word.characters {
if vowels.contains(String(i)) {
result2 = String(i)
break
}
}
if result2 == "" {
return ""
}
if index > result2.characters.count {
return ""
}
return result
}
```swift
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// getClosestVowel(word: "yogurt") == "u"
// getClosestVowel(word: "FULL") == "U"
// getClosestVowel(word: "quick") == ""
// getClosestVowel(word: "ab") == ""
func getClosestVowel(word: String) -> String {
var vowels = ["a", "e", "i", "o", "u"]
var result = ""
var index = 0
for i in word.characters.reversed() {
if vowels.contains(String(i)) {
result = String(i)
break
}
index += 1
}
if result == "" {
return ""
}
var result2 = ""
for i in word.characters {
if vowels.contains(String(i)) {
result2 = String(i)
break
}
}
if result2 == "" {
return ""
}
if index > result2.characters.count {
return ""
}
return result
}
```
var vowels = ["a", "e", "i", "o", "u"] // variable 'vowels' was never mutated; consider changing to 'let' constant
for i in word.characters.reversed() { // 'characters' is unavailable: Please use String directly
for i in word.characters { // 'characters' is unavailable: Please use String directly
if index > result2.characters.count { // 'characters' is unavailable: Please use String directly
func matchParens(lst: [String]) -> String {
var stack = [String]()
for s in lst {
if s == "(" {
stack.append(s)
} else {
if stack.isEmpty {
return "No"
}
stack.removeLast()
}
}
return stack.isEmpty? "Yes" : "No"
}
```swift
// You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// matchParens(lst: ["()(", ")"]) == "Yes"
// matchParens(lst: [")", ")"]) == "No"
func matchParens(lst: [String]) -> String {
var stack = [String]()
for s in lst {
if s == "(" {
stack.append(s)
} else {
if stack.isEmpty {
return "No"
}
stack.removeLast()
}
}
return stack.isEmpty? "Yes" : "No"
}
```
return stack.isEmpty? "Yes" : "No" // string literal is unused
return stack.isEmpty? "Yes" : "No" // expected expression
return stack.isEmpty? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return stack.isEmpty? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return stack.isEmpty? "Yes" : "No" // cannot use optional chaining on non-optional value of type 'Bool'
func matchParens(lst: [String]) -> String {
var stack = [String]()
for s in lst {
if s == "(" {
stack.append(s)
} else {
if stack.isEmpty {
return "No"
}
stack.removeLast()
}
}
return stack.isEmpty? "Yes" : "No"
}
```swift
// You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// matchParens(lst: ["()(", ")"]) == "Yes"
// matchParens(lst: [")", ")"]) == "No"
func matchParens(lst: [String]) -> String {
var stack = [String]()
for s in lst {
if s == "(" {
stack.append(s)
} else {
if stack.isEmpty {
return "No"
}
stack.removeLast()
}
}
return stack.isEmpty? "Yes" : "No"
}
```
return stack.isEmpty? "Yes" : "No" // string literal is unused
return stack.isEmpty? "Yes" : "No" // expected expression
return stack.isEmpty? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return stack.isEmpty? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return stack.isEmpty? "Yes" : "No" // cannot use optional chaining on non-optional value of type 'Bool'
func matchParens(lst: [String]) -> String {
var stack: [String] = []
for s in lst {
if s == "(" {
stack.append(s)
} else {
if stack.isEmpty {
return "No"
}
stack.removeLast()
}
}
return stack.isEmpty? "Yes" : "No"
}
```swift
// You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// matchParens(lst: ["()(", ")"]) == "Yes"
// matchParens(lst: [")", ")"]) == "No"
func matchParens(lst: [String]) -> String {
var stack: [String] = []
for s in lst {
if s == "(" {
stack.append(s)
} else {
if stack.isEmpty {
return "No"
}
stack.removeLast()
}
}
return stack.isEmpty? "Yes" : "No"
}
```
return stack.isEmpty? "Yes" : "No" // string literal is unused
return stack.isEmpty? "Yes" : "No" // expected expression
return stack.isEmpty? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return stack.isEmpty? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return stack.isEmpty? "Yes" : "No" // cannot use optional chaining on non-optional value of type 'Bool'
func matchParens(lst: [String]) -> String {
var stack = [String]()
for s in lst {
if s == "(" {
stack.append(s)
} else {
if stack.isEmpty {
return "No"
}
stack.removeLast()
}
}
return stack.isEmpty? "Yes" : "No"
}
```swift
// You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// matchParens(lst: ["()(", ")"]) == "Yes"
// matchParens(lst: [")", ")"]) == "No"
func matchParens(lst: [String]) -> String {
var stack = [String]()
for s in lst {
if s == "(" {
stack.append(s)
} else {
if stack.isEmpty {
return "No"
}
stack.removeLast()
}
}
return stack.isEmpty? "Yes" : "No"
}
```
return stack.isEmpty? "Yes" : "No" // string literal is unused
return stack.isEmpty? "Yes" : "No" // expected expression
return stack.isEmpty? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return stack.isEmpty? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return stack.isEmpty? "Yes" : "No" // cannot use optional chaining on non-optional value of type 'Bool'
func matchParens(lst: [String]) -> String {
var stack = [String]()
for str in lst {
if str == "(" {
stack.append(str)
} else {
if stack.isEmpty {
return "No"
}
stack.removeLast()
}
}
return stack.isEmpty? "Yes" : "No"
}
```swift
// You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// matchParens(lst: ["()(", ")"]) == "Yes"
// matchParens(lst: [")", ")"]) == "No"
func matchParens(lst: [String]) -> String {
var stack = [String]()
for str in lst {
if str == "(" {
stack.append(str)
} else {
if stack.isEmpty {
return "No"
}
stack.removeLast()
}
}
return stack.isEmpty? "Yes" : "No"
}
```
return stack.isEmpty? "Yes" : "No" // string literal is unused
return stack.isEmpty? "Yes" : "No" // expected expression
return stack.isEmpty? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return stack.isEmpty? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return stack.isEmpty? "Yes" : "No" // cannot use optional chaining on non-optional value of type 'Bool'
func matchParens(lst: [String]) -> String {
var stack = [String]()
for s in lst {
if s == "(" {
stack.append(s)
} else {
if stack.isEmpty {
return "No"
}
stack.removeLast()
}
}
return stack.isEmpty? "Yes" : "No"
}
```swift
// You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// matchParens(lst: ["()(", ")"]) == "Yes"
// matchParens(lst: [")", ")"]) == "No"
func matchParens(lst: [String]) -> String {
var stack = [String]()
for s in lst {
if s == "(" {
stack.append(s)
} else {
if stack.isEmpty {
return "No"
}
stack.removeLast()
}
}
return stack.isEmpty? "Yes" : "No"
}
```
return stack.isEmpty? "Yes" : "No" // string literal is unused
return stack.isEmpty? "Yes" : "No" // expected expression
return stack.isEmpty? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return stack.isEmpty? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return stack.isEmpty? "Yes" : "No" // cannot use optional chaining on non-optional value of type 'Bool'
func matchParens(lst: [String]) -> String {
var stack = [Character]()
for char in lst[0] {
stack.append(char)
}
for char in lst[1] {
if stack.isEmpty {
return "No"
}
if stack.last == "(" && char == ")" {
stack.removeLast()
} else {
return "No"
}
}
return stack.isEmpty? "Yes" : "No"
}
```swift
// You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// matchParens(lst: ["()(", ")"]) == "Yes"
// matchParens(lst: [")", ")"]) == "No"
func matchParens(lst: [String]) -> String {
var stack = [Character]()
for char in lst[0] {
stack.append(char)
}
for char in lst[1] {
if stack.isEmpty {
return "No"
}
if stack.last == "(" && char == ")" {
stack.removeLast()
} else {
return "No"
}
}
return stack.isEmpty? "Yes" : "No"
}
```
return stack.isEmpty? "Yes" : "No" // expected expression
return stack.isEmpty? "Yes" : "No" // string literal is unused
return stack.isEmpty? "Yes" : "No" // cannot use optional chaining on non-optional value of type 'Bool'
return stack.isEmpty? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return stack.isEmpty? "Yes" : "No" // consecutive statements on a line must be separated by ';'
func matchParens(lst: [String]) -> String {
var stack = [String]()
for str in lst {
if str == "(" {
stack.append(str)
} else {
if stack.isEmpty {
return "No"
}
stack.removeLast()
}
}
return stack.isEmpty? "Yes" : "No"
}
```swift
// You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// matchParens(lst: ["()(", ")"]) == "Yes"
// matchParens(lst: [")", ")"]) == "No"
func matchParens(lst: [String]) -> String {
var stack = [String]()
for str in lst {
if str == "(" {
stack.append(str)
} else {
if stack.isEmpty {
return "No"
}
stack.removeLast()
}
}
return stack.isEmpty? "Yes" : "No"
}
```
return stack.isEmpty? "Yes" : "No" // string literal is unused
return stack.isEmpty? "Yes" : "No" // expected expression
return stack.isEmpty? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return stack.isEmpty? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return stack.isEmpty? "Yes" : "No" // cannot use optional chaining on non-optional value of type 'Bool'
func matchParens(lst: [String]) -> String {
var stack = [String]()
for s in lst {
if s == "(" {
stack.append(s)
} else {
if stack.isEmpty {
return "No"
}
stack.removeLast()
}
}
return stack.isEmpty? "Yes" : "No"
}
```swift
// You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// matchParens(lst: ["()(", ")"]) == "Yes"
// matchParens(lst: [")", ")"]) == "No"
func matchParens(lst: [String]) -> String {
var stack = [String]()
for s in lst {
if s == "(" {
stack.append(s)
} else {
if stack.isEmpty {
return "No"
}
stack.removeLast()
}
}
return stack.isEmpty? "Yes" : "No"
}
```
return stack.isEmpty? "Yes" : "No" // string literal is unused
return stack.isEmpty? "Yes" : "No" // expected expression
return stack.isEmpty? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return stack.isEmpty? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return stack.isEmpty? "Yes" : "No" // cannot use optional chaining on non-optional value of type 'Bool'
func matchParens(lst: [String]) -> String {
var stack = [String]()
for str in lst {
if str == "(" {
stack.append(str)
} else {
if stack.isEmpty {
return "No"
}
stack.removeLast()
}
}
return stack.isEmpty? "Yes" : "No"
}
```swift
// You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// matchParens(lst: ["()(", ")"]) == "Yes"
// matchParens(lst: [")", ")"]) == "No"
func matchParens(lst: [String]) -> String {
var stack = [String]()
for str in lst {
if str == "(" {
stack.append(str)
} else {
if stack.isEmpty {
return "No"
}
stack.removeLast()
}
}
return stack.isEmpty? "Yes" : "No"
}
```
return stack.isEmpty? "Yes" : "No" // string literal is unused
return stack.isEmpty? "Yes" : "No" // expected expression
return stack.isEmpty? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return stack.isEmpty? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return stack.isEmpty? "Yes" : "No" // cannot use optional chaining on non-optional value of type 'Bool'
func maximum(arr: [Int], k: Int) -> [Int] {
var result = [Int]()
var heap = Heap(sort: { $0 > $1 })
for num in arr {
heap.push(num)
}
for _ in 0..<k {
result.append(heap.pop()!)
}
return result
}
```swift
// Given an array arr of integers and a positive integer k, return a sorted array
// of length k with the maximum k numbers in arr.
// Example 1:
// Example 2:
// Example 3:
// Note:
// 1. The length of the array will be in the range of [1, 1000].
// 2. The elements in the array will be in the range of [-1000, 1000].
// 3. 0 <= k <= len(arr)
// maximum(arr: [-3, -4, 5], k: 3) == [-4, -3, 5]
// maximum(arr: [4, -4, 4], k: 2) == [4, 4]
// maximum(arr: [-3, 2, 1, 2, -1, -2, 1], k: 1) == [2]
func maximum(arr: [Int], k: Int) -> [Int] {
var result = [Int]()
var heap = Heap(sort: { $0 > $1 })
for num in arr {
heap.push(num)
}
for _ in 0..<k {
result.append(heap.pop()!)
}
return result
}
```
var heap = Heap(sort: { $0 > $1 }) // cannot find 'Heap' in scope
func maximum(arr: [Int], k: Int) -> [Int] {
var result = [Int]()
var heap = Heap(sort: { $0 > $1 })
for num in arr {
heap.push(num)
}
for _ in 0..<k {
result.append(heap.pop()!)
}
return result
}
```swift
// Given an array arr of integers and a positive integer k, return a sorted array
// of length k with the maximum k numbers in arr.
// Example 1:
// Example 2:
// Example 3:
// Note:
// 1. The length of the array will be in the range of [1, 1000].
// 2. The elements in the array will be in the range of [-1000, 1000].
// 3. 0 <= k <= len(arr)
// maximum(arr: [-3, -4, 5], k: 3) == [-4, -3, 5]
// maximum(arr: [4, -4, 4], k: 2) == [4, 4]
// maximum(arr: [-3, 2, 1, 2, -1, -2, 1], k: 1) == [2]
func maximum(arr: [Int], k: Int) -> [Int] {
var result = [Int]()
var heap = Heap(sort: { $0 > $1 })
for num in arr {
heap.push(num)
}
for _ in 0..<k {
result.append(heap.pop()!)
}
return result
}
```
var heap = Heap(sort: { $0 > $1 }) // cannot find 'Heap' in scope
func maximum(arr: [Int], k: Int) -> [Int] {
var result = [Int]()
var heap = Heap<Int>(sort: >)
for num in arr {
heap.push(num)
}
for _ in 0..<k {
result.append(heap.pop()!)
}
return result
}
```swift
// Given an array arr of integers and a positive integer k, return a sorted array
// of length k with the maximum k numbers in arr.
// Example 1:
// Example 2:
// Example 3:
// Note:
// 1. The length of the array will be in the range of [1, 1000].
// 2. The elements in the array will be in the range of [-1000, 1000].
// 3. 0 <= k <= len(arr)
// maximum(arr: [-3, -4, 5], k: 3) == [-4, -3, 5]
// maximum(arr: [4, -4, 4], k: 2) == [4, 4]
// maximum(arr: [-3, 2, 1, 2, -1, -2, 1], k: 1) == [2]
func maximum(arr: [Int], k: Int) -> [Int] {
var result = [Int]()
var heap = Heap<Int>(sort: >)
for num in arr {
heap.push(num)
}
for _ in 0..<k {
result.append(heap.pop()!)
}
return result
}
```
var heap = Heap<Int>(sort: >) // cannot find 'Heap' in scope
func maximum(arr: [Int], k: Int) -> [Int] {
var maxHeap = Heap(sort: { $0 > $1 })
for i in arr {
if maxHeap.count < k {
maxHeap.push(i)
} else {
if i > maxHeap.peek() {
maxHeap.pop()
maxHeap.push(i)
}
}
}
return maxHeap.toArray()
}
```swift
// Given an array arr of integers and a positive integer k, return a sorted array
// of length k with the maximum k numbers in arr.
// Example 1:
// Example 2:
// Example 3:
// Note:
// 1. The length of the array will be in the range of [1, 1000].
// 2. The elements in the array will be in the range of [-1000, 1000].
// 3. 0 <= k <= len(arr)
// maximum(arr: [-3, -4, 5], k: 3) == [-4, -3, 5]
// maximum(arr: [4, -4, 4], k: 2) == [4, 4]
// maximum(arr: [-3, 2, 1, 2, -1, -2, 1], k: 1) == [2]
func maximum(arr: [Int], k: Int) -> [Int] {
var maxHeap = Heap(sort: { $0 > $1 })
for i in arr {
if maxHeap.count < k {
maxHeap.push(i)
} else {
if i > maxHeap.peek() {
maxHeap.pop()
maxHeap.push(i)
}
}
}
return maxHeap.toArray()
}
```
var maxHeap = Heap(sort: { $0 > $1 }) // cannot find 'Heap' in scope
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here
}
```swift
// Given an array arr of integers and a positive integer k, return a sorted array
// of length k with the maximum k numbers in arr.
// Example 1:
// Example 2:
// Example 3:
// Note:
// 1. The length of the array will be in the range of [1, 1000].
// 2. The elements in the array will be in the range of [-1000, 1000].
// 3. 0 <= k <= len(arr)
// maximum(arr: [-3, -4, 5], k: 3) == [-4, -3, 5]
// maximum(arr: [4, -4, 4], k: 2) == [4, 4]
// maximum(arr: [-3, 2, 1, 2, -1, -2, 1], k: 1) == [2]
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here
}
```
} // missing return in global function expected to return '[Int]'
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here
}
```swift
// Given an array arr of integers and a positive integer k, return a sorted array
// of length k with the maximum k numbers in arr.
// Example 1:
// Example 2:
// Example 3:
// Note:
// 1. The length of the array will be in the range of [1, 1000].
// 2. The elements in the array will be in the range of [-1000, 1000].
// 3. 0 <= k <= len(arr)
// maximum(arr: [-3, -4, 5], k: 3) == [-4, -3, 5]
// maximum(arr: [4, -4, 4], k: 2) == [4, 4]
// maximum(arr: [-3, 2, 1, 2, -1, -2, 1], k: 1) == [2]
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here
}
```
} // missing return in global function expected to return '[Int]'
func maximum(arr: [Int], k: Int) -> [Int] {
var result = [Int]()
var heap = Heap(sort: >)
for num in arr {
heap.push(num)
}
for _ in 0..<k {
result.append(heap.pop()!)
}
return result
}
```swift
// Given an array arr of integers and a positive integer k, return a sorted array
// of length k with the maximum k numbers in arr.
// Example 1:
// Example 2:
// Example 3:
// Note:
// 1. The length of the array will be in the range of [1, 1000].
// 2. The elements in the array will be in the range of [-1000, 1000].
// 3. 0 <= k <= len(arr)
// maximum(arr: [-3, -4, 5], k: 3) == [-4, -3, 5]
// maximum(arr: [4, -4, 4], k: 2) == [4, 4]
// maximum(arr: [-3, 2, 1, 2, -1, -2, 1], k: 1) == [2]
func maximum(arr: [Int], k: Int) -> [Int] {
var result = [Int]()
var heap = Heap(sort: >)
for num in arr {
heap.push(num)
}
for _ in 0..<k {
result.append(heap.pop()!)
}
return result
}
```
var heap = Heap(sort: >) // cannot find 'Heap' in scope
func maximum(arr: [Int], k: Int) -> [Int] {
var result = [Int]()
var heap = Heap(sort: { $0 > $1 })
for num in arr {
heap.push(num)
}
for _ in 0..<k {
result.append(heap.pop()!)
}
return result
}
```swift
// Given an array arr of integers and a positive integer k, return a sorted array
// of length k with the maximum k numbers in arr.
// Example 1:
// Example 2:
// Example 3:
// Note:
// 1. The length of the array will be in the range of [1, 1000].
// 2. The elements in the array will be in the range of [-1000, 1000].
// 3. 0 <= k <= len(arr)
// maximum(arr: [-3, -4, 5], k: 3) == [-4, -3, 5]
// maximum(arr: [4, -4, 4], k: 2) == [4, 4]
// maximum(arr: [-3, 2, 1, 2, -1, -2, 1], k: 1) == [2]
func maximum(arr: [Int], k: Int) -> [Int] {
var result = [Int]()
var heap = Heap(sort: { $0 > $1 })
for num in arr {
heap.push(num)
}
for _ in 0..<k {
result.append(heap.pop()!)
}
return result
}
```
var heap = Heap(sort: { $0 > $1 }) // cannot find 'Heap' in scope
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here
return []
}
```swift
// Given an array arr of integers and a positive integer k, return a sorted array
// of length k with the maximum k numbers in arr.
// Example 1:
// Example 2:
// Example 3:
// Note:
// 1. The length of the array will be in the range of [1, 1000].
// 2. The elements in the array will be in the range of [-1000, 1000].
// 3. 0 <= k <= len(arr)
// maximum(arr: [-3, -4, 5], k: 3) == [-4, -3, 5]
// maximum(arr: [4, -4, 4], k: 2) == [4, 4]
// maximum(arr: [-3, 2, 1, 2, -1, -2, 1], k: 1) == [2]
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here
return []
}
```
// XCTAssertTrue failed
func maximum(arr: [Int], k: Int) -> [Int] {
var result = [Int]()
var heap = Heap<Int>(sort: >)
for num in arr {
heap.push(num)
}
for _ in 0..<k {
result.append(heap.pop()!)
}
return result
}
```swift
// Given an array arr of integers and a positive integer k, return a sorted array
// of length k with the maximum k numbers in arr.
// Example 1:
// Example 2:
// Example 3:
// Note:
// 1. The length of the array will be in the range of [1, 1000].
// 2. The elements in the array will be in the range of [-1000, 1000].
// 3. 0 <= k <= len(arr)
// maximum(arr: [-3, -4, 5], k: 3) == [-4, -3, 5]
// maximum(arr: [4, -4, 4], k: 2) == [4, 4]
// maximum(arr: [-3, 2, 1, 2, -1, -2, 1], k: 1) == [2]
func maximum(arr: [Int], k: Int) -> [Int] {
var result = [Int]()
var heap = Heap<Int>(sort: >)
for num in arr {
heap.push(num)
}
for _ in 0..<k {
result.append(heap.pop()!)
}
return result
}
```
var heap = Heap<Int>(sort: >) // cannot find 'Heap' in scope
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// solution(lst: [5, 8, 7, 1]) == 12
// solution(lst: [3, 3, 3, 3, 3]) == 9
// solution(lst: [30, 13, 24, 321]) == 0
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```
// XCTAssertTrue failed
func solution(lst: [Int]) -> Int {
return lst.enumerated().filter { $0.offset % 2 == 0 }.map { $0.element }.reduce(0, +)
}
```swift
// Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// solution(lst: [5, 8, 7, 1]) == 12
// solution(lst: [3, 3, 3, 3, 3]) == 9
// solution(lst: [30, 13, 24, 321]) == 0
func solution(lst: [Int]) -> Int {
return lst.enumerated().filter { $0.offset % 2 == 0 }.map { $0.element }.reduce(0, +)
}
```
// XCTAssertTrue failed
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// solution(lst: [5, 8, 7, 1]) == 12
// solution(lst: [3, 3, 3, 3, 3]) == 9
// solution(lst: [30, 13, 24, 321]) == 0
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```
// XCTAssertTrue failed
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// solution(lst: [5, 8, 7, 1]) == 12
// solution(lst: [3, 3, 3, 3, 3]) == 9
// solution(lst: [30, 13, 24, 321]) == 0
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```
// XCTAssertTrue failed
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// solution(lst: [5, 8, 7, 1]) == 12
// solution(lst: [3, 3, 3, 3, 3]) == 9
// solution(lst: [30, 13, 24, 321]) == 0
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```
// XCTAssertTrue failed
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// solution(lst: [5, 8, 7, 1]) == 12
// solution(lst: [3, 3, 3, 3, 3]) == 9
// solution(lst: [30, 13, 24, 321]) == 0
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```
// XCTAssertTrue failed
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// solution(lst: [5, 8, 7, 1]) == 12
// solution(lst: [3, 3, 3, 3, 3]) == 9
// solution(lst: [30, 13, 24, 321]) == 0
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```
// XCTAssertTrue failed
func solution(lst: [Int]) -> Int {
return lst.enumerated().filter { $0.offset % 2 == 0 }.map { $0.element }.reduce(0, +)
}
```swift
// Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// solution(lst: [5, 8, 7, 1]) == 12
// solution(lst: [3, 3, 3, 3, 3]) == 9
// solution(lst: [30, 13, 24, 321]) == 0
func solution(lst: [Int]) -> Int {
return lst.enumerated().filter { $0.offset % 2 == 0 }.map { $0.element }.reduce(0, +)
}
```
// XCTAssertTrue failed
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// solution(lst: [5, 8, 7, 1]) == 12
// solution(lst: [3, 3, 3, 3, 3]) == 9
// solution(lst: [30, 13, 24, 321]) == 0
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```
// XCTAssertTrue failed
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// solution(lst: [5, 8, 7, 1]) == 12
// solution(lst: [3, 3, 3, 3, 3]) == 9
// solution(lst: [30, 13, 24, 321]) == 0
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 {
sum += value
}
}
return sum
}
```
// XCTAssertTrue failed
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
let num = arr[i]
let numDigits = num.numberOfDigits()
if numDigits <= 2 {
sum += num
}
}
return sum
}
```swift
// Given a non-empty array of integers arr and an integer k, return
// the sum of the elements with at most two digits from the first k elements of arr.
// Example:
// Constraints:
// 1. 1 <= len(arr) <= 100
// 2. 1 <= k <= len(arr)
// addElements(arr: [111, 21, 3, 4000, 5, 6, 7, 8, 9], k: 4) == 24
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
let num = arr[i]
let numDigits = num.numberOfDigits()
if numDigits <= 2 {
sum += num
}
}
return sum
}
```
let numDigits = num.numberOfDigits() // value of type 'Int' has no member 'numberOfDigits'
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
sum += arr[i]
}
return sum
}
```swift
// Given a non-empty array of integers arr and an integer k, return
// the sum of the elements with at most two digits from the first k elements of arr.
// Example:
// Constraints:
// 1. 1 <= len(arr) <= 100
// 2. 1 <= k <= len(arr)
// addElements(arr: [111, 21, 3, 4000, 5, 6, 7, 8, 9], k: 4) == 24
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
sum += arr[i]
}
return sum
}
```
// XCTAssertTrue failed
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
sum += arr[i]
}
return sum
}
```swift
// Given a non-empty array of integers arr and an integer k, return
// the sum of the elements with at most two digits from the first k elements of arr.
// Example:
// Constraints:
// 1. 1 <= len(arr) <= 100
// 2. 1 <= k <= len(arr)
// addElements(arr: [111, 21, 3, 4000, 5, 6, 7, 8, 9], k: 4) == 24
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
sum += arr[i]
}
return sum
}
```
// XCTAssertTrue failed
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
sum += arr[i]
}
return sum
}
```swift
// Given a non-empty array of integers arr and an integer k, return
// the sum of the elements with at most two digits from the first k elements of arr.
// Example:
// Constraints:
// 1. 1 <= len(arr) <= 100
// 2. 1 <= k <= len(arr)
// addElements(arr: [111, 21, 3, 4000, 5, 6, 7, 8, 9], k: 4) == 24
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
sum += arr[i]
}
return sum
}
```
// XCTAssertTrue failed
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
sum += arr[i]
}
return sum
}
```swift
// Given a non-empty array of integers arr and an integer k, return
// the sum of the elements with at most two digits from the first k elements of arr.
// Example:
// Constraints:
// 1. 1 <= len(arr) <= 100
// 2. 1 <= k <= len(arr)
// addElements(arr: [111, 21, 3, 4000, 5, 6, 7, 8, 9], k: 4) == 24
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
sum += arr[i]
}
return sum
}
```
// XCTAssertTrue failed
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
sum += arr[i]
}
return sum
}
```swift
// Given a non-empty array of integers arr and an integer k, return
// the sum of the elements with at most two digits from the first k elements of arr.
// Example:
// Constraints:
// 1. 1 <= len(arr) <= 100
// 2. 1 <= k <= len(arr)
// addElements(arr: [111, 21, 3, 4000, 5, 6, 7, 8, 9], k: 4) == 24
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
sum += arr[i]
}
return sum
}
```
// XCTAssertTrue failed
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
sum += arr[i]
}
return sum
}
```swift
// Given a non-empty array of integers arr and an integer k, return
// the sum of the elements with at most two digits from the first k elements of arr.
// Example:
// Constraints:
// 1. 1 <= len(arr) <= 100
// 2. 1 <= k <= len(arr)
// addElements(arr: [111, 21, 3, 4000, 5, 6, 7, 8, 9], k: 4) == 24
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
sum += arr[i]
}
return sum
}
```
// XCTAssertTrue failed
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
let num = arr[i]
if num < 10 {
sum += num
} else {
let numStr = String(num)
if numStr.count == 2 {
sum += num
} else {
sum += Int(String(numStr.prefix(2)))!
}
}
}
return sum
}
```swift
// Given a non-empty array of integers arr and an integer k, return
// the sum of the elements with at most two digits from the first k elements of arr.
// Example:
// Constraints:
// 1. 1 <= len(arr) <= 100
// 2. 1 <= k <= len(arr)
// addElements(arr: [111, 21, 3, 4000, 5, 6, 7, 8, 9], k: 4) == 24
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
let num = arr[i]
if num < 10 {
sum += num
} else {
let numStr = String(num)
if numStr.count == 2 {
sum += num
} else {
sum += Int(String(numStr.prefix(2)))!
}
}
}
return sum
}
```
// XCTAssertTrue failed
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
sum += arr[i]
}
return sum
}
```swift
// Given a non-empty array of integers arr and an integer k, return
// the sum of the elements with at most two digits from the first k elements of arr.
// Example:
// Constraints:
// 1. 1 <= len(arr) <= 100
// 2. 1 <= k <= len(arr)
// addElements(arr: [111, 21, 3, 4000, 5, 6, 7, 8, 9], k: 4) == 24
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
sum += arr[i]
}
return sum
}
```
// XCTAssertTrue failed
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
sum += arr[i]
}
return sum
}
```swift
// Given a non-empty array of integers arr and an integer k, return
// the sum of the elements with at most two digits from the first k elements of arr.
// Example:
// Constraints:
// 1. 1 <= len(arr) <= 100
// 2. 1 <= k <= len(arr)
// addElements(arr: [111, 21, 3, 4000, 5, 6, 7, 8, 9], k: 4) == 24
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
sum += arr[i]
}
return sum
}
```
// XCTAssertTrue failed
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var num = n
while num!= 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
result.append(num)
}
return result.sorted()
}
```swift
// Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// getOddCollatz(n: 5) == [1, 5]
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var num = n
while num!= 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
result.append(num)
}
return result.sorted()
}
```
while num!= 1 { // '=' must have consistent whitespace on both sides
while num!= 1 { // use of '=' in a boolean context, did you mean '=='?
while num!= 1 { // cannot force unwrap value of non-optional type 'Int'
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var current = n
while current!= 1 {
if current % 2 == 0 {
current /= 2
} else {
current = current * 3 + 1
}
if current % 2 == 1 {
result.append(current)
}
}
return result
}
```swift
// Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// getOddCollatz(n: 5) == [1, 5]
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var current = n
while current!= 1 {
if current % 2 == 0 {
current /= 2
} else {
current = current * 3 + 1
}
if current % 2 == 1 {
result.append(current)
}
}
return result
}
```
while current!= 1 { // use of '=' in a boolean context, did you mean '=='?
while current!= 1 { // cannot force unwrap value of non-optional type 'Int'
while current!= 1 { // '=' must have consistent whitespace on both sides
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var num = n
while num!= 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
result.append(num)
}
return result
}
```swift
// Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// getOddCollatz(n: 5) == [1, 5]
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var num = n
while num!= 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
result.append(num)
}
return result
}
```
while num!= 1 { // '=' must have consistent whitespace on both sides
while num!= 1 { // use of '=' in a boolean context, did you mean '=='?
while num!= 1 { // cannot force unwrap value of non-optional type 'Int'
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var num = n
while num > 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
result.append(num)
}
return result.sorted()
}
```swift
// Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// getOddCollatz(n: 5) == [1, 5]
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var num = n
while num > 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
result.append(num)
}
return result.sorted()
}
```
// XCTAssertTrue failed
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var num = n
while num!= 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
result.append(num)
}
return result.sorted()
}
```swift
// Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// getOddCollatz(n: 5) == [1, 5]
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var num = n
while num!= 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
result.append(num)
}
return result.sorted()
}
```
while num!= 1 { // '=' must have consistent whitespace on both sides
while num!= 1 { // use of '=' in a boolean context, did you mean '=='?
while num!= 1 { // cannot force unwrap value of non-optional type 'Int'
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var num = n
while num!= 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
result.append(num)
}
return result.sorted()
}
```swift
// Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// getOddCollatz(n: 5) == [1, 5]
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var num = n
while num!= 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
result.append(num)
}
return result.sorted()
}
```
while num!= 1 { // '=' must have consistent whitespace on both sides
while num!= 1 { // use of '=' in a boolean context, did you mean '=='?
while num!= 1 { // cannot force unwrap value of non-optional type 'Int'
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var num = n
while num!= 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
result.append(num)
}
return result
}
```swift
// Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// getOddCollatz(n: 5) == [1, 5]
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var num = n
while num!= 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
result.append(num)
}
return result
}
```
while num!= 1 { // '=' must have consistent whitespace on both sides
while num!= 1 { // use of '=' in a boolean context, did you mean '=='?
while num!= 1 { // cannot force unwrap value of non-optional type 'Int'
func getOddCollatz(n: Int) -> [Int] {
var result: [Int] = []
var num = n
while num > 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
result.append(num)
}
return result
}
```swift
// Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// getOddCollatz(n: 5) == [1, 5]
func getOddCollatz(n: Int) -> [Int] {
var result: [Int] = []
var num = n
while num > 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
result.append(num)
}
return result
}
```
// XCTAssertTrue failed
func getOddCollatz(n: Int) -> [Int] {
var result: [Int] = []
var num = n
while num > 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
result.append(num)
}
return result
}
```swift
// Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// getOddCollatz(n: 5) == [1, 5]
func getOddCollatz(n: Int) -> [Int] {
var result: [Int] = []
var num = n
while num > 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
result.append(num)
}
return result
}
```
// XCTAssertTrue failed
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var num = n
while num > 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
result.append(num)
}
return result.sorted()
}
```swift
// Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// getOddCollatz(n: 5) == [1, 5]
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var num = n
while num > 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
result.append(num)
}
return result.sorted()
}
```
// XCTAssertTrue failed
func validDate(date: String) -> Bool {
// Write your code here
}
```swift
// You have to write a function which validates a given date string and
// returns true if the date is valid otherwise false.
// The date is valid if all of the following rules are satisfied:
// 1. The date string is not empty.
// 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// validDate(date: "03-11-2000") == true
// validDate(date: "15-01-2012") == false
// validDate(date: "04-0-2040") == false
// validDate(date: "06-04-2020") == true
// validDate(date: "06/04/2020") == false
func validDate(date: String) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func validDate(date: String) -> Bool {
// Write your code here
}
```swift
// You have to write a function which validates a given date string and
// returns true if the date is valid otherwise false.
// The date is valid if all of the following rules are satisfied:
// 1. The date string is not empty.
// 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// validDate(date: "03-11-2000") == true
// validDate(date: "15-01-2012") == false
// validDate(date: "04-0-2040") == false
// validDate(date: "06-04-2020") == true
// validDate(date: "06/04/2020") == false
func validDate(date: String) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func validDate(date: String) -> Bool {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MM-dd-yyyy"
if let date = dateFormatter.date(from: date) {
let calendar = Calendar.current
let year = calendar.component(.year, from: date)
let month = calendar.component(.month, from: date)
let day = calendar.component(.day, from: date)
let daysInMonth = calendar.range(of:.day, in:.month, for: date)!.count
return year > 0 && month > 0 && month <= 12 && day > 0 && day <= daysInMonth
}
return false
}
```swift
// You have to write a function which validates a given date string and
// returns true if the date is valid otherwise false.
// The date is valid if all of the following rules are satisfied:
// 1. The date string is not empty.
// 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// validDate(date: "03-11-2000") == true
// validDate(date: "15-01-2012") == false
// validDate(date: "04-0-2040") == false
// validDate(date: "06-04-2020") == true
// validDate(date: "06/04/2020") == false
func validDate(date: String) -> Bool {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MM-dd-yyyy"
if let date = dateFormatter.date(from: date) {
let calendar = Calendar.current
let year = calendar.component(.year, from: date)
let month = calendar.component(.month, from: date)
let day = calendar.component(.day, from: date)
let daysInMonth = calendar.range(of:.day, in:.month, for: date)!.count
return year > 0 && month > 0 && month <= 12 && day > 0 && day <= daysInMonth
}
return false
}
```
func validDate(date: String) -> Bool {
// Write your code here.
}
```swift
// You have to write a function which validates a given date string and
// returns true if the date is valid otherwise false.
// The date is valid if all of the following rules are satisfied:
// 1. The date string is not empty.
// 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// validDate(date: "03-11-2000") == true
// validDate(date: "15-01-2012") == false
// validDate(date: "04-0-2040") == false
// validDate(date: "06-04-2020") == true
// validDate(date: "06/04/2020") == false
func validDate(date: String) -> Bool {
// Write your code here.
}
```
} // missing return in global function expected to return 'Bool'
func validDate(date: String) -> Bool {
// Write your code here
}
```swift
// You have to write a function which validates a given date string and
// returns true if the date is valid otherwise false.
// The date is valid if all of the following rules are satisfied:
// 1. The date string is not empty.
// 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// validDate(date: "03-11-2000") == true
// validDate(date: "15-01-2012") == false
// validDate(date: "04-0-2040") == false
// validDate(date: "06-04-2020") == true
// validDate(date: "06/04/2020") == false
func validDate(date: String) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func validDate(date: String) -> Bool {
// Write your code here.
}
```swift
// You have to write a function which validates a given date string and
// returns true if the date is valid otherwise false.
// The date is valid if all of the following rules are satisfied:
// 1. The date string is not empty.
// 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// validDate(date: "03-11-2000") == true
// validDate(date: "15-01-2012") == false
// validDate(date: "04-0-2040") == false
// validDate(date: "06-04-2020") == true
// validDate(date: "06/04/2020") == false
func validDate(date: String) -> Bool {
// Write your code here.
}
```
} // missing return in global function expected to return 'Bool'
func validDate(date: String) -> Bool {
// Write your code here
}
```swift
// You have to write a function which validates a given date string and
// returns true if the date is valid otherwise false.
// The date is valid if all of the following rules are satisfied:
// 1. The date string is not empty.
// 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// validDate(date: "03-11-2000") == true
// validDate(date: "15-01-2012") == false
// validDate(date: "04-0-2040") == false
// validDate(date: "06-04-2020") == true
// validDate(date: "06/04/2020") == false
func validDate(date: String) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func validDate(date: String) -> Bool {
// Write your code here.
}
```swift
// You have to write a function which validates a given date string and
// returns true if the date is valid otherwise false.
// The date is valid if all of the following rules are satisfied:
// 1. The date string is not empty.
// 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// validDate(date: "03-11-2000") == true
// validDate(date: "15-01-2012") == false
// validDate(date: "04-0-2040") == false
// validDate(date: "06-04-2020") == true
// validDate(date: "06/04/2020") == false
func validDate(date: String) -> Bool {
// Write your code here.
}
```
} // missing return in global function expected to return 'Bool'
func validDate(date: String) -> Bool {
// Write your code here.
}
```swift
// You have to write a function which validates a given date string and
// returns true if the date is valid otherwise false.
// The date is valid if all of the following rules are satisfied:
// 1. The date string is not empty.
// 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// validDate(date: "03-11-2000") == true
// validDate(date: "15-01-2012") == false
// validDate(date: "04-0-2040") == false
// validDate(date: "06-04-2020") == true
// validDate(date: "06/04/2020") == false
func validDate(date: String) -> Bool {
// Write your code here.
}
```
} // missing return in global function expected to return 'Bool'
func validDate(date: String) -> Bool {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MM-dd-yyyy"
if let date = dateFormatter.date(from: date) {
let calendar = Calendar.current
let day = calendar.component(.day, from: date)
let month = calendar.component(.month, from: date)
let year = calendar.component(.year, from: date)
let daysInMonth = calendar.range(of:.day, in:.month, for: date)!.count
if day > 0 && day <= daysInMonth && month > 0 && month <= 12 && year > 0 {
return true
}
}
return false
}
```swift
// You have to write a function which validates a given date string and
// returns true if the date is valid otherwise false.
// The date is valid if all of the following rules are satisfied:
// 1. The date string is not empty.
// 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// validDate(date: "03-11-2000") == true
// validDate(date: "15-01-2012") == false
// validDate(date: "04-0-2040") == false
// validDate(date: "06-04-2020") == true
// validDate(date: "06/04/2020") == false
func validDate(date: String) -> Bool {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MM-dd-yyyy"
if let date = dateFormatter.date(from: date) {
let calendar = Calendar.current
let day = calendar.component(.day, from: date)
let month = calendar.component(.month, from: date)
let year = calendar.component(.year, from: date)
let daysInMonth = calendar.range(of:.day, in:.month, for: date)!.count
if day > 0 && day <= daysInMonth && month > 0 && month <= 12 && year > 0 {
return true
}
}
return false
}
```
extension Int: Error {
}
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
// Your code here
}
```swift
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
// Your code here
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
// TODO: Implement me!
return.failure(0)
}
```swift
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
// TODO: Implement me!
return.failure(0)
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.success([])
}
```swift
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.success([])
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.failure(0)
}
```swift
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.failure(0)
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.failure(0)
}
```swift
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.failure(0)
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.success([])
}
func splitWords(txt: String) -> Result<[String], Int> {
return.success([])
}
```swift
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.success([])
}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1,... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") ==.success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") ==.success(["Hello", "world!"])
// splitWords(txt: "abcdef") ==.failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.success([])
}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1,... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") ==.success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") ==.success(["Hello", "world!"])
// splitWords(txt: "abcdef") ==.failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.success([])
}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1,... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") ==.success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") ==.success(["Hello", "world!"])
// splitWords(txt: "abcdef") ==.failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.success([])
}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1,... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") ==.success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") ==.success(["Hello", "world!"])
// splitWords(txt: "abcdef") ==.failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.success([])
}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1,... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") ==.success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") ==.success(["Hello", "world!"])
// splitWords(txt: "abcdef") ==.failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.success([])
}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1,... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") ==.success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") ==.success(["Hello", "world!"])
// splitWords(txt: "abcdef") ==.failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.success
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
func splitWords(txt: String) -> Result<[String], Int> { // invalid redeclaration of 'splitWords(txt:)'
extension Int: Error {
}
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.failure(0)
}
func sum(_ arr: [Int]) -> Int {
return 0
}
```swift
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.failure(0)
}
// Given an array of integers, return the sum of the integers in the array.
// Examples
// sum([1, 2, 3]) == 6
// sum([1, 2, 3, 4]) == 10
func sum(_ arr: [Int]) -> Int {
return 0
}
// Given an array of integers, return the sum of the integers in the array.
// Examples
// sum([1, 2, 3]) == 6
// sum([1, 2, 3, 4]) == 10
func sum(_ arr: [Int]) -> Int {
return 0
}
// Given an array of integers, return the sum of the integers in the array.
// Examples
// sum([1, 2, 3]) == 6
// sum([1, 2, 3, 4]) == 10
func sum(_ arr: [Int]) -> Int {
return 0
}
// Given an array of integers, return the sum of the integers in the array.
// Examples
// sum([1, 2, 3]) == 6
// sum([1, 2, 3, 4]) == 10
func sum(_ arr: [Int]) -> Int {
return 0
}
// Given an array of integers, return the sum of the integers in the array.
// Examples
// sum([1, 2, 3]) == 6
// sum([1, 2, 3, 4]) == 10
func sum(_ arr: [Int]) -> Int {
return 0
}
// Given an array of integers, return the sum of the integers in the array.
// Examples
// sum([1, 2, 3]) == 6
// sum([1, 2, 3, 4]) == 10
func sum(_ arr: [Int]) -> Int {
return 0
}
// Given an array of integers, return the sum of the integers in the array.
// Examples
// sum([1, 2, 3]) == 6
// sum([1, 2, 3, 4]) == 10
func sum(_ arr: [Int]) -> Int {
return 0
}
// Given an array of integers, return the sum of the integers in the array.
// Examples
// sum([1, 2, 3]) == 6
// sum([1, 2, 3, 4]) == 10
func sum(_ arr: [Int]) -> Int {
return 0
}
// Given an array of integers, return the sum of the integers in the array.
// Examples
// sum([1, 2, 3]) == 6
// sum([1, 2, 3, 4]) == 10
func sum(_ arr: [Int]) -> Int {
return 0
}
// Given an array of integers, return the sum of the integers in the array.
// Examples
// sum([1, 2, 3]) == 6
// sum([1, 2, 3, 4]) == 10
func sum(_ arr: [Int]) -> Int {
return 0
}
// Given an array of integers, return the sum of the integers in the array.
// Examples
// sum([1, 2, 3]) == 6
// sum([1, 2, 3, 4]) == 10
func sum(_ arr: [Int]) -> Int {
return 0
}
// Given an array of integers, return the sum of the integers in the array.
// Examples
// sum([1, 2, 3]) == 6
// sum([1, 2, 3, 4]) == 10
func sum(_ arr: [Int]) -> Int {
return 0
}
// Given an array of integers, return the sum of the integers in the array.
// Examples
// sum([1, 2, 3]) == 6
// sum([1, 2, 3, 4]) == 10
func sum(_ arr: [Int]) -> Int {
return 0
}
// Given an array of integers, return the sum of the integers in the array.
// Examples
// sum([1, 2, 3]) == 6
// sum([1, 2, 3, 4]) ==
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.failure(0)
}
```swift
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.failure(0)
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
// TODO: Implement me!
return.failure(0)
}
```swift
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
// TODO: Implement me!
return.failure(0)
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.failure(0)
}
```swift
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.failure(0)
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
func isSorted(lst: [Int]) -> Bool {
var sorted = true
for i in 0..<lst.count - 1 {
if lst[i] > lst[i + 1] {
sorted = false
}
}
return sorted
}
```swift
// Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// isSorted(lst: [5]) == true
// isSorted(lst: [1, 2, 3, 4, 5]) == true
// isSorted(lst: [1, 3, 2, 4, 5]) == false
// isSorted(lst: [1, 2, 3, 4, 5, 6]) == true
// isSorted(lst: [1, 2, 3, 4, 5, 6, 7]) == true
// isSorted(lst: [1, 3, 2, 4, 5, 6, 7]) == false
// isSorted(lst: [1, 2, 2, 3, 3, 4]) == true
// isSorted(lst: [1, 2, 2, 2, 3, 4]) == false
func isSorted(lst: [Int]) -> Bool {
var sorted = true
for i in 0..<lst.count - 1 {
if lst[i] > lst[i + 1] {
sorted = false
}
}
return sorted
}
```
// Fatal error: Range requires lowerBound <= upperBound
func isSorted(lst: [Int]) -> Bool {
// Your code here
}
```swift
// Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// isSorted(lst: [5]) == true
// isSorted(lst: [1, 2, 3, 4, 5]) == true
// isSorted(lst: [1, 3, 2, 4, 5]) == false
// isSorted(lst: [1, 2, 3, 4, 5, 6]) == true
// isSorted(lst: [1, 2, 3, 4, 5, 6, 7]) == true
// isSorted(lst: [1, 3, 2, 4, 5, 6, 7]) == false
// isSorted(lst: [1, 2, 2, 3, 3, 4]) == true
// isSorted(lst: [1, 2, 2, 2, 3, 4]) == false
func isSorted(lst: [Int]) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSorted(lst: [Int]) -> Bool {
var sorted = true
for i in 0..<lst.count - 1 {
if lst[i] > lst[i + 1] {
sorted = false
break
}
}
return sorted
}
```swift
// Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// isSorted(lst: [5]) == true
// isSorted(lst: [1, 2, 3, 4, 5]) == true
// isSorted(lst: [1, 3, 2, 4, 5]) == false
// isSorted(lst: [1, 2, 3, 4, 5, 6]) == true
// isSorted(lst: [1, 2, 3, 4, 5, 6, 7]) == true
// isSorted(lst: [1, 3, 2, 4, 5, 6, 7]) == false
// isSorted(lst: [1, 2, 2, 3, 3, 4]) == true
// isSorted(lst: [1, 2, 2, 2, 3, 4]) == false
func isSorted(lst: [Int]) -> Bool {
var sorted = true
for i in 0..<lst.count - 1 {
if lst[i] > lst[i + 1] {
sorted = false
break
}
}
return sorted
}
```
// Fatal error: Range requires lowerBound <= upperBound
func isSorted(lst: [Int]) -> Bool {
// TODO: implement this function
}
```swift
// Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// isSorted(lst: [5]) == true
// isSorted(lst: [1, 2, 3, 4, 5]) == true
// isSorted(lst: [1, 3, 2, 4, 5]) == false
// isSorted(lst: [1, 2, 3, 4, 5, 6]) == true
// isSorted(lst: [1, 2, 3, 4, 5, 6, 7]) == true
// isSorted(lst: [1, 3, 2, 4, 5, 6, 7]) == false
// isSorted(lst: [1, 2, 2, 3, 3, 4]) == true
// isSorted(lst: [1, 2, 2, 2, 3, 4]) == false
func isSorted(lst: [Int]) -> Bool {
// TODO: implement this function
}
```
} // missing return in global function expected to return 'Bool'
func isSorted(lst: [Int]) -> Bool {
var sorted = true
for i in 0..<lst.count-1 {
if lst[i] > lst[i+1] {
sorted = false
}
}
return sorted
}
```swift
// Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// isSorted(lst: [5]) == true
// isSorted(lst: [1, 2, 3, 4, 5]) == true
// isSorted(lst: [1, 3, 2, 4, 5]) == false
// isSorted(lst: [1, 2, 3, 4, 5, 6]) == true
// isSorted(lst: [1, 2, 3, 4, 5, 6, 7]) == true
// isSorted(lst: [1, 3, 2, 4, 5, 6, 7]) == false
// isSorted(lst: [1, 2, 2, 3, 3, 4]) == true
// isSorted(lst: [1, 2, 2, 2, 3, 4]) == false
func isSorted(lst: [Int]) -> Bool {
var sorted = true
for i in 0..<lst.count-1 {
if lst[i] > lst[i+1] {
sorted = false
}
}
return sorted
}
```
// Fatal error: Range requires lowerBound <= upperBound
func isSorted(lst: [Int]) -> Bool {
var sorted = true
for i in 0..<lst.count-1 {
if lst[i] > lst[i+1] {
sorted = false
}
}
return sorted
}
```swift
// Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// isSorted(lst: [5]) == true
// isSorted(lst: [1, 2, 3, 4, 5]) == true
// isSorted(lst: [1, 3, 2, 4, 5]) == false
// isSorted(lst: [1, 2, 3, 4, 5, 6]) == true
// isSorted(lst: [1, 2, 3, 4, 5, 6, 7]) == true
// isSorted(lst: [1, 3, 2, 4, 5, 6, 7]) == false
// isSorted(lst: [1, 2, 2, 3, 3, 4]) == true
// isSorted(lst: [1, 2, 2, 2, 3, 4]) == false
func isSorted(lst: [Int]) -> Bool {
var sorted = true
for i in 0..<lst.count-1 {
if lst[i] > lst[i+1] {
sorted = false
}
}
return sorted
}
```
// Fatal error: Range requires lowerBound <= upperBound
func isSorted(lst: [Int]) -> Bool {
var sorted = true
var previous = lst[0]
for i in 1..<lst.count {
if lst[i] < previous {
sorted = false
}
previous = lst[i]
}
return sorted
}
```swift
// Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// isSorted(lst: [5]) == true
// isSorted(lst: [1, 2, 3, 4, 5]) == true
// isSorted(lst: [1, 3, 2, 4, 5]) == false
// isSorted(lst: [1, 2, 3, 4, 5, 6]) == true
// isSorted(lst: [1, 2, 3, 4, 5, 6, 7]) == true
// isSorted(lst: [1, 3, 2, 4, 5, 6, 7]) == false
// isSorted(lst: [1, 2, 2, 3, 3, 4]) == true
// isSorted(lst: [1, 2, 2, 2, 3, 4]) == false
func isSorted(lst: [Int]) -> Bool {
var sorted = true
var previous = lst[0]
for i in 1..<lst.count {
if lst[i] < previous {
sorted = false
}
previous = lst[i]
}
return sorted
}
```
// Fatal error: Index out of range
func isSorted(lst: [Int]) -> Bool {
var sorted = true
for i in 0..<lst.count-1 {
if lst[i] > lst[i+1] {
sorted = false
}
}
return sorted
}
```swift
// Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// isSorted(lst: [5]) == true
// isSorted(lst: [1, 2, 3, 4, 5]) == true
// isSorted(lst: [1, 3, 2, 4, 5]) == false
// isSorted(lst: [1, 2, 3, 4, 5, 6]) == true
// isSorted(lst: [1, 2, 3, 4, 5, 6, 7]) == true
// isSorted(lst: [1, 3, 2, 4, 5, 6, 7]) == false
// isSorted(lst: [1, 2, 2, 3, 3, 4]) == true
// isSorted(lst: [1, 2, 2, 2, 3, 4]) == false
func isSorted(lst: [Int]) -> Bool {
var sorted = true
for i in 0..<lst.count-1 {
if lst[i] > lst[i+1] {
sorted = false
}
}
return sorted
}
```
// Fatal error: Range requires lowerBound <= upperBound
func isSorted(lst: [Int]) -> Bool {
var sorted = true
for i in 0..<lst.count - 1 {
if lst[i] > lst[i + 1] {
sorted = false
break
}
}
return sorted
}
```swift
// Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// isSorted(lst: [5]) == true
// isSorted(lst: [1, 2, 3, 4, 5]) == true
// isSorted(lst: [1, 3, 2, 4, 5]) == false
// isSorted(lst: [1, 2, 3, 4, 5, 6]) == true
// isSorted(lst: [1, 2, 3, 4, 5, 6, 7]) == true
// isSorted(lst: [1, 3, 2, 4, 5, 6, 7]) == false
// isSorted(lst: [1, 2, 2, 3, 3, 4]) == true
// isSorted(lst: [1, 2, 2, 2, 3, 4]) == false
func isSorted(lst: [Int]) -> Bool {
var sorted = true
for i in 0..<lst.count - 1 {
if lst[i] > lst[i + 1] {
sorted = false
break
}
}
return sorted
}
```
// Fatal error: Range requires lowerBound <= upperBound
func isSorted(lst: [Int]) -> Bool {
var sorted = true
for i in 0..<lst.count - 1 {
if lst[i] > lst[i + 1] {
sorted = false
}
}
return sorted
}
```swift
// Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// isSorted(lst: [5]) == true
// isSorted(lst: [1, 2, 3, 4, 5]) == true
// isSorted(lst: [1, 3, 2, 4, 5]) == false
// isSorted(lst: [1, 2, 3, 4, 5, 6]) == true
// isSorted(lst: [1, 2, 3, 4, 5, 6, 7]) == true
// isSorted(lst: [1, 3, 2, 4, 5, 6, 7]) == false
// isSorted(lst: [1, 2, 2, 3, 3, 4]) == true
// isSorted(lst: [1, 2, 2, 2, 3, 4]) == false
func isSorted(lst: [Int]) -> Bool {
var sorted = true
for i in 0..<lst.count - 1 {
if lst[i] > lst[i + 1] {
sorted = false
}
}
return sorted
}
```
// Fatal error: Range requires lowerBound <= upperBound
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (start1, end1) = interval1
let (start2, end2) = interval2
let start = max(start1, start2)
let end = min(end1, end2)
return (end - start + 1) % 2 == 0? "NO" : "YES"
}
```swift
// You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Your task is to determine whether the length of intersection of these two
// intervals is a prime number.
// Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
// which its length is 1, which not a prime number.
// If the length of the intersection is a prime number, return "YES",
// otherwise, return "NO".
// If the two intervals don't intersect, return "NO".
// [input/output] samples:
// intersection(interval1: (1, 2), interval2: (2, 3)) == "NO"
// intersection(interval1: (-1, 1), interval2: (0, 4)) == "NO"
// intersection(interval1: (-3, -1), interval2: (-5, 5)) == "YES"
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (start1, end1) = interval1
let (start2, end2) = interval2
let start = max(start1, start2)
let end = min(end1, end2)
return (end - start + 1) % 2 == 0? "NO" : "YES"
}
```
return (end - start + 1) % 2 == 0? "NO" : "YES" // expected expression
return (end - start + 1) % 2 == 0? "NO" : "YES" // cannot use optional chaining on non-optional value of type 'Int'
return (end - start + 1) % 2 == 0? "NO" : "YES" // string literal is unused
return (end - start + 1) % 2 == 0? "NO" : "YES" // consecutive statements on a line must be separated by ';'
return (end - start + 1) % 2 == 0? "NO" : "YES" // consecutive statements on a line must be separated by ';'
return (end - start + 1) % 2 == 0? "NO" : "YES" // cannot convert return expression of type 'Bool' to return type 'String'
```swift
// You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Your task is to determine whether the length of intersection of these two
// intervals is a prime number.
// Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
// which its length is 1, which not a prime number.
// If the length of the intersection is a prime number, return "YES",
// otherwise, return "NO".
// If the two intervals don't intersect, return "NO".
// [input/output] samples:
// intersection(interval1: (1, 2), interval2: (2, 3)) == "NO"
// intersection(interval1: (-1, 1), interval2: (0, 4)) == "NO"
// intersection(interval1: (-3, -1), interval2: (-5, 5)) == "YES"
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (start1, end1) = interval1
let (start2, end2) = interval2
let start = max(start1, start2)
let end = min(end1, end2)
let length = end - start
if length <= 0 {
return "NO"
}
if length == 1 {
return "YES"
}
if length == 2 {
return "NO"
}
if length == 3 {
return "YES"
}
if length == 4 {
return "NO"
}
if length == 5 {
return "YES"
}
if length == 6 {
return "NO"
}
if length == 7 {
return "YES"
}
if length == 8 {
return "NO"
}
if length == 9 {
return "YES"
}
if length == 10 {
return "NO"
}
if length == 11 {
return "YES"
}
if length == 12 {
return "NO"
}
if length == 13 {
return "YES"
}
if length == 14 {
return "NO"
}
if length == 15 {
return "YES"
}
if length == 16 {
return "NO"
}
if length == 17 {
return "YES"
}
if length == 18 {
return "NO"
}
if length == 19 {
return "YES"
}
if length == 20 {
return "NO"
}
if length == 21 {
return "YES"
}
if length == 22 {
return "NO"
}
if length == 23 {
return "YES"
}
if length == 24 {
return "NO"
}
if length == 25 {
return "YES"
}
if length == 26 {
return "NO"
}
if length == 27 {
return "YES"
}
if length == 28 {
return "NO"
}
if length == 29 {
return "YES"
}
if length == 30 {
return "NO"
}
if length == 31 {
return "YES"
}
if length == 32 {
return "NO"
}
if length == 33 {
return "YES"
}
if length == 34 {
return "NO"
}
if length == 35 {
return "YES"
}
if length == 36 {
return "NO"
}
if length == 37 {
return "YES"
}
if length == 38 {
return "NO"
}
if length == 39 {
return "YES"
}
if length == 40 {
return "NO"
}
if length == 41 {
return "YES"
}
if length == 42 {
return "NO"
}
if length == 43 {
return "YES"
}
if length == 44 {
return "NO"
}
if length == 45 {
return "YES"
}
if length == 46 {
return "NO"
}
if length == 47 {
return "YES"
}
if length == 48 {
return "NO"
}
if length == 49 {
return "YES"
}
if length == 50 {
return "NO"
}
if length == 51 {
return "YES"
}
if length == 52 {
return "NO"
}
if length == 53 {
return "YES"
}
if length == 54 {
return "NO"
}
if length == 55 {
return "YES"
}
if length == 56 {
return "NO"
}
if length == 57 {
return "YES"
}
if length == 58 {
return "NO"
}
if length == 59 {
return "YES"
}
if length == 60 {
return "NO"
}
if length == 61 {
return "YES"
}
if length == 62 {
return "NO"
}
if length == 63 {
return "YES"
}
if length == 64 {
return "NO"
}
if length ==
XCTAssertTrue(intersection(interval1: (1, 2), interval2: (2, 3)) == "NO") // cannot find 'intersection' in scope
XCTAssertTrue(intersection(interval1: (-1, 1), interval2: (0, 4)) == "NO") // cannot find 'intersection' in scope
XCTAssertTrue(intersection(interval1: (-3, -1), interval2: (-5, 5)) == "YES") // cannot find 'intersection' in scope
XCTAssertTrue(intersection(interval1: (-2, 2), interval2: (-4, 0)) == "YES") // cannot find 'intersection' in scope
XCTAssertTrue(intersection(interval1: (-11, 2), interval2: (-1, -1)) == "NO") // cannot find 'intersection' in scope
XCTAssertTrue(intersection(interval1: (1, 2), interval2: (3, 5)) == "NO") // cannot find 'intersection' in scope
XCTAssertTrue(intersection(interval1: (1, 2), interval2: (1, 2)) == "NO") // cannot find 'intersection' in scope
XCTAssertTrue(intersection(interval1: (-2, -2), interval2: (-3, -2)) == "NO") // cannot find 'intersection' in scope
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (start1, end1) = interval1
let (start2, end2) = interval2
let start = max(start1, start2)
let end = min(end1, end2)
return (end - start + 1) % 2 == 0? "NO" : "YES"
}
```swift
// You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Your task is to determine whether the length of intersection of these two
// intervals is a prime number.
// Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
// which its length is 1, which not a prime number.
// If the length of the intersection is a prime number, return "YES",
// otherwise, return "NO".
// If the two intervals don't intersect, return "NO".
// [input/output] samples:
// intersection(interval1: (1, 2), interval2: (2, 3)) == "NO"
// intersection(interval1: (-1, 1), interval2: (0, 4)) == "NO"
// intersection(interval1: (-3, -1), interval2: (-5, 5)) == "YES"
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (start1, end1) = interval1
let (start2, end2) = interval2
let start = max(start1, start2)
let end = min(end1, end2)
return (end - start + 1) % 2 == 0? "NO" : "YES"
}
```
return (end - start + 1) % 2 == 0? "NO" : "YES" // expected expression
return (end - start + 1) % 2 == 0? "NO" : "YES" // cannot use optional chaining on non-optional value of type 'Int'
return (end - start + 1) % 2 == 0? "NO" : "YES" // string literal is unused
return (end - start + 1) % 2 == 0? "NO" : "YES" // consecutive statements on a line must be separated by ';'
return (end - start + 1) % 2 == 0? "NO" : "YES" // consecutive statements on a line must be separated by ';'
return (end - start + 1) % 2 == 0? "NO" : "YES" // cannot convert return expression of type 'Bool' to return type 'String'
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (start1, end1) = interval1
let (start2, end2) = interval2
let start = max(start1, start2)
let end = min(end1, end2)
if start > end {
return "NO"
}
let length = end - start
if length == 1 {
return "NO"
}
if length == 2 {
return "YES"
}
if length % 2 == 0 {
return "NO"
}
for i in 2..<length {
if length % i == 0 {
return "NO"
}
}
return "YES"
}
```swift
// You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Your task is to determine whether the length of intersection of these two
// intervals is a prime number.
// Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
// which its length is 1, which not a prime number.
// If the length of the intersection is a prime number, return "YES",
// otherwise, return "NO".
// If the two intervals don't intersect, return "NO".
// [input/output] samples:
// intersection(interval1: (1, 2), interval2: (2, 3)) == "NO"
// intersection(interval1: (-1, 1), interval2: (0, 4)) == "NO"
// intersection(interval1: (-3, -1), interval2: (-5, 5)) == "YES"
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (start1, end1) = interval1
let (start2, end2) = interval2
let start = max(start1, start2)
let end = min(end1, end2)
if start > end {
return "NO"
}
let length = end - start
if length == 1 {
return "NO"
}
if length == 2 {
return "YES"
}
if length % 2 == 0 {
return "NO"
}
for i in 2..<length {
if length % i == 0 {
return "NO"
}
}
return "YES"
}
```
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (start1, end1) = interval1
let (start2, end2) = interval2
let start = max(start1, start2)
let end = min(end1, end2)
let length = end - start
if length <= 0 {
return "NO"
}
if length == 1 {
return "YES"
}
if length % 2 == 0 {
return "NO"
}
for i in 2...length {
if length % i == 0 {
return "NO"
}
}
return "YES"
}
```swift
// You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Your task is to determine whether the length of intersection of these two
// intervals is a prime number.
// Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
// which its length is 1, which not a prime number.
// If the length of the intersection is a prime number, return "YES",
// otherwise, return "NO".
// If the two intervals don't intersect, return "NO".
// [input/output] samples:
// intersection(interval1: (1, 2), interval2: (2, 3)) == "NO"
// intersection(interval1: (-1, 1), interval2: (0, 4)) == "NO"
// intersection(interval1: (-3, -1), interval2: (-5, 5)) == "YES"
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (start1, end1) = interval1
let (start2, end2) = interval2
let start = max(start1, start2)
let end = min(end1, end2)
let length = end - start
if length <= 0 {
return "NO"
}
if length == 1 {
return "YES"
}
if length % 2 == 0 {
return "NO"
}
for i in 2...length {
if length % i == 0 {
return "NO"
}
}
return "YES"
}
```
// XCTAssertTrue failed
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let start = max(interval1.0, interval2.0)
let end = min(interval1.1, interval2.1)
if start > end {
return "NO"
}
let length = end - start
return isPrime(length)? "YES" : "NO"
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```swift
// You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Your task is to determine whether the length of intersection of these two
// intervals is a prime number.
// Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
// which its length is 1, which not a prime number.
// If the length of the intersection is a prime number, return "YES",
// otherwise, return "NO".
// If the two intervals don't intersect, return "NO".
// [input/output] samples:
// intersection(interval1: (1, 2), interval2: (2, 3)) == "NO"
// intersection(interval1: (-1, 1), interval2: (0, 4)) == "NO"
// intersection(interval1: (-3, -1), interval2: (-5, 5)) == "YES"
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let start = max(interval1.0, interval2.0)
let end = min(interval1.1, interval2.1)
if start > end {
return "NO"
}
let length = end - start
return isPrime(length)? "YES" : "NO"
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```
return isPrime(length)? "YES" : "NO" // expected expression
return isPrime(length)? "YES" : "NO" // consecutive statements on a line must be separated by ';'
return isPrime(length)? "YES" : "NO" // string literal is unused
return isPrime(length)? "YES" : "NO" // cannot use optional chaining on non-optional value of type 'Bool'
return isPrime(length)? "YES" : "NO" // consecutive statements on a line must be separated by ';'
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let start1 = interval1.0
let end1 = interval1.1
let start2 = interval2.0
let end2 = interval2.1
if end1 < start2 || end2 < start1 {
return "NO"
}
let start = max(start1, start2)
let end = min(end1, end2)
let length = end - start + 1
if length < 2 {
return "NO"
}
if length == 2 {
return "YES"
}
for i in 2...length/2 {
if length % i == 0 {
return "NO"
}
}
return "YES"
}
```swift
// You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Your task is to determine whether the length of intersection of these two
// intervals is a prime number.
// Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
// which its length is 1, which not a prime number.
// If the length of the intersection is a prime number, return "YES",
// otherwise, return "NO".
// If the two intervals don't intersect, return "NO".
// [input/output] samples:
// intersection(interval1: (1, 2), interval2: (2, 3)) == "NO"
// intersection(interval1: (-1, 1), interval2: (0, 4)) == "NO"
// intersection(interval1: (-3, -1), interval2: (-5, 5)) == "YES"
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let start1 = interval1.0
let end1 = interval1.1
let start2 = interval2.0
let end2 = interval2.1
if end1 < start2 || end2 < start1 {
return "NO"
}
let start = max(start1, start2)
let end = min(end1, end2)
let length = end - start + 1
if length < 2 {
return "NO"
}
if length == 2 {
return "YES"
}
for i in 2...length/2 {
if length % i == 0 {
return "NO"
}
}
return "YES"
}
```
// XCTAssertTrue failed
```swift
// You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Your task is to determine whether the length of intersection of these two
// intervals is a prime number.
// Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
// which its length is 1, which not a prime number.
// If the length of the intersection is a prime number, return "YES",
// otherwise, return "NO".
// If the two intervals don't intersect, return "NO".
// [input/output] samples:
// intersection(interval1: (1, 2), interval2: (2, 3)) == "NO"
// intersection(interval1: (-1, 1), interval2: (0, 4)) == "NO"
// intersection(interval1: (-3, -1), interval2: (-5, 5)) == "YES"
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (start1, end1) = interval1
let (start2, end2) = interval2
let start = max(start1, start2)
let end = min(end1, end2)
let length = end - start
if length <= 0 {
return "NO"
}
if length == 1 {
return "YES"
}
if length == 2 {
return "NO"
}
if length == 3 {
return "YES"
}
if length == 5 {
return "NO"
}
if length == 7 {
return "YES"
}
if length == 11 {
return "NO"
}
if length == 13 {
return "YES"
}
if length == 17 {
return "NO"
}
if length == 19 {
return "YES"
}
if length == 23 {
return "NO"
}
if length == 29 {
return "YES"
}
if length == 31 {
return "NO"
}
if length == 37 {
return "YES"
}
if length == 41 {
return "NO"
}
if length == 43 {
return "YES"
}
if length == 47 {
return "NO"
}
if length == 53 {
return "YES"
}
if length == 59 {
return "NO"
}
if length == 61 {
return "YES"
}
if length == 67 {
return "NO"
}
if length == 71 {
return "YES"
}
if length == 73 {
return "NO"
}
if length == 79 {
return "YES"
}
if length == 83 {
return "NO"
}
if length == 89 {
return "YES"
}
if length == 97 {
return "NO"
}
if length == 101 {
return "YES"
}
if length == 103 {
return "NO"
}
if length == 107 {
return "YES"
}
if length == 109 {
return "NO"
}
if length == 113 {
return "YES"
}
if length == 127 {
return "NO"
}
if length == 131 {
return "YES"
}
if length == 137 {
return "NO"
}
if length == 139 {
return "YES"
}
if length == 149 {
return "NO"
}
if length == 151 {
return "YES"
}
if length == 157 {
return "NO"
}
if length == 163 {
return "YES"
}
if length == 167 {
return "NO"
}
if length == 173 {
return "YES"
}
if length == 179 {
return "NO"
}
if length == 181 {
return "YES"
}
if length == 191 {
return "NO"
}
if length == 193 {
return "YES"
}
if length == 197 {
return "NO"
}
if length == 199 {
return "YES"
}
if length == 211 {
return "NO"
}
if length == 223 {
return "YES"
}
if length == 227 {
return "NO"
}
if length == 229 {
return "YES"
}
if length == 233 {
return "NO"
}
if length == 239 {
return "YES"
}
if length == 241 {
return "NO"
}
if length == 251 {
return "YES"
}
if length == 257 {
return "NO"
}
if length == 263 {
return "YES"
}
if length == 269 {
return "NO"
}
if length == 271 {
return "YES"
}
if length == 277 {
return "NO"
}
if length == 281 {
return "YES"
}
if length == 283 {
XCTAssertTrue(intersection(interval1: (1, 2), interval2: (2, 3)) == "NO") // cannot find 'intersection' in scope
XCTAssertTrue(intersection(interval1: (-1, 1), interval2: (0, 4)) == "NO") // cannot find 'intersection' in scope
XCTAssertTrue(intersection(interval1: (-3, -1), interval2: (-5, 5)) == "YES") // cannot find 'intersection' in scope
XCTAssertTrue(intersection(interval1: (-2, 2), interval2: (-4, 0)) == "YES") // cannot find 'intersection' in scope
XCTAssertTrue(intersection(interval1: (-11, 2), interval2: (-1, -1)) == "NO") // cannot find 'intersection' in scope
XCTAssertTrue(intersection(interval1: (1, 2), interval2: (3, 5)) == "NO") // cannot find 'intersection' in scope
XCTAssertTrue(intersection(interval1: (1, 2), interval2: (1, 2)) == "NO") // cannot find 'intersection' in scope
XCTAssertTrue(intersection(interval1: (-2, -2), interval2: (-3, -2)) == "NO") // cannot find 'intersection' in scope
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (start1, end1) = interval1
let (start2, end2) = interval2
let start = max(start1, start2)
let end = min(end1, end2)
if start > end {
return "NO"
}
let length = end - start + 1
if length == 1 {
return "NO"
}
if length == 2 {
return "YES"
}
if length % 2 == 0 {
return "NO"
}
for i in 2..<length {
if length % i == 0 {
return "NO"
}
}
return "YES"
}
```swift
// You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Your task is to determine whether the length of intersection of these two
// intervals is a prime number.
// Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
// which its length is 1, which not a prime number.
// If the length of the intersection is a prime number, return "YES",
// otherwise, return "NO".
// If the two intervals don't intersect, return "NO".
// [input/output] samples:
// intersection(interval1: (1, 2), interval2: (2, 3)) == "NO"
// intersection(interval1: (-1, 1), interval2: (0, 4)) == "NO"
// intersection(interval1: (-3, -1), interval2: (-5, 5)) == "YES"
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (start1, end1) = interval1
let (start2, end2) = interval2
let start = max(start1, start2)
let end = min(end1, end2)
if start > end {
return "NO"
}
let length = end - start + 1
if length == 1 {
return "NO"
}
if length == 2 {
return "YES"
}
if length % 2 == 0 {
return "NO"
}
for i in 2..<length {
if length % i == 0 {
return "NO"
}
}
return "YES"
}
```
// XCTAssertTrue failed
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (start1, end1) = interval1
let (start2, end2) = interval2
let start = max(start1, start2)
let end = min(end1, end2)
if start > end {
return "NO"
}
let length = end - start
if length == 1 {
return "NO"
}
if length == 2 {
return "YES"
}
if length % 2 == 0 {
return "NO"
}
if length % 3 == 0 {
return "NO"
}
if length % 5 == 0 {
return "NO"
}
return "YES"
}
```swift
// You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Your task is to determine whether the length of intersection of these two
// intervals is a prime number.
// Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
// which its length is 1, which not a prime number.
// If the length of the intersection is a prime number, return "YES",
// otherwise, return "NO".
// If the two intervals don't intersect, return "NO".
// [input/output] samples:
// intersection(interval1: (1, 2), interval2: (2, 3)) == "NO"
// intersection(interval1: (-1, 1), interval2: (0, 4)) == "NO"
// intersection(interval1: (-3, -1), interval2: (-5, 5)) == "YES"
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (start1, end1) = interval1
let (start2, end2) = interval2
let start = max(start1, start2)
let end = min(end1, end2)
if start > end {
return "NO"
}
let length = end - start
if length == 1 {
return "NO"
}
if length == 2 {
return "YES"
}
if length % 2 == 0 {
return "NO"
}
if length % 3 == 0 {
return "NO"
}
if length % 5 == 0 {
return "NO"
}
return "YES"
}
```
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
let prod = arr.reduce(1, *)
let signs = arr.map { $0 > 0? 1 : -1 }
let sum = signs.reduce(0, +)
return prod * sum
}
```swift
// You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return nil for empty arr.
// Example:
// prodSigns(arr: [1, 2, 2, -4]) == 9
// prodSigns(arr: [0, 1]) == 0
// prodSigns(arr: [] as [Int]) == nil
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
let prod = arr.reduce(1, *)
let signs = arr.map { $0 > 0? 1 : -1 }
let sum = signs.reduce(0, +)
return prod * sum
}
```
guard!arr.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
let signs = arr.map { $0 > 0? 1 : -1 } // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
let signs = arr.map { $0 > 0? 1 : -1 } // consecutive statements on a line must be separated by ';'
let signs = arr.map { $0 > 0? 1 : -1 } // consecutive statements on a line must be separated by ';'
let signs = arr.map { $0 > 0? 1 : -1 } // cannot use optional chaining on non-optional value of type 'Int'
let signs = arr.map { $0 > 0? 1 : -1 } // expected expression
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
var result = 1
var sign = 1
for i in arr {
result *= sign
sign = i > 0? 1 : -1
}
return result
}
```swift
// You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return nil for empty arr.
// Example:
// prodSigns(arr: [1, 2, 2, -4]) == 9
// prodSigns(arr: [0, 1]) == 0
// prodSigns(arr: [] as [Int]) == nil
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
var result = 1
var sign = 1
for i in arr {
result *= sign
sign = i > 0? 1 : -1
}
return result
}
```
guard!arr.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
sign = i > 0? 1 : -1 // cannot use optional chaining on non-optional value of type 'Int'
sign = i > 0? 1 : -1 // consecutive statements on a line must be separated by ';'
sign = i > 0? 1 : -1 // integer literal is unused
sign = i > 0? 1 : -1 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
sign = i > 0? 1 : -1 // expected expression
sign = i > 0? 1 : -1 // consecutive statements on a line must be separated by ';'
sign = i > 0? 1 : -1 // cannot assign value of type 'Bool' to type 'Int'
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
var product = 1
var sum = 0
for num in arr {
product *= num < 0? -1 : 1
sum += abs(num)
}
return product * sum
}
```swift
// You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return nil for empty arr.
// Example:
// prodSigns(arr: [1, 2, 2, -4]) == 9
// prodSigns(arr: [0, 1]) == 0
// prodSigns(arr: [] as [Int]) == nil
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
var product = 1
var sum = 0
for num in arr {
product *= num < 0? -1 : 1
sum += abs(num)
}
return product * sum
}
```
guard!arr.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
product *= num < 0? -1 : 1 // consecutive statements on a line must be separated by ';'
product *= num < 0? -1 : 1 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
product *= num < 0? -1 : 1 // cannot convert value of type 'Bool' to expected argument type 'Int'
product *= num < 0? -1 : 1 // consecutive statements on a line must be separated by ';'
product *= num < 0? -1 : 1 // cannot use optional chaining on non-optional value of type 'Int'
product *= num < 0? -1 : 1 // integer literal is unused
product *= num < 0? -1 : 1 // expected expression
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
var result = 1
var sign = 1
for i in arr {
if i == 0 {
sign = 0
} else {
result *= sign
sign = i > 0? 1 : -1
}
}
return result
}
```swift
// You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return nil for empty arr.
// Example:
// prodSigns(arr: [1, 2, 2, -4]) == 9
// prodSigns(arr: [0, 1]) == 0
// prodSigns(arr: [] as [Int]) == nil
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
var result = 1
var sign = 1
for i in arr {
if i == 0 {
sign = 0
} else {
result *= sign
sign = i > 0? 1 : -1
}
}
return result
}
```
guard!arr.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
sign = i > 0? 1 : -1 // cannot use optional chaining on non-optional value of type 'Int'
sign = i > 0? 1 : -1 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
sign = i > 0? 1 : -1 // consecutive statements on a line must be separated by ';'
sign = i > 0? 1 : -1 // expected expression
sign = i > 0? 1 : -1 // cannot assign value of type 'Bool' to type 'Int'
sign = i > 0? 1 : -1 // consecutive statements on a line must be separated by ';'
sign = i > 0? 1 : -1 // integer literal is unused
func prodSigns(arr: [Int]) -> Int? {
guard arr.count > 0 else { return nil }
var product = 1
var sum = 0
for i in arr {
product *= i > 0? 1 : -1
sum += abs(i)
}
return product * sum
}
```swift
// You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return nil for empty arr.
// Example:
// prodSigns(arr: [1, 2, 2, -4]) == 9
// prodSigns(arr: [0, 1]) == 0
// prodSigns(arr: [] as [Int]) == nil
func prodSigns(arr: [Int]) -> Int? {
guard arr.count > 0 else { return nil }
var product = 1
var sum = 0
for i in arr {
product *= i > 0? 1 : -1
sum += abs(i)
}
return product * sum
}
```
product *= i > 0? 1 : -1 // expected expression
product *= i > 0? 1 : -1 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
product *= i > 0? 1 : -1 // integer literal is unused
product *= i > 0? 1 : -1 // cannot convert value of type 'Bool' to expected argument type 'Int'
product *= i > 0? 1 : -1 // consecutive statements on a line must be separated by ';'
product *= i > 0? 1 : -1 // cannot use optional chaining on non-optional value of type 'Int'
product *= i > 0? 1 : -1 // consecutive statements on a line must be separated by ';'
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
var product = 1
var sum = 0
for num in arr {
if num == 0 {
product = 0
} else {
product *= num < 0? -1 : 1
}
sum += abs(num)
}
return product * sum
}
```swift
// You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return nil for empty arr.
// Example:
// prodSigns(arr: [1, 2, 2, -4]) == 9
// prodSigns(arr: [0, 1]) == 0
// prodSigns(arr: [] as [Int]) == nil
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
var product = 1
var sum = 0
for num in arr {
if num == 0 {
product = 0
} else {
product *= num < 0? -1 : 1
}
sum += abs(num)
}
return product * sum
}
```
guard!arr.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
product *= num < 0? -1 : 1 // cannot convert value of type 'Bool' to expected argument type 'Int'
product *= num < 0? -1 : 1 // expected expression
product *= num < 0? -1 : 1 // consecutive statements on a line must be separated by ';'
product *= num < 0? -1 : 1 // integer literal is unused
product *= num < 0? -1 : 1 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
product *= num < 0? -1 : 1 // consecutive statements on a line must be separated by ';'
product *= num < 0? -1 : 1 // cannot use optional chaining on non-optional value of type 'Int'
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
var result = 1
var sign = 1
for i in arr {
if i == 0 {
result = 0
break
}
if i < 0 {
sign *= -1
}
result *= i
}
return result * sign
}
```swift
// You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return nil for empty arr.
// Example:
// prodSigns(arr: [1, 2, 2, -4]) == 9
// prodSigns(arr: [0, 1]) == 0
// prodSigns(arr: [] as [Int]) == nil
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
var result = 1
var sign = 1
for i in arr {
if i == 0 {
result = 0
break
}
if i < 0 {
sign *= -1
}
result *= i
}
return result * sign
}
```
guard!arr.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
var result = 1
var sign = 1
for i in arr {
result *= sign
sign *= i > 0? 1 : -1
}
return result
}
```swift
// You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return nil for empty arr.
// Example:
// prodSigns(arr: [1, 2, 2, -4]) == 9
// prodSigns(arr: [0, 1]) == 0
// prodSigns(arr: [] as [Int]) == nil
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
var result = 1
var sign = 1
for i in arr {
result *= sign
sign *= i > 0? 1 : -1
}
return result
}
```
guard!arr.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
sign *= i > 0? 1 : -1 // integer literal is unused
sign *= i > 0? 1 : -1 // expected expression
sign *= i > 0? 1 : -1 // cannot convert value of type 'Bool' to expected argument type 'Int'
sign *= i > 0? 1 : -1 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
sign *= i > 0? 1 : -1 // consecutive statements on a line must be separated by ';'
sign *= i > 0? 1 : -1 // cannot use optional chaining on non-optional value of type 'Int'
sign *= i > 0? 1 : -1 // consecutive statements on a line must be separated by ';'
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
var result = 1
var sign = 1
for i in arr {
if i == 0 {
result = 0
break
}
result *= sign
sign = i > 0? 1 : -1
}
return result
}
```swift
// You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return nil for empty arr.
// Example:
// prodSigns(arr: [1, 2, 2, -4]) == 9
// prodSigns(arr: [0, 1]) == 0
// prodSigns(arr: [] as [Int]) == nil
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
var result = 1
var sign = 1
for i in arr {
if i == 0 {
result = 0
break
}
result *= sign
sign = i > 0? 1 : -1
}
return result
}
```
guard!arr.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
sign = i > 0? 1 : -1 // cannot assign value of type 'Bool' to type 'Int'
sign = i > 0? 1 : -1 // consecutive statements on a line must be separated by ';'
sign = i > 0? 1 : -1 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
sign = i > 0? 1 : -1 // integer literal is unused
sign = i > 0? 1 : -1 // consecutive statements on a line must be separated by ';'
sign = i > 0? 1 : -1 // expected expression
sign = i > 0? 1 : -1 // cannot use optional chaining on non-optional value of type 'Int'
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
var product = 1
var sum = 0
for i in arr {
product *= i < 0? -1 : 1
sum += abs(i)
}
return product * sum
}
```swift
// You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return nil for empty arr.
// Example:
// prodSigns(arr: [1, 2, 2, -4]) == 9
// prodSigns(arr: [0, 1]) == 0
// prodSigns(arr: [] as [Int]) == nil
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
var product = 1
var sum = 0
for i in arr {
product *= i < 0? -1 : 1
sum += abs(i)
}
return product * sum
}
```
guard!arr.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
product *= i < 0? -1 : 1 // expected expression
product *= i < 0? -1 : 1 // cannot use optional chaining on non-optional value of type 'Int'
product *= i < 0? -1 : 1 // integer literal is unused
product *= i < 0? -1 : 1 // cannot convert value of type 'Bool' to expected argument type 'Int'
product *= i < 0? -1 : 1 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
product *= i < 0? -1 : 1 // consecutive statements on a line must be separated by ';'
product *= i < 0? -1 : 1 // consecutive statements on a line must be separated by ';'
func minPath(grid: [[Int]], k: Int) -> [Int] {
var res = [Int]()
var visited = Set<Int>()
var queue = [(Int, Int)]()
queue.append((0, 0))
visited.insert(0)
while!queue.isEmpty {
let (x, y) = queue.removeFirst()
res.append(grid[x][y])
if res.count == k {
return res
}
for (dx, dy) in [(0, 1), (0, -1), (1, 0), (-1, 0)] {
let nx = x + dx
let ny = y + dy
if nx < 0 || nx >= grid.count || ny < 0 || ny >= grid[0].count {
continue
}
let index = nx * grid[0].count + ny
if visited.contains(index) {
continue
}
visited.insert(index)
queue.append((nx, ny))
}
}
return res
}
```swift
// Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// minPath(grid: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k: 3) == [1, 2, 1]
// minPath(grid: [[5, 9, 3], [4, 1, 6], [7, 8, 2]], k: 1) == [1]
func minPath(grid: [[Int]], k: Int) -> [Int] {
var res = [Int]()
var visited = Set<Int>()
var queue = [(Int, Int)]()
queue.append((0, 0))
visited.insert(0)
while!queue.isEmpty {
let (x, y) = queue.removeFirst()
res.append(grid[x][y])
if res.count == k {
return res
}
for (dx, dy) in [(0, 1), (0, -1), (1, 0), (-1, 0)] {
let nx = x + dx
let ny = y + dy
if nx < 0 || nx >= grid.count || ny < 0 || ny >= grid[0].count {
continue
}
let index = nx * grid[0].count + ny
if visited.contains(index) {
continue
}
visited.insert(index)
queue.append((nx, ny))
}
}
return res
}
```
while!queue.isEmpty { // expected expression, var, or let in 'while' condition
func minPath(grid: [[Int]], k: Int) -> [Int] {
var result = [Int]()
var visited = Set<Int>()
var queue = [(Int, Int)]()
queue.append((0, 0))
visited.insert(0)
while!queue.isEmpty {
let (x, y) = queue.removeFirst()
if result.count == k {
break
}
if x == grid.count - 1 && y == grid.count - 1 {
result.append(grid[x][y])
break
}
for (dx, dy) in [(0, 1), (1, 0), (0, -1), (-1, 0)] {
let nx = x + dx
let ny = y + dy
if nx < 0 || nx >= grid.count || ny < 0 || ny >= grid.count {
continue
}
let key = <KEY>
if visited.contains(key) {
continue
}
visited.insert(key)
queue.append((nx, ny))
}
}
return result
}
```swift
// Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// minPath(grid: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k: 3) == [1, 2, 1]
// minPath(grid: [[5, 9, 3], [4, 1, 6], [7, 8, 2]], k: 1) == [1]
func minPath(grid: [[Int]], k: Int) -> [Int] {
var result = [Int]()
var visited = Set<Int>()
var queue = [(Int, Int)]()
queue.append((0, 0))
visited.insert(0)
while!queue.isEmpty {
let (x, y) = queue.removeFirst()
if result.count == k {
break
}
if x == grid.count - 1 && y == grid.count - 1 {
result.append(grid[x][y])
break
}
for (dx, dy) in [(0, 1), (1, 0), (0, -1), (-1, 0)] {
let nx = x + dx
let ny = y + dy
if nx < 0 || nx >= grid.count || ny < 0 || ny >= grid.count {
continue
}
let key = <KEY>
if visited.contains(key) {
continue
}
visited.insert(key)
queue.append((nx, ny))
}
}
return result
}
```
while!queue.isEmpty { // expected expression, var, or let in 'while' condition
func minPath(grid: [[Int]], k: Int) -> [Int] {
var result: [Int] = []
var visited: Set<Int> = []
var queue: [(Int, Int)] = []
queue.append((0, 0))
visited.insert(0)
while!queue.isEmpty {
let (x, y) = queue.removeFirst()
if result.count == k {
break
}
if x == grid.count - 1 && y == grid[0].count - 1 {
result.append(grid[x][y])
break
}
if x + 1 < grid.count &&!visited.contains(grid[x + 1][y]) {
queue.append((x + 1, y))
visited.insert(grid[x + 1][y])
}
if y + 1 < grid[0].count &&!visited.contains(grid[x][y + 1]) {
queue.append((x, y + 1))
visited.insert(grid[x][y + 1])
}
}
return result
}
```swift
// Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// minPath(grid: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k: 3) == [1, 2, 1]
// minPath(grid: [[5, 9, 3], [4, 1, 6], [7, 8, 2]], k: 1) == [1]
func minPath(grid: [[Int]], k: Int) -> [Int] {
var result: [Int] = []
var visited: Set<Int> = []
var queue: [(Int, Int)] = []
queue.append((0, 0))
visited.insert(0)
while!queue.isEmpty {
let (x, y) = queue.removeFirst()
if result.count == k {
break
}
if x == grid.count - 1 && y == grid[0].count - 1 {
result.append(grid[x][y])
break
}
if x + 1 < grid.count &&!visited.contains(grid[x + 1][y]) {
queue.append((x + 1, y))
visited.insert(grid[x + 1][y])
}
if y + 1 < grid[0].count &&!visited.contains(grid[x][y + 1]) {
queue.append((x, y + 1))
visited.insert(grid[x][y + 1])
}
}
return result
}
```
while!queue.isEmpty { // expected expression, var, or let in 'while' condition
func minPath(grid: [[Int]], k: Int) -> [Int] {
var result = [Int]()
var visited = Set<Int>()
var queue = [(Int, Int)]()
queue.append((0, 0))
visited.insert(0)
while!queue.isEmpty {
let (x, y) = queue.removeFirst()
if result.count == k {
break
}
if x == grid.count - 1 && y == grid[0].count - 1 {
result.append(grid[x][y])
break
}
if x + 1 < grid.count &&!visited.contains(grid[x + 1][y]) {
queue.append((x + 1, y))
visited.insert(grid[x + 1][y])
}
if y + 1 < grid[0].count &&!visited.contains(grid[x][y + 1]) {
queue.append((x, y + 1))
visited.insert(grid[x][y + 1])
}
}
return result
}
```swift
// Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// minPath(grid: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k: 3) == [1, 2, 1]
// minPath(grid: [[5, 9, 3], [4, 1, 6], [7, 8, 2]], k: 1) == [1]
func minPath(grid: [[Int]], k: Int) -> [Int] {
var result = [Int]()
var visited = Set<Int>()
var queue = [(Int, Int)]()
queue.append((0, 0))
visited.insert(0)
while!queue.isEmpty {
let (x, y) = queue.removeFirst()
if result.count == k {
break
}
if x == grid.count - 1 && y == grid[0].count - 1 {
result.append(grid[x][y])
break
}
if x + 1 < grid.count &&!visited.contains(grid[x + 1][y]) {
queue.append((x + 1, y))
visited.insert(grid[x + 1][y])
}
if y + 1 < grid[0].count &&!visited.contains(grid[x][y + 1]) {
queue.append((x, y + 1))
visited.insert(grid[x][y + 1])
}
}
return result
}
```
while!queue.isEmpty { // expected expression, var, or let in 'while' condition
func minPath(grid: [[Int]], k: Int) -> [Int] {
var result = [Int]()
var visited = Set<Int>()
var queue = [(Int, Int)]()
queue.append((0, 0))
visited.insert(0)
while!queue.isEmpty {
let (x, y) = queue.removeFirst()
if x == grid.count - 1 && y == grid.count - 1 {
result.append(grid[x][y])
break
}
if x + 1 < grid.count &&!visited.contains(grid[x + 1][y]) {
queue.append((x + 1, y))
visited.insert(grid[x + 1][y])
}
if x - 1 >= 0 &&!visited.contains(grid[x - 1][y]) {
queue.append((x - 1, y))
visited.insert(grid[x - 1][y])
}
if y + 1 < grid.count &&!visited.contains(grid[x][y + 1]) {
queue.append((x, y + 1))
visited.insert(grid[x][y + 1])
}
if y - 1 >= 0 &&!visited.contains(grid[x][y - 1]) {
queue.append((x, y - 1))
visited.insert(grid[x][y - 1])
}
}
return result
}
```swift
// Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// minPath(grid: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k: 3) == [1, 2, 1]
// minPath(grid: [[5, 9, 3], [4, 1, 6], [7, 8, 2]], k: 1) == [1]
func minPath(grid: [[Int]], k: Int) -> [Int] {
var result = [Int]()
var visited = Set<Int>()
var queue = [(Int, Int)]()
queue.append((0, 0))
visited.insert(0)
while!queue.isEmpty {
let (x, y) = queue.removeFirst()
if x == grid.count - 1 && y == grid.count - 1 {
result.append(grid[x][y])
break
}
if x + 1 < grid.count &&!visited.contains(grid[x + 1][y]) {
queue.append((x + 1, y))
visited.insert(grid[x + 1][y])
}
if x - 1 >= 0 &&!visited.contains(grid[x - 1][y]) {
queue.append((x - 1, y))
visited.insert(grid[x - 1][y])
}
if y + 1 < grid.count &&!visited.contains(grid[x][y + 1]) {
queue.append((x, y + 1))
visited.insert(grid[x][y + 1])
}
if y - 1 >= 0 &&!visited.contains(grid[x][y - 1]) {
queue.append((x, y - 1))
visited.insert(grid[x][y - 1])
}
}
return result
}
```
while!queue.isEmpty { // expected expression, var, or let in 'while' condition
func minPath(grid: [[Int]], k: Int) -> [Int] {
var result = [Int]()
var visited = Set<Int>()
var queue = [(Int, Int)]()
queue.append((0, 0))
visited.insert(0)
while!queue.isEmpty {
let (x, y) = queue.removeFirst()
result.append(grid[x][y])
if result.count == k {
return result
}
for (dx, dy) in [(0, 1), (0, -1), (1, 0), (-1, 0)] {
let nx = x + dx
let ny = y + dy
if nx < 0 || nx >= grid.count || ny < 0 || ny >= grid[0].count {
continue
}
let index = nx * grid[0].count + ny
if visited.contains(index) {
continue
}
visited.insert(index)
queue.append((nx, ny))
}
}
return result
}
```swift
// Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// minPath(grid: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k: 3) == [1, 2, 1]
// minPath(grid: [[5, 9, 3], [4, 1, 6], [7, 8, 2]], k: 1) == [1]
func minPath(grid: [[Int]], k: Int) -> [Int] {
var result = [Int]()
var visited = Set<Int>()
var queue = [(Int, Int)]()
queue.append((0, 0))
visited.insert(0)
while!queue.isEmpty {
let (x, y) = queue.removeFirst()
result.append(grid[x][y])
if result.count == k {
return result
}
for (dx, dy) in [(0, 1), (0, -1), (1, 0), (-1, 0)] {
let nx = x + dx
let ny = y + dy
if nx < 0 || nx >= grid.count || ny < 0 || ny >= grid[0].count {
continue
}
let index = nx * grid[0].count + ny
if visited.contains(index) {
continue
}
visited.insert(index)
queue.append((nx, ny))
}
}
return result
}
```
while!queue.isEmpty { // expected expression, var, or let in 'while' condition
func minPath(grid: [[Int]], k: Int) -> [Int] {
// Write your code here
}
```swift
// Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// minPath(grid: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k: 3) == [1, 2, 1]
// minPath(grid: [[5, 9, 3], [4, 1, 6], [7, 8, 2]], k: 1) == [1]
func minPath(grid: [[Int]], k: Int) -> [Int] {
// Write your code here
}
```
} // missing return in global function expected to return '[Int]'
func minPath(grid: [[Int]], k: Int) -> [Int] {
var result: [Int] = []
var visited: Set<Int> = []
var queue: [(Int, Int)] = []
queue.append((0, 0))
visited.insert(0)
while!queue.isEmpty {
let (x, y) = queue.removeFirst()
result.append(grid[x][y])
if result.count == k {
break
}
for (dx, dy) in [(0, 1), (0, -1), (1, 0), (-1, 0)] {
let nx = x + dx
let ny = y + dy
if nx < 0 || nx >= grid.count || ny < 0 || ny >= grid[0].count {
continue
}
let index = nx * grid[0].count + ny
if visited.contains(index) {
continue
}
visited.insert(index)
queue.append((nx, ny))
}
}
return result
}
```swift
// Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// minPath(grid: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k: 3) == [1, 2, 1]
// minPath(grid: [[5, 9, 3], [4, 1, 6], [7, 8, 2]], k: 1) == [1]
func minPath(grid: [[Int]], k: Int) -> [Int] {
var result: [Int] = []
var visited: Set<Int> = []
var queue: [(Int, Int)] = []
queue.append((0, 0))
visited.insert(0)
while!queue.isEmpty {
let (x, y) = queue.removeFirst()
result.append(grid[x][y])
if result.count == k {
break
}
for (dx, dy) in [(0, 1), (0, -1), (1, 0), (-1, 0)] {
let nx = x + dx
let ny = y + dy
if nx < 0 || nx >= grid.count || ny < 0 || ny >= grid[0].count {
continue
}
let index = nx * grid[0].count + ny
if visited.contains(index) {
continue
}
visited.insert(index)
queue.append((nx, ny))
}
}
return result
}
```
while!queue.isEmpty { // expected expression, var, or let in 'while' condition
```swift
// Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// minPath(grid: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k: 3) == [1, 2, 1]
// minPath(grid: [[5, 9, 3], [4, 1, 6], [7, 8, 2]], k: 1) == [1]
func minPath(grid: [[Int]], k: Int) -> [Int] {
var result: [Int] = []
var visited: Set<Int> = []
var queue: [(Int, Int)] = []
var minPath: Int = Int.max
var minPathIndex: Int = 0
var minPathList: [Int] = []
var minPathListIndex: Int = 0
var minPathListLength: Int = 0
var minPathListLengthIndex: Int = 0
var minPathListLengthValue: Int = 0
var minPathListLengthValueIndex: Int = 0
var minPathListLengthValueValue: Int = 0
var minPathListLengthValueValueIndex: Int = 0
var minPathListLengthValueValueValue: Int = 0
var minPathListLengthValueValueValueIndex: Int = 0
var minPathListLengthValueValueValueValue: Int = 0
var minPathListLengthValueValueValueValueIndex: Int = 0
var minPathListLengthValueValueValueValueValue: Int = 0
var minPathListLengthValueValueValueValueValueIndex: Int = 0
var minPathListLengthValueValueValueValueValueValue: Int = 0
var minPathListLengthValueValueValueValueValueValueIndex: Int = 0
var minPathListLengthValueValueValueValueValueValueValue: Int = 0
var minPathListLengthValueValueValueValueValueValueValueIndex: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValue: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueIndex: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValue: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueIndex: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValue: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValueIndex: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValueValue: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValueValueIndex: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValueValueValue: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValueValueValueIndex: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValueValueValueValue: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValueValueValueValueIndex: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValueValueValueValueValue: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValueValueValueValueValueIndex: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValueValueValueValueValueValue: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueIndex: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValue: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueIndex: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValue: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueIndex: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValue: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueIndex: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValue: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueIndex: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValue: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueIndex: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValueValue: Int = 0
var minPathListLengthValueValueValueValueValueValueValueValueValueValueValue
XCTAssertTrue(minPath(grid: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k: 3) == [1, 2, 1]) // cannot find 'minPath' in scope
XCTAssertTrue(minPath(grid: [[5, 9, 3], [4, 1, 6], [7, 8, 2]], k: 1) == [1]) // cannot find 'minPath' in scope
XCTAssertTrue(minPath(grid: [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]], k: 4) == [1, 2, 1, 2]) // cannot find 'minPath' in scope
XCTAssertTrue(minPath(grid: [[6, 4, 13, 10], [5, 7, 12, 1], [3, 16, 11, 15], [8, 14, 9, 2]], k: 7) == [1, 10, 1, 10, 1, 10, 1]) // cannot find 'minPath' in scope
XCTAssertTrue(minPath(grid: [[8, 14, 9, 2], [6, 4, 13, 15], [5, 7, 1, 12], [3, 10, 11, 16]], k: 5) == [1, 7, 1, 7, 1]) // cannot find 'minPath' in scope
XCTAssertTrue(minPath(grid: [[11, 8, 7, 2], [5, 16, 14, 4], [9, 3, 15, 6], [12, 13, 10, 1]], k: 9) == [1, 6, 1, 6, 1, 6, 1, 6, 1]) // cannot find 'minPath' in scope
XCTAssertTrue(minPath(grid: [[12, 13, 10, 1], [9, 3, 15, 6], [5, 16, 14, 4], [11, 8, 7, 2]], k: 12) == [1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6]) // cannot find 'minPath' in scope
XCTAssertTrue(minPath(grid: [[2, 7, 4], [3, 1, 5], [6, 8, 9]], k: 8) == [1, 3, 1, 3, 1, 3, 1, 3]) // cannot find 'minPath' in scope
XCTAssertTrue(minPath(grid: [[6, 1, 5], [3, 8, 9], [2, 7, 4]], k: 8) == [1, 5, 1, 5, 1, 5, 1, 5]) // cannot find 'minPath' in scope
XCTAssertTrue(minPath(grid: [[1, 2], [3, 4]], k: 10) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) // cannot find 'minPath' in scope
XCTAssertTrue(minPath(grid: [[1, 3], [3, 2]], k: 10) == [1, 3, 1, 3, 1, 3, 1, 3, 1, 3]) // cannot find 'minPath' in scope
```swift
// Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// minPath(grid: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k: 3) == [1, 2, 1]
// minPath(grid: [[5, 9, 3], [4, 1, 6], [7, 8, 2]], k: 1) == [1]
func minPath(grid: [[Int]], k: Int) -> [Int] {
var result = [Int]()
var visited = Set<Int>()
var queue = [(Int, Int)]()
var min = Int.max
var minPath = [Int]()
var minPathLength = 0
var minPathIndex = 0
var minPathIndexQueue = [(Int, Int)]()
var minPathIndexQueueLength = 0
var minPathIndexQueueIndex = 0
var minPathIndexQueueMin = Int.max
var minPathIndexQueueMinIndex = 0
var minPathIndexQueueMinPath = [Int]()
var minPathIndexQueueMinPathLength = 0
var minPathIndexQueueMinPathIndex = 0
var minPathIndexQueueMinPathIndexQueue = [(Int, Int)]()
var minPathIndexQueueMinPathIndexQueueLength = 0
var minPathIndexQueueMinPathIndexQueueIndex = 0
var minPathIndexQueueMinPathIndexQueueMin = Int.max
var minPathIndexQueueMinPathIndexQueueMinIndex = 0
var minPathIndexQueueMinPathIndexQueueMinPath = [Int]()
var minPathIndexQueueMinPathIndexQueueMinPathLength = 0
var minPathIndexQueueMinPathIndexQueueMinPathIndex = 0
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueue = [(Int, Int)]()
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueLength = 0
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueIndex = 0
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMin = Int.max
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinIndex = 0
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPath = [Int]()
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathLength = 0
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndex = 0
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueue = [(Int, Int)]()
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueLength = 0
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueIndex = 0
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMin = Int.max
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinIndex = 0
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPath = [Int]()
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathLength = 0
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndex = 0
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueue = [(Int, Int)]()
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueLength = 0
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueIndex = 0
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMin = Int.max
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinIndex = 0
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPath = [Int]()
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathLength = 0
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndex = 0
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueue = [(Int, Int)]()
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueLength = 0
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueIndex = 0
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMin = Int.max
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinIndex = 0
var minPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPathIndexQueueMinPath = [Int]()
var minPathIndexQueue
XCTAssertTrue(minPath(grid: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k: 3) == [1, 2, 1]) // cannot find 'minPath' in scope
XCTAssertTrue(minPath(grid: [[5, 9, 3], [4, 1, 6], [7, 8, 2]], k: 1) == [1]) // cannot find 'minPath' in scope
XCTAssertTrue(minPath(grid: [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]], k: 4) == [1, 2, 1, 2]) // cannot find 'minPath' in scope
XCTAssertTrue(minPath(grid: [[6, 4, 13, 10], [5, 7, 12, 1], [3, 16, 11, 15], [8, 14, 9, 2]], k: 7) == [1, 10, 1, 10, 1, 10, 1]) // cannot find 'minPath' in scope
XCTAssertTrue(minPath(grid: [[8, 14, 9, 2], [6, 4, 13, 15], [5, 7, 1, 12], [3, 10, 11, 16]], k: 5) == [1, 7, 1, 7, 1]) // cannot find 'minPath' in scope
XCTAssertTrue(minPath(grid: [[11, 8, 7, 2], [5, 16, 14, 4], [9, 3, 15, 6], [12, 13, 10, 1]], k: 9) == [1, 6, 1, 6, 1, 6, 1, 6, 1]) // cannot find 'minPath' in scope
XCTAssertTrue(minPath(grid: [[12, 13, 10, 1], [9, 3, 15, 6], [5, 16, 14, 4], [11, 8, 7, 2]], k: 12) == [1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6]) // cannot find 'minPath' in scope
XCTAssertTrue(minPath(grid: [[2, 7, 4], [3, 1, 5], [6, 8, 9]], k: 8) == [1, 3, 1, 3, 1, 3, 1, 3]) // cannot find 'minPath' in scope
XCTAssertTrue(minPath(grid: [[6, 1, 5], [3, 8, 9], [2, 7, 4]], k: 8) == [1, 5, 1, 5, 1, 5, 1, 5]) // cannot find 'minPath' in scope
XCTAssertTrue(minPath(grid: [[1, 2], [3, 4]], k: 10) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) // cannot find 'minPath' in scope
XCTAssertTrue(minPath(grid: [[1, 3], [3, 2]], k: 10) == [1, 3, 1, 3, 1, 3, 1, 3, 1, 3]) // cannot find 'minPath' in scope
func tri(n: Int) -> [Int] {
var tribonacci = [1, 3, 2]
for i in 3...n {
if i % 2 == 0 {
tribonacci.append(tribonacci[i / 2])
} else {
tribonacci.append(tribonacci[i - 1] + tribonacci[i - 2] + tribonacci[i + 1])
}
}
return tribonacci
}
```swift
// Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
// the last couple centuries. However, what people don't know is Tribonacci sequence.
// Tribonacci sequence is defined by the recurrence:
// tri(1) = 3
// tri(n) = 1 + n / 2, if n is even.
// tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
// For example:
// tri(2) = 1 + (2 / 2) = 2
// tri(4) = 3
// tri(3) = tri(2) + tri(1) + tri(4)
// = 2 + 3 + 3 = 8
// You are given a non-negative integer number n, you have to a return an array of the
// first n + 1 numbers of the Tribonacci sequence.
// Examples:
// tri(n: 3) == [1, 3, 2, 8]
func tri(n: Int) -> [Int] {
var tribonacci = [1, 3, 2]
for i in 3...n {
if i % 2 == 0 {
tribonacci.append(tribonacci[i / 2])
} else {
tribonacci.append(tribonacci[i - 1] + tribonacci[i - 2] + tribonacci[i + 1])
}
}
return tribonacci
}
```
// Fatal error: Index out of range
func tri(n: Int) -> [Int] {
var tribonacci = [Int](repeating: 0, count: n + 1)
tribonacci[0] = 1
tribonacci[1] = 3
tribonacci[2] = 2
for i in 3..<n+1 {
if i % 2 == 0 {
tribonacci[i] = 1 + i / 2
} else {
tribonacci[i] = tribonacci[i-1] + tribonacci[i-2] + tribonacci[i+1]
}
}
return tribonacci
}
```swift
// Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
// the last couple centuries. However, what people don't know is Tribonacci sequence.
// Tribonacci sequence is defined by the recurrence:
// tri(1) = 3
// tri(n) = 1 + n / 2, if n is even.
// tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
// For example:
// tri(2) = 1 + (2 / 2) = 2
// tri(4) = 3
// tri(3) = tri(2) + tri(1) + tri(4)
// = 2 + 3 + 3 = 8
// You are given a non-negative integer number n, you have to a return an array of the
// first n + 1 numbers of the Tribonacci sequence.
// Examples:
// tri(n: 3) == [1, 3, 2, 8]
func tri(n: Int) -> [Int] {
var tribonacci = [Int](repeating: 0, count: n + 1)
tribonacci[0] = 1
tribonacci[1] = 3
tribonacci[2] = 2
for i in 3..<n+1 {
if i % 2 == 0 {
tribonacci[i] = 1 + i / 2
} else {
tribonacci[i] = tribonacci[i-1] + tribonacci[i-2] + tribonacci[i+1]
}
}
return tribonacci
}
```
// Fatal error: Index out of range
func tri(n: Int) -> [Int] {
var result = [1, 3, 2]
for i in 3...n {
if i % 2 == 0 {
result.append(1 + i / 2)
} else {
result.append(result[i - 1] + result[i - 2] + result[i + 1])
}
}
return result
}
```swift
// Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
// the last couple centuries. However, what people don't know is Tribonacci sequence.
// Tribonacci sequence is defined by the recurrence:
// tri(1) = 3
// tri(n) = 1 + n / 2, if n is even.
// tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
// For example:
// tri(2) = 1 + (2 / 2) = 2
// tri(4) = 3
// tri(3) = tri(2) + tri(1) + tri(4)
// = 2 + 3 + 3 = 8
// You are given a non-negative integer number n, you have to a return an array of the
// first n + 1 numbers of the Tribonacci sequence.
// Examples:
// tri(n: 3) == [1, 3, 2, 8]
func tri(n: Int) -> [Int] {
var result = [1, 3, 2]
for i in 3...n {
if i % 2 == 0 {
result.append(1 + i / 2)
} else {
result.append(result[i - 1] + result[i - 2] + result[i + 1])
}
}
return result
}
```
// Fatal error: Index out of range
func tri(n: Int) -> [Int] {
var result = [Int]()
for i in 0...n {
if i == 0 {
result.append(1)
} else if i == 1 {
result.append(3)
} else if i == 2 {
result.append(2)
} else {
if i % 2 == 0 {
result.append(1 + i / 2)
} else {
result.append(result[i - 1] + result[i - 2] + result[i + 1])
}
}
}
return result
}
```swift
// Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
// the last couple centuries. However, what people don't know is Tribonacci sequence.
// Tribonacci sequence is defined by the recurrence:
// tri(1) = 3
// tri(n) = 1 + n / 2, if n is even.
// tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
// For example:
// tri(2) = 1 + (2 / 2) = 2
// tri(4) = 3
// tri(3) = tri(2) + tri(1) + tri(4)
// = 2 + 3 + 3 = 8
// You are given a non-negative integer number n, you have to a return an array of the
// first n + 1 numbers of the Tribonacci sequence.
// Examples:
// tri(n: 3) == [1, 3, 2, 8]
func tri(n: Int) -> [Int] {
var result = [Int]()
for i in 0...n {
if i == 0 {
result.append(1)
} else if i == 1 {
result.append(3)
} else if i == 2 {
result.append(2)
} else {
if i % 2 == 0 {
result.append(1 + i / 2)
} else {
result.append(result[i - 1] + result[i - 2] + result[i + 1])
}
}
}
return result
}
```
// Fatal error: Index out of range
func tri(n: Int) -> [Int] {
var result = [1, 3, 2]
for i in 3..<n {
if i % 2 == 0 {
result.append(result[i / 2])
} else {
result.append(result[i - 1] + result[i - 2] + result[i + 1])
}
}
return result
}
```swift
// Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
// the last couple centuries. However, what people don't know is Tribonacci sequence.
// Tribonacci sequence is defined by the recurrence:
// tri(1) = 3
// tri(n) = 1 + n / 2, if n is even.
// tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
// For example:
// tri(2) = 1 + (2 / 2) = 2
// tri(4) = 3
// tri(3) = tri(2) + tri(1) + tri(4)
// = 2 + 3 + 3 = 8
// You are given a non-negative integer number n, you have to a return an array of the
// first n + 1 numbers of the Tribonacci sequence.
// Examples:
// tri(n: 3) == [1, 3, 2, 8]
func tri(n: Int) -> [Int] {
var result = [1, 3, 2]
for i in 3..<n {
if i % 2 == 0 {
result.append(result[i / 2])
} else {
result.append(result[i - 1] + result[i - 2] + result[i + 1])
}
}
return result
}
```
// XCTAssertTrue failed
func tri(n: Int) -> [Int] {
var tribonacci = [1, 3, 2]
for i in 3...n {
if i % 2 == 0 {
tribonacci.append(tribonacci[i / 2])
} else {
tribonacci.append(tribonacci[i - 1] + tribonacci[i - 2] + tribonacci[i + 1])
}
}
return tribonacci
}
```swift
// Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
// the last couple centuries. However, what people don't know is Tribonacci sequence.
// Tribonacci sequence is defined by the recurrence:
// tri(1) = 3
// tri(n) = 1 + n / 2, if n is even.
// tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
// For example:
// tri(2) = 1 + (2 / 2) = 2
// tri(4) = 3
// tri(3) = tri(2) + tri(1) + tri(4)
// = 2 + 3 + 3 = 8
// You are given a non-negative integer number n, you have to a return an array of the
// first n + 1 numbers of the Tribonacci sequence.
// Examples:
// tri(n: 3) == [1, 3, 2, 8]
func tri(n: Int) -> [Int] {
var tribonacci = [1, 3, 2]
for i in 3...n {
if i % 2 == 0 {
tribonacci.append(tribonacci[i / 2])
} else {
tribonacci.append(tribonacci[i - 1] + tribonacci[i - 2] + tribonacci[i + 1])
}
}
return tribonacci
}
```
// Fatal error: Index out of range
func tri(n: Int) -> [Int] {
var tribonacci = [1, 3, 2]
if n < 3 {
return Array(tribonacci[0...n])
}
for i in 3...n {
if i % 2 == 0 {
tribonacci.append(tribonacci[i / 2])
} else {
tribonacci.append(tribonacci[i - 1] + tribonacci[i - 2] + tribonacci[i + 1])
}
}
return tribonacci
}
```swift
// Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
// the last couple centuries. However, what people don't know is Tribonacci sequence.
// Tribonacci sequence is defined by the recurrence:
// tri(1) = 3
// tri(n) = 1 + n / 2, if n is even.
// tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
// For example:
// tri(2) = 1 + (2 / 2) = 2
// tri(4) = 3
// tri(3) = tri(2) + tri(1) + tri(4)
// = 2 + 3 + 3 = 8
// You are given a non-negative integer number n, you have to a return an array of the
// first n + 1 numbers of the Tribonacci sequence.
// Examples:
// tri(n: 3) == [1, 3, 2, 8]
func tri(n: Int) -> [Int] {
var tribonacci = [1, 3, 2]
if n < 3 {
return Array(tribonacci[0...n])
}
for i in 3...n {
if i % 2 == 0 {
tribonacci.append(tribonacci[i / 2])
} else {
tribonacci.append(tribonacci[i - 1] + tribonacci[i - 2] + tribonacci[i + 1])
}
}
return tribonacci
}
```
// Fatal error: Index out of range
func tri(n: Int) -> [Int] {
var tribonacci = [1, 3, 2]
if n < 3 {
return Array(tribonacci[0...n])
}
for i in 3...n {
if i % 2 == 0 {
tribonacci.append(tribonacci[i / 2])
} else {
tribonacci.append(tribonacci[i - 1] + tribonacci[i - 2] + tribonacci[i + 1])
}
}
return tribonacci
}
```swift
// Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
// the last couple centuries. However, what people don't know is Tribonacci sequence.
// Tribonacci sequence is defined by the recurrence:
// tri(1) = 3
// tri(n) = 1 + n / 2, if n is even.
// tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
// For example:
// tri(2) = 1 + (2 / 2) = 2
// tri(4) = 3
// tri(3) = tri(2) + tri(1) + tri(4)
// = 2 + 3 + 3 = 8
// You are given a non-negative integer number n, you have to a return an array of the
// first n + 1 numbers of the Tribonacci sequence.
// Examples:
// tri(n: 3) == [1, 3, 2, 8]
func tri(n: Int) -> [Int] {
var tribonacci = [1, 3, 2]
if n < 3 {
return Array(tribonacci[0...n])
}
for i in 3...n {
if i % 2 == 0 {
tribonacci.append(tribonacci[i / 2])
} else {
tribonacci.append(tribonacci[i - 1] + tribonacci[i - 2] + tribonacci[i + 1])
}
}
return tribonacci
}
```
// Fatal error: Index out of range
func tri(n: Int) -> [Int] {
var result = [1, 3, 2]
for i in 3...n {
if i % 2 == 0 {
result.append(1 + i / 2)
} else {
result.append(result[i - 1] + result[i - 2] + result[i + 1])
}
}
return result
}
```swift
// Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
// the last couple centuries. However, what people don't know is Tribonacci sequence.
// Tribonacci sequence is defined by the recurrence:
// tri(1) = 3
// tri(n) = 1 + n / 2, if n is even.
// tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
// For example:
// tri(2) = 1 + (2 / 2) = 2
// tri(4) = 3
// tri(3) = tri(2) + tri(1) + tri(4)
// = 2 + 3 + 3 = 8
// You are given a non-negative integer number n, you have to a return an array of the
// first n + 1 numbers of the Tribonacci sequence.
// Examples:
// tri(n: 3) == [1, 3, 2, 8]
func tri(n: Int) -> [Int] {
var result = [1, 3, 2]
for i in 3...n {
if i % 2 == 0 {
result.append(1 + i / 2)
} else {
result.append(result[i - 1] + result[i - 2] + result[i + 1])
}
}
return result
}
```
// Fatal error: Index out of range
func tri(n: Int) -> [Int] {
var result = [1, 3, 2]
if n < 3 {
return Array(result[0...n])
}
for i in 3...n {
if i % 2 == 0 {
result.append(result[i / 2])
} else {
result.append(result[i - 1] + result[i - 2] + result[i + 1])
}
}
return result
}
```swift
// Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
// the last couple centuries. However, what people don't know is Tribonacci sequence.
// Tribonacci sequence is defined by the recurrence:
// tri(1) = 3
// tri(n) = 1 + n / 2, if n is even.
// tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
// For example:
// tri(2) = 1 + (2 / 2) = 2
// tri(4) = 3
// tri(3) = tri(2) + tri(1) + tri(4)
// = 2 + 3 + 3 = 8
// You are given a non-negative integer number n, you have to a return an array of the
// first n + 1 numbers of the Tribonacci sequence.
// Examples:
// tri(n: 3) == [1, 3, 2, 8]
func tri(n: Int) -> [Int] {
var result = [1, 3, 2]
if n < 3 {
return Array(result[0...n])
}
for i in 3...n {
if i % 2 == 0 {
result.append(result[i / 2])
} else {
result.append(result[i - 1] + result[i - 2] + result[i + 1])
}
}
return result
}
```
// Fatal error: Index out of range
func digits(n: Int) -> Int {
var result = 1
var num = n
while num > 0 {
let digit = num % 10
if digit % 2 == 1 {
result *= digit
}
num /= 10
}
return result
}
```swift
// Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// digits(n: 1) == 1
// digits(n: 4) == 0
// digits(n: 235) == 15
func digits(n: Int) -> Int {
var result = 1
var num = n
while num > 0 {
let digit = num % 10
if digit % 2 == 1 {
result *= digit
}
num /= 10
}
return result
}
```
// XCTAssertTrue failed
func digits(n: Int) -> Int {
var result = 0
var n = n
while n > 0 {
let digit = n % 10
if digit % 2 == 1 {
result = result * 10 + digit
}
n /= 10
}
return result
}
```swift
// Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// digits(n: 1) == 1
// digits(n: 4) == 0
// digits(n: 235) == 15
func digits(n: Int) -> Int {
var result = 0
var n = n
while n > 0 {
let digit = n % 10
if digit % 2 == 1 {
result = result * 10 + digit
}
n /= 10
}
return result
}
```
// XCTAssertTrue failed
func digits(n: Int) -> Int {
var result = 0
var num = n
while num > 0 {
let digit = num % 10
if digit % 2 == 1 {
result *= 10
result += digit
}
num /= 10
}
return result
}
```swift
// Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// digits(n: 1) == 1
// digits(n: 4) == 0
// digits(n: 235) == 15
func digits(n: Int) -> Int {
var result = 0
var num = n
while num > 0 {
let digit = num % 10
if digit % 2 == 1 {
result *= 10
result += digit
}
num /= 10
}
return result
}
```
// XCTAssertTrue failed
func digits(n: Int) -> Int {
var result = 0
var number = n
while number > 0 {
let digit = number % 10
if digit % 2 == 1 {
result = result * 10 + digit
}
number /= 10
}
return result
}
```swift
// Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// digits(n: 1) == 1
// digits(n: 4) == 0
// digits(n: 235) == 15
func digits(n: Int) -> Int {
var result = 0
var number = n
while number > 0 {
let digit = number % 10
if digit % 2 == 1 {
result = result * 10 + digit
}
number /= 10
}
return result
}
```
// XCTAssertTrue failed
func digits(n: Int) -> Int {
var result = 1
var number = n
while number > 0 {
let digit = number % 10
if digit % 2 == 1 {
result *= digit
}
number /= 10
}
return result
}
```swift
// Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// digits(n: 1) == 1
// digits(n: 4) == 0
// digits(n: 235) == 15
func digits(n: Int) -> Int {
var result = 1
var number = n
while number > 0 {
let digit = number % 10
if digit % 2 == 1 {
result *= digit
}
number /= 10
}
return result
}
```
// XCTAssertTrue failed
func digits(n: Int) -> Int {
var result = 1
var number = n
while number > 0 {
let digit = number % 10
if digit % 2 == 1 {
result *= digit
}
number /= 10
}
return result
}
```swift
// Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// digits(n: 1) == 1
// digits(n: 4) == 0
// digits(n: 235) == 15
func digits(n: Int) -> Int {
var result = 1
var number = n
while number > 0 {
let digit = number % 10
if digit % 2 == 1 {
result *= digit
}
number /= 10
}
return result
}
```
// XCTAssertTrue failed
func digits(n: Int) -> Int {
var result = 0
var n = n
while n > 0 {
let digit = n % 10
if digit % 2 == 1 {
result = result * 10 + digit
}
n /= 10
}
return result
}
```swift
// Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// digits(n: 1) == 1
// digits(n: 4) == 0
// digits(n: 235) == 15
func digits(n: Int) -> Int {
var result = 0
var n = n
while n > 0 {
let digit = n % 10
if digit % 2 == 1 {
result = result * 10 + digit
}
n /= 10
}
return result
}
```
// XCTAssertTrue failed
func digits(n: Int) -> Int {
var result = 1
var num = n
while num > 0 {
let digit = num % 10
if digit % 2 == 1 {
result *= digit
}
num /= 10
}
return result
}
```swift
// Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// digits(n: 1) == 1
// digits(n: 4) == 0
// digits(n: 235) == 15
func digits(n: Int) -> Int {
var result = 1
var num = n
while num > 0 {
let digit = num % 10
if digit % 2 == 1 {
result *= digit
}
num /= 10
}
return result
}
```
// XCTAssertTrue failed
func digits(n: Int) -> Int {
var result = 1
var num = n
while num > 0 {
let digit = num % 10
if digit % 2 == 1 {
result *= digit
}
num /= 10
}
return result
}
```swift
// Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// digits(n: 1) == 1
// digits(n: 4) == 0
// digits(n: 235) == 15
func digits(n: Int) -> Int {
var result = 1
var num = n
while num > 0 {
let digit = num % 10
if digit % 2 == 1 {
result *= digit
}
num /= 10
}
return result
}
```
// XCTAssertTrue failed
func digits(n: Int) -> Int {
var result = 1
var number = n
while number > 0 {
let digit = number % 10
if digit % 2 == 1 {
result *= digit
}
number /= 10
}
return result
}
```swift
// Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// digits(n: 1) == 1
// digits(n: 4) == 0
// digits(n: 235) == 15
func digits(n: Int) -> Int {
var result = 1
var number = n
while number > 0 {
let digit = number % 10
if digit % 2 == 1 {
result *= digit
}
number /= 10
}
return result
}
```
// XCTAssertTrue failed
func isNested(string: String) -> Bool {
var stack = [Character]()
for char in string {
if char == "[" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// Create a function that takes a string as input which contains only square brackets.
// The function should return true if and only if there is a valid subsequence of brackets
// where at least one bracket in the subsequence is nested.
// isNested(string: "[[]]") == true
// isNested(string: "[]]]]]]][[[[[]") == false
// isNested(string: "[][]") == false
// isNested(string: "[]") == false
// isNested(string: "[[][]]") == true
// isNested(string: "[[]][[") == true
func isNested(string: String) -> Bool {
var stack = [Character]()
for char in string {
if char == "[" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
// XCTAssertTrue failed
func isNested(string: String) -> Bool {
return false
}
```swift
// Create a function that takes a string as input which contains only square brackets.
// The function should return true if and only if there is a valid subsequence of brackets
// where at least one bracket in the subsequence is nested.
// isNested(string: "[[]]") == true
// isNested(string: "[]]]]]]][[[[[]") == false
// isNested(string: "[][]") == false
// isNested(string: "[]") == false
// isNested(string: "[[][]]") == true
// isNested(string: "[[]][[") == true
func isNested(string: String) -> Bool {
return false
}
```
// XCTAssertTrue failed
func isNested(string: String) -> Bool {
var stack = [Character]()
for char in string {
if char == "[" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// Create a function that takes a string as input which contains only square brackets.
// The function should return true if and only if there is a valid subsequence of brackets
// where at least one bracket in the subsequence is nested.
// isNested(string: "[[]]") == true
// isNested(string: "[]]]]]]][[[[[]") == false
// isNested(string: "[][]") == false
// isNested(string: "[]") == false
// isNested(string: "[[][]]") == true
// isNested(string: "[[]][[") == true
func isNested(string: String) -> Bool {
var stack = [Character]()
for char in string {
if char == "[" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
// XCTAssertTrue failed
func isNested(string: String) -> Bool {
// your code here
}
```swift
// Create a function that takes a string as input which contains only square brackets.
// The function should return true if and only if there is a valid subsequence of brackets
// where at least one bracket in the subsequence is nested.
// isNested(string: "[[]]") == true
// isNested(string: "[]]]]]]][[[[[]") == false
// isNested(string: "[][]") == false
// isNested(string: "[]") == false
// isNested(string: "[[][]]") == true
// isNested(string: "[[]][[") == true
func isNested(string: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isNested(string: String) -> Bool {
// TODO: Write your code here
}
```swift
// Create a function that takes a string as input which contains only square brackets.
// The function should return true if and only if there is a valid subsequence of brackets
// where at least one bracket in the subsequence is nested.
// isNested(string: "[[]]") == true
// isNested(string: "[]]]]]]][[[[[]") == false
// isNested(string: "[][]") == false
// isNested(string: "[]") == false
// isNested(string: "[[][]]") == true
// isNested(string: "[[]][[") == true
func isNested(string: String) -> Bool {
// TODO: Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isNested(string: String) -> Bool {
// your code here
}
```swift
// Create a function that takes a string as input which contains only square brackets.
// The function should return true if and only if there is a valid subsequence of brackets
// where at least one bracket in the subsequence is nested.
// isNested(string: "[[]]") == true
// isNested(string: "[]]]]]]][[[[[]") == false
// isNested(string: "[][]") == false
// isNested(string: "[]") == false
// isNested(string: "[[][]]") == true
// isNested(string: "[[]][[") == true
func isNested(string: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isNested(string: String) -> Bool {
var stack = [Character]()
for char in string {
if char == "[" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// Create a function that takes a string as input which contains only square brackets.
// The function should return true if and only if there is a valid subsequence of brackets
// where at least one bracket in the subsequence is nested.
// isNested(string: "[[]]") == true
// isNested(string: "[]]]]]]][[[[[]") == false
// isNested(string: "[][]") == false
// isNested(string: "[]") == false
// isNested(string: "[[][]]") == true
// isNested(string: "[[]][[") == true
func isNested(string: String) -> Bool {
var stack = [Character]()
for char in string {
if char == "[" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
// XCTAssertTrue failed
func isNested(string: String) -> Bool {
var stack = [Character]()
for char in string {
if char == "[" {
stack.append(char)
} else if char == "]" {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// Create a function that takes a string as input which contains only square brackets.
// The function should return true if and only if there is a valid subsequence of brackets
// where at least one bracket in the subsequence is nested.
// isNested(string: "[[]]") == true
// isNested(string: "[]]]]]]][[[[[]") == false
// isNested(string: "[][]") == false
// isNested(string: "[]") == false
// isNested(string: "[[][]]") == true
// isNested(string: "[[]][[") == true
func isNested(string: String) -> Bool {
var stack = [Character]()
for char in string {
if char == "[" {
stack.append(char)
} else if char == "]" {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
// XCTAssertTrue failed
func isNested(string: String) -> Bool {
var stack: [Character] = []
for char in string {
if char == "[" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// Create a function that takes a string as input which contains only square brackets.
// The function should return true if and only if there is a valid subsequence of brackets
// where at least one bracket in the subsequence is nested.
// isNested(string: "[[]]") == true
// isNested(string: "[]]]]]]][[[[[]") == false
// isNested(string: "[][]") == false
// isNested(string: "[]") == false
// isNested(string: "[[][]]") == true
// isNested(string: "[[]][[") == true
func isNested(string: String) -> Bool {
var stack: [Character] = []
for char in string {
if char == "[" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
// XCTAssertTrue failed
func isNested(string: String) -> Bool {
var stack = [Character]()
for char in string {
if char == "[" {
stack.append(char)
} else if char == "]" {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// Create a function that takes a string as input which contains only square brackets.
// The function should return true if and only if there is a valid subsequence of brackets
// where at least one bracket in the subsequence is nested.
// isNested(string: "[[]]") == true
// isNested(string: "[]]]]]]][[[[[]") == false
// isNested(string: "[][]") == false
// isNested(string: "[]") == false
// isNested(string: "[[][]]") == true
// isNested(string: "[[]][[") == true
func isNested(string: String) -> Bool {
var stack = [Character]()
for char in string {
if char == "[" {
stack.append(char)
} else if char == "]" {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
// XCTAssertTrue failed
func sumSquares(lst: [Double]) -> Int {
var sum = 0
for i in lst {
sum += Int(ceil(i)) * Int(ceil(i))
}
return sum
}
```swift
// You are given an array of numbers.
// You need to return the sum of squared numbers in the given array,
// round each element in the array to the upper int(Ceiling) first.
// Examples:
// sumSquares(lst: [1.0, 2.0, 3.0]) == 14
// sumSquares(lst: [1.0, 4.0, 9.0]) == 98
// sumSquares(lst: [1.0, 3.0, 5.0, 7.0]) == 84
// sumSquares(lst: [1.4, 4.2, 0.0]) == 29
// sumSquares(lst: [-2.4, 1.0, 1.0]) == 6
func sumSquares(lst: [Double]) -> Int {
var sum = 0
for i in lst {
sum += Int(ceil(i)) * Int(ceil(i))
}
return sum
}
```
func sumSquares(lst: [Double]) -> Int {
var sum = 0
for i in lst {
sum += Int(ceil(i)) * Int(ceil(i))
}
return sum
}
```swift
// You are given an array of numbers.
// You need to return the sum of squared numbers in the given array,
// round each element in the array to the upper int(Ceiling) first.
// Examples:
// sumSquares(lst: [1.0, 2.0, 3.0]) == 14
// sumSquares(lst: [1.0, 4.0, 9.0]) == 98
// sumSquares(lst: [1.0, 3.0, 5.0, 7.0]) == 84
// sumSquares(lst: [1.4, 4.2, 0.0]) == 29
// sumSquares(lst: [-2.4, 1.0, 1.0]) == 6
func sumSquares(lst: [Double]) -> Int {
var sum = 0
for i in lst {
sum += Int(ceil(i)) * Int(ceil(i))
}
return sum
}
```
func sumSquares(lst: [Double]) -> Int {
var sum = 0
for i in lst {
sum += Int(ceil(i)) * Int(ceil(i))
}
return sum
}
```swift
// You are given an array of numbers.
// You need to return the sum of squared numbers in the given array,
// round each element in the array to the upper int(Ceiling) first.
// Examples:
// sumSquares(lst: [1.0, 2.0, 3.0]) == 14
// sumSquares(lst: [1.0, 4.0, 9.0]) == 98
// sumSquares(lst: [1.0, 3.0, 5.0, 7.0]) == 84
// sumSquares(lst: [1.4, 4.2, 0.0]) == 29
// sumSquares(lst: [-2.4, 1.0, 1.0]) == 6
func sumSquares(lst: [Double]) -> Int {
var sum = 0
for i in lst {
sum += Int(ceil(i)) * Int(ceil(i))
}
return sum
}
```
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) }.reduce(0, +))
}
```swift
// You are given an array of numbers.
// You need to return the sum of squared numbers in the given array,
// round each element in the array to the upper int(Ceiling) first.
// Examples:
// sumSquares(lst: [1.0, 2.0, 3.0]) == 14
// sumSquares(lst: [1.0, 4.0, 9.0]) == 98
// sumSquares(lst: [1.0, 3.0, 5.0, 7.0]) == 84
// sumSquares(lst: [1.4, 4.2, 0.0]) == 29
// sumSquares(lst: [-2.4, 1.0, 1.0]) == 6
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) }.reduce(0, +))
}
```
// XCTAssertTrue failed
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { Int(ceil($0)) }.reduce(0, +))
}
```swift
// You are given an array of numbers.
// You need to return the sum of squared numbers in the given array,
// round each element in the array to the upper int(Ceiling) first.
// Examples:
// sumSquares(lst: [1.0, 2.0, 3.0]) == 14
// sumSquares(lst: [1.0, 4.0, 9.0]) == 98
// sumSquares(lst: [1.0, 3.0, 5.0, 7.0]) == 84
// sumSquares(lst: [1.4, 4.2, 0.0]) == 29
// sumSquares(lst: [-2.4, 1.0, 1.0]) == 6
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { Int(ceil($0)) }.reduce(0, +))
}
```
// XCTAssertTrue failed
func sumSquares(lst: [Double]) -> Int {
return 0
}
```swift
// You are given an array of numbers.
// You need to return the sum of squared numbers in the given array,
// round each element in the array to the upper int(Ceiling) first.
// Examples:
// sumSquares(lst: [1.0, 2.0, 3.0]) == 14
// sumSquares(lst: [1.0, 4.0, 9.0]) == 98
// sumSquares(lst: [1.0, 3.0, 5.0, 7.0]) == 84
// sumSquares(lst: [1.4, 4.2, 0.0]) == 29
// sumSquares(lst: [-2.4, 1.0, 1.0]) == 6
func sumSquares(lst: [Double]) -> Int {
return 0
}
```
// XCTAssertTrue failed
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map {
ceil($0)
}.reduce(0, { $0 + Int(pow($1, 2)) }))
}
```swift
// You are given an array of numbers.
// You need to return the sum of squared numbers in the given array,
// round each element in the array to the upper int(Ceiling) first.
// Examples:
// sumSquares(lst: [1.0, 2.0, 3.0]) == 14
// sumSquares(lst: [1.0, 4.0, 9.0]) == 98
// sumSquares(lst: [1.0, 3.0, 5.0, 7.0]) == 84
// sumSquares(lst: [1.4, 4.2, 0.0]) == 29
// sumSquares(lst: [-2.4, 1.0, 1.0]) == 6
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map {
ceil($0)
}.reduce(0, { $0 + Int(pow($1, 2)) }))
}
```
func sumSquares(lst: [Double]) -> Int {
var sum = 0
for i in lst {
sum += Int(ceil(i)) * Int(ceil(i))
}
return sum
}
```swift
// You are given an array of numbers.
// You need to return the sum of squared numbers in the given array,
// round each element in the array to the upper int(Ceiling) first.
// Examples:
// sumSquares(lst: [1.0, 2.0, 3.0]) == 14
// sumSquares(lst: [1.0, 4.0, 9.0]) == 98
// sumSquares(lst: [1.0, 3.0, 5.0, 7.0]) == 84
// sumSquares(lst: [1.4, 4.2, 0.0]) == 29
// sumSquares(lst: [-2.4, 1.0, 1.0]) == 6
func sumSquares(lst: [Double]) -> Int {
var sum = 0
for i in lst {
sum += Int(ceil(i)) * Int(ceil(i))
}
return sum
}
```
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) }.reduce(0, +))
}
```swift
// You are given an array of numbers.
// You need to return the sum of squared numbers in the given array,
// round each element in the array to the upper int(Ceiling) first.
// Examples:
// sumSquares(lst: [1.0, 2.0, 3.0]) == 14
// sumSquares(lst: [1.0, 4.0, 9.0]) == 98
// sumSquares(lst: [1.0, 3.0, 5.0, 7.0]) == 84
// sumSquares(lst: [1.4, 4.2, 0.0]) == 29
// sumSquares(lst: [-2.4, 1.0, 1.0]) == 6
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) }.reduce(0, +))
}
```
// XCTAssertTrue failed
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) }.reduce(0, +))
}
```swift
// You are given an array of numbers.
// You need to return the sum of squared numbers in the given array,
// round each element in the array to the upper int(Ceiling) first.
// Examples:
// sumSquares(lst: [1.0, 2.0, 3.0]) == 14
// sumSquares(lst: [1.0, 4.0, 9.0]) == 98
// sumSquares(lst: [1.0, 3.0, 5.0, 7.0]) == 84
// sumSquares(lst: [1.4, 4.2, 0.0]) == 29
// sumSquares(lst: [-2.4, 1.0, 1.0]) == 6
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) }.reduce(0, +))
}
```
// XCTAssertTrue failed
func checkIfLastCharIsALetter(txt: String) -> Bool {
// Write your code here.
}
```swift
// Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// checkIfLastCharIsALetter(txt: "apple pie") == false
// checkIfLastCharIsALetter(txt: "apple pi e") == true
// checkIfLastCharIsALetter(txt: "apple pi e ") == false
// checkIfLastCharIsALetter(txt: "") == false
func checkIfLastCharIsALetter(txt: String) -> Bool {
// Write your code here.
}
```
} // missing return in global function expected to return 'Bool'
func checkIfLastCharIsALetter(txt: String) -> Bool {
// Write your code here
}
```swift
// Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// checkIfLastCharIsALetter(txt: "apple pie") == false
// checkIfLastCharIsALetter(txt: "apple pi e") == true
// checkIfLastCharIsALetter(txt: "apple pi e ") == false
// checkIfLastCharIsALetter(txt: "") == false
func checkIfLastCharIsALetter(txt: String) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func checkIfLastCharIsALetter(txt: String) -> Bool {
// Write your code here.
}
```swift
// Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// checkIfLastCharIsALetter(txt: "apple pie") == false
// checkIfLastCharIsALetter(txt: "apple pi e") == true
// checkIfLastCharIsALetter(txt: "apple pi e ") == false
// checkIfLastCharIsALetter(txt: "") == false
func checkIfLastCharIsALetter(txt: String) -> Bool {
// Write your code here.
}
```
} // missing return in global function expected to return 'Bool'
func checkIfLastCharIsALetter(txt: String) -> Bool {
// Your code here
}
```swift
// Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// checkIfLastCharIsALetter(txt: "apple pie") == false
// checkIfLastCharIsALetter(txt: "apple pi e") == true
// checkIfLastCharIsALetter(txt: "apple pi e ") == false
// checkIfLastCharIsALetter(txt: "") == false
func checkIfLastCharIsALetter(txt: String) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func checkIfLastCharIsALetter(txt: String) -> Bool {
// Write your code here
}
```swift
// Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// checkIfLastCharIsALetter(txt: "apple pie") == false
// checkIfLastCharIsALetter(txt: "apple pi e") == true
// checkIfLastCharIsALetter(txt: "apple pi e ") == false
// checkIfLastCharIsALetter(txt: "") == false
func checkIfLastCharIsALetter(txt: String) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func checkIfLastCharIsALetter(txt: String) -> Bool {
// Write your code here
}
```swift
// Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// checkIfLastCharIsALetter(txt: "apple pie") == false
// checkIfLastCharIsALetter(txt: "apple pi e") == true
// checkIfLastCharIsALetter(txt: "apple pi e ") == false
// checkIfLastCharIsALetter(txt: "") == false
func checkIfLastCharIsALetter(txt: String) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func checkIfLastCharIsALetter(txt: String) -> Bool {
return false
}
```swift
// Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// checkIfLastCharIsALetter(txt: "apple pie") == false
// checkIfLastCharIsALetter(txt: "apple pi e") == true
// checkIfLastCharIsALetter(txt: "apple pi e ") == false
// checkIfLastCharIsALetter(txt: "") == false
func checkIfLastCharIsALetter(txt: String) -> Bool {
return false
}
```
// XCTAssertTrue failed
func checkIfLastCharIsALetter(txt: String) -> Bool {
return false
}
```swift
// Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// checkIfLastCharIsALetter(txt: "apple pie") == false
// checkIfLastCharIsALetter(txt: "apple pi e") == true
// checkIfLastCharIsALetter(txt: "apple pi e ") == false
// checkIfLastCharIsALetter(txt: "") == false
func checkIfLastCharIsALetter(txt: String) -> Bool {
return false
}
```
// XCTAssertTrue failed
func checkIfLastCharIsALetter(txt: String) -> Bool {
return false
}
```swift
// Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// checkIfLastCharIsALetter(txt: "apple pie") == false
// checkIfLastCharIsALetter(txt: "apple pi e") == true
// checkIfLastCharIsALetter(txt: "apple pi e ") == false
// checkIfLastCharIsALetter(txt: "") == false
func checkIfLastCharIsALetter(txt: String) -> Bool {
return false
}
```
// XCTAssertTrue failed
func checkIfLastCharIsALetter(txt: String) -> Bool {
return false
}
```swift
// Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// checkIfLastCharIsALetter(txt: "apple pie") == false
// checkIfLastCharIsALetter(txt: "apple pi e") == true
// checkIfLastCharIsALetter(txt: "apple pi e ") == false
// checkIfLastCharIsALetter(txt: "") == false
func checkIfLastCharIsALetter(txt: String) -> Bool {
return false
}
```
// XCTAssertTrue failed
func canArrange(arr: [Int]) -> Int {
// Your code here
}
```swift
// Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately preceding it. If
// no such element exists then return -1. The given array will not contain
// duplicate values.
// Examples:
// canArrange(arr: [1, 2, 4, 3, 5]) == 3
// canArrange(arr: [1, 2, 3]) == -1
func canArrange(arr: [Int]) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func canArrange(arr: [Int]) -> Int {
// Your code here
}
```swift
// Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately preceding it. If
// no such element exists then return -1. The given array will not contain
// duplicate values.
// Examples:
// canArrange(arr: [1, 2, 4, 3, 5]) == 3
// canArrange(arr: [1, 2, 3]) == -1
func canArrange(arr: [Int]) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func canArrange(arr: [Int]) -> Int {
// Write your code here.
}
```swift
// Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately preceding it. If
// no such element exists then return -1. The given array will not contain
// duplicate values.
// Examples:
// canArrange(arr: [1, 2, 4, 3, 5]) == 3
// canArrange(arr: [1, 2, 3]) == -1
func canArrange(arr: [Int]) -> Int {
// Write your code here.
}
```
} // missing return in global function expected to return 'Int'
func canArrange(arr: [Int]) -> Int {
// Your code here
}
```swift
// Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately preceding it. If
// no such element exists then return -1. The given array will not contain
// duplicate values.
// Examples:
// canArrange(arr: [1, 2, 4, 3, 5]) == 3
// canArrange(arr: [1, 2, 3]) == -1
func canArrange(arr: [Int]) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func canArrange(arr: [Int]) -> Int {
var result = -1
for i in 0..<arr.count {
if i == 0 {
result = 0
} else if arr[i] <= arr[i - 1] {
result = i
break
}
}
return result
}
```swift
// Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately preceding it. If
// no such element exists then return -1. The given array will not contain
// duplicate values.
// Examples:
// canArrange(arr: [1, 2, 4, 3, 5]) == 3
// canArrange(arr: [1, 2, 3]) == -1
func canArrange(arr: [Int]) -> Int {
var result = -1
for i in 0..<arr.count {
if i == 0 {
result = 0
} else if arr[i] <= arr[i - 1] {
result = i
break
}
}
return result
}
```
// XCTAssertTrue failed
func canArrange(arr: [Int]) -> Int {
// Your code here
}
```swift
// Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately preceding it. If
// no such element exists then return -1. The given array will not contain
// duplicate values.
// Examples:
// canArrange(arr: [1, 2, 4, 3, 5]) == 3
// canArrange(arr: [1, 2, 3]) == -1
func canArrange(arr: [Int]) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func canArrange(arr: [Int]) -> Int {
var result = -1
for i in 0..<arr.count {
if arr[i] <= result {
result = i
}
}
return result
}
```swift
// Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately preceding it. If
// no such element exists then return -1. The given array will not contain
// duplicate values.
// Examples:
// canArrange(arr: [1, 2, 4, 3, 5]) == 3
// canArrange(arr: [1, 2, 3]) == -1
func canArrange(arr: [Int]) -> Int {
var result = -1
for i in 0..<arr.count {
if arr[i] <= result {
result = i
}
}
return result
}
```
// XCTAssertTrue failed
func canArrange(arr: [Int]) -> Int {
var result = -1
for i in 0..<arr.count {
if i == 0 {
continue
}
if arr[i] <= arr[i - 1] {
result = i
break
}
}
return result
}
```swift
// Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately preceding it. If
// no such element exists then return -1. The given array will not contain
// duplicate values.
// Examples:
// canArrange(arr: [1, 2, 4, 3, 5]) == 3
// canArrange(arr: [1, 2, 3]) == -1
func canArrange(arr: [Int]) -> Int {
var result = -1
for i in 0..<arr.count {
if i == 0 {
continue
}
if arr[i] <= arr[i - 1] {
result = i
break
}
}
return result
}
```
// XCTAssertTrue failed
func canArrange(arr: [Int]) -> Int {
var result = -1
var i = 0
while i < arr.count {
if i + 1 < arr.count && arr[i] <= arr[i + 1] {
i += 1
} else {
result = i
break
}
}
return result
}
```swift
// Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately preceding it. If
// no such element exists then return -1. The given array will not contain
// duplicate values.
// Examples:
// canArrange(arr: [1, 2, 4, 3, 5]) == 3
// canArrange(arr: [1, 2, 3]) == -1
func canArrange(arr: [Int]) -> Int {
var result = -1
var i = 0
while i < arr.count {
if i + 1 < arr.count && arr[i] <= arr[i + 1] {
i += 1
} else {
result = i
break
}
}
return result
}
```
// XCTAssertTrue failed
func canArrange(arr: [Int]) -> Int {
var result = -1
for i in 0..<arr.count {
if arr[i] <= i {
result = i
}
}
return result
}
```swift
// Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately preceding it. If
// no such element exists then return -1. The given array will not contain
// duplicate values.
// Examples:
// canArrange(arr: [1, 2, 4, 3, 5]) == 3
// canArrange(arr: [1, 2, 3]) == -1
func canArrange(arr: [Int]) -> Int {
var result = -1
for i in 0..<arr.count {
if arr[i] <= i {
result = i
}
}
return result
}
```
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var negative: Int?
var positive: Int?
for i in lst {
if i < 0 {
negative = i
}
if i > 0 {
positive = i
}
}
return (negative, positive)
}
```swift
// Create a function that returns a tuple (a, b), where 'a' is
// the largest of negative integers, and 'b' is the smallest
// of positive integers in an array.
// If there is no negative or positive integers, return them as nil.
// Examples:
// largestSmallestIntegers(lst: [2, 4, 1, 3, 5, 7]) == (nil, 1)
// largestSmallestIntegers(lst: [] as [Int]) == (nil, nil)
// largestSmallestIntegers(lst: [0]) == (nil, nil)
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var negative: Int?
var positive: Int?
for i in lst {
if i < 0 {
negative = i
}
if i > 0 {
positive = i
}
}
return (negative, positive)
}
```
// XCTAssertTrue failed
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var negatives = [Int]()
var positives = [Int]()
for i in lst {
if i < 0 {
negatives.append(i)
} else if i > 0 {
positives.append(i)
}
}
if negatives.count > 0 {
let max = negatives.max()
return (max, nil)
} else if positives.count > 0 {
let min = positives.min()
return (nil, min)
} else {
return (nil, nil)
}
}
```swift
// Create a function that returns a tuple (a, b), where 'a' is
// the largest of negative integers, and 'b' is the smallest
// of positive integers in an array.
// If there is no negative or positive integers, return them as nil.
// Examples:
// largestSmallestIntegers(lst: [2, 4, 1, 3, 5, 7]) == (nil, 1)
// largestSmallestIntegers(lst: [] as [Int]) == (nil, nil)
// largestSmallestIntegers(lst: [0]) == (nil, nil)
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var negatives = [Int]()
var positives = [Int]()
for i in lst {
if i < 0 {
negatives.append(i)
} else if i > 0 {
positives.append(i)
}
}
if negatives.count > 0 {
let max = negatives.max()
return (max, nil)
} else if positives.count > 0 {
let min = positives.min()
return (nil, min)
} else {
return (nil, nil)
}
}
```
// XCTAssertTrue failed
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var negative: Int?
var positive: Int?
var negativeMax = Int.min
var positiveMin = Int.max
for i in lst {
if i < 0 {
if i > negativeMax {
negativeMax = i
negative = i
}
} else if i > 0 {
if i < positiveMin {
positiveMin = i
positive = i
}
}
}
return (negative, positive)
}
```swift
// Create a function that returns a tuple (a, b), where 'a' is
// the largest of negative integers, and 'b' is the smallest
// of positive integers in an array.
// If there is no negative or positive integers, return them as nil.
// Examples:
// largestSmallestIntegers(lst: [2, 4, 1, 3, 5, 7]) == (nil, 1)
// largestSmallestIntegers(lst: [] as [Int]) == (nil, nil)
// largestSmallestIntegers(lst: [0]) == (nil, nil)
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var negative: Int?
var positive: Int?
var negativeMax = Int.min
var positiveMin = Int.max
for i in lst {
if i < 0 {
if i > negativeMax {
negativeMax = i
negative = i
}
} else if i > 0 {
if i < positiveMin {
positiveMin = i
positive = i
}
}
}
return (negative, positive)
}
```
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var negative: Int?
var positive: Int?
for i in lst {
if i < 0 {
negative = i
}
if i > 0 {
positive = i
}
}
return (negative, positive)
}
```swift
// Create a function that returns a tuple (a, b), where 'a' is
// the largest of negative integers, and 'b' is the smallest
// of positive integers in an array.
// If there is no negative or positive integers, return them as nil.
// Examples:
// largestSmallestIntegers(lst: [2, 4, 1, 3, 5, 7]) == (nil, 1)
// largestSmallestIntegers(lst: [] as [Int]) == (nil, nil)
// largestSmallestIntegers(lst: [0]) == (nil, nil)
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var negative: Int?
var positive: Int?
for i in lst {
if i < 0 {
negative = i
}
if i > 0 {
positive = i
}
}
return (negative, positive)
}
```
// XCTAssertTrue failed
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var negative: Int?
var positive: Int?
for i in lst {
if i < 0 {
negative = i
}
if i > 0 {
positive = i
}
}
return (negative, positive)
}
```swift
// Create a function that returns a tuple (a, b), where 'a' is
// the largest of negative integers, and 'b' is the smallest
// of positive integers in an array.
// If there is no negative or positive integers, return them as nil.
// Examples:
// largestSmallestIntegers(lst: [2, 4, 1, 3, 5, 7]) == (nil, 1)
// largestSmallestIntegers(lst: [] as [Int]) == (nil, nil)
// largestSmallestIntegers(lst: [0]) == (nil, nil)
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var negative: Int?
var positive: Int?
for i in lst {
if i < 0 {
negative = i
}
if i > 0 {
positive = i
}
}
return (negative, positive)
}
```
// XCTAssertTrue failed
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var negative: Int?
var positive: Int?
for i in lst {
if i < 0 {
negative = i
}
if i > 0 {
positive = i
}
}
return (negative, positive)
}
```swift
// Create a function that returns a tuple (a, b), where 'a' is
// the largest of negative integers, and 'b' is the smallest
// of positive integers in an array.
// If there is no negative or positive integers, return them as nil.
// Examples:
// largestSmallestIntegers(lst: [2, 4, 1, 3, 5, 7]) == (nil, 1)
// largestSmallestIntegers(lst: [] as [Int]) == (nil, nil)
// largestSmallestIntegers(lst: [0]) == (nil, nil)
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var negative: Int?
var positive: Int?
for i in lst {
if i < 0 {
negative = i
}
if i > 0 {
positive = i
}
}
return (negative, positive)
}
```
// XCTAssertTrue failed
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var negative: Int?
var positive: Int?
for i in lst {
if i < 0 {
negative = i
}
if i > 0 {
positive = i
}
}
return (negative, positive)
}
```swift
// Create a function that returns a tuple (a, b), where 'a' is
// the largest of negative integers, and 'b' is the smallest
// of positive integers in an array.
// If there is no negative or positive integers, return them as nil.
// Examples:
// largestSmallestIntegers(lst: [2, 4, 1, 3, 5, 7]) == (nil, 1)
// largestSmallestIntegers(lst: [] as [Int]) == (nil, nil)
// largestSmallestIntegers(lst: [0]) == (nil, nil)
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var negative: Int?
var positive: Int?
for i in lst {
if i < 0 {
negative = i
}
if i > 0 {
positive = i
}
}
return (negative, positive)
}
```
// XCTAssertTrue failed
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var negative: Int? = nil
var positive: Int? = nil
for i in lst {
if i < 0 {
negative = i
}
if i > 0 {
positive = i
}
}
return (negative, positive)
}
```swift
// Create a function that returns a tuple (a, b), where 'a' is
// the largest of negative integers, and 'b' is the smallest
// of positive integers in an array.
// If there is no negative or positive integers, return them as nil.
// Examples:
// largestSmallestIntegers(lst: [2, 4, 1, 3, 5, 7]) == (nil, 1)
// largestSmallestIntegers(lst: [] as [Int]) == (nil, nil)
// largestSmallestIntegers(lst: [0]) == (nil, nil)
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var negative: Int? = nil
var positive: Int? = nil
for i in lst {
if i < 0 {
negative = i
}
if i > 0 {
positive = i
}
}
return (negative, positive)
}
```
// XCTAssertTrue failed
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var negative: Int?
var positive: Int?
for i in lst {
if i < 0 {
negative = i
}
if i > 0 {
positive = i
}
}
return (negative, positive)
}
```swift
// Create a function that returns a tuple (a, b), where 'a' is
// the largest of negative integers, and 'b' is the smallest
// of positive integers in an array.
// If there is no negative or positive integers, return them as nil.
// Examples:
// largestSmallestIntegers(lst: [2, 4, 1, 3, 5, 7]) == (nil, 1)
// largestSmallestIntegers(lst: [] as [Int]) == (nil, nil)
// largestSmallestIntegers(lst: [0]) == (nil, nil)
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var negative: Int?
var positive: Int?
for i in lst {
if i < 0 {
negative = i
}
if i > 0 {
positive = i
}
}
return (negative, positive)
}
```
// XCTAssertTrue failed
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var negative: Int?
var positive: Int?
for i in lst {
if i < 0 {
negative = i
}
if i > 0 {
positive = i
}
}
return (negative, positive)
}
```swift
// Create a function that returns a tuple (a, b), where 'a' is
// the largest of negative integers, and 'b' is the smallest
// of positive integers in an array.
// If there is no negative or positive integers, return them as nil.
// Examples:
// largestSmallestIntegers(lst: [2, 4, 1, 3, 5, 7]) == (nil, 1)
// largestSmallestIntegers(lst: [] as [Int]) == (nil, nil)
// largestSmallestIntegers(lst: [0]) == (nil, nil)
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var negative: Int?
var positive: Int?
for i in lst {
if i < 0 {
negative = i
}
if i > 0 {
positive = i
}
}
return (negative, positive)
}
```
// XCTAssertTrue failed
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
func compareOne(a: Value, b: Value) -> Value? {
// Your code here
}
func compareTwo(a: Value, b: Value) -> Value? {
// Your code here
}
```swift
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// compareOne(a: .intValue(1), b: .doubleValue(2.5)) == .doubleValue(2.5)
// compareOne(a: .intValue(1), b: .stringValue("2,3")) == .stringValue("2,3")
// compareOne(a: .stringValue("5,1"), b: .stringValue("6")) == .stringValue("6")
// compareOne(a: .stringValue("1"), b: .intValue(1)) == nil
func compareOne(a: Value, b: Value) -> Value? {
// Your code here
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareTwo(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareTwo(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareTwo(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareTwo(a:.stringValue("1"), b:.intValue(1)) == nil
func compareTwo(a: Value, b: Value) -> Value? {
// Your code here
}
```
} // missing return in global function expected to return 'Value?'
} // missing return in global function expected to return 'Value?'
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
func compareOne(a: Value, b: Value) -> Value? {
// Your code here
}
func compareTwo(a: Value, b: Value) -> Value? {
// Your code here
}
```swift
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// compareOne(a: .intValue(1), b: .doubleValue(2.5)) == .doubleValue(2.5)
// compareOne(a: .intValue(1), b: .stringValue("2,3")) == .stringValue("2,3")
// compareOne(a: .stringValue("5,1"), b: .stringValue("6")) == .stringValue("6")
// compareOne(a: .stringValue("1"), b: .intValue(1)) == nil
func compareOne(a: Value, b: Value) -> Value? {
// Your code here
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareTwo(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareTwo(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareTwo(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareTwo(a:.stringValue("1"), b:.intValue(1)) == nil
func compareTwo(a: Value, b: Value) -> Value? {
// Your code here
}
```
} // missing return in global function expected to return 'Value?'
} // missing return in global function expected to return 'Value?'
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
func compareOne(a: Value, b: Value) -> Value? {
// Your code here
}
func compareTwo(a: Value, b: Value) -> Value? {
// Your code here
}
```swift
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// compareOne(a: .intValue(1), b: .doubleValue(2.5)) == .doubleValue(2.5)
// compareOne(a: .intValue(1), b: .stringValue("2,3")) == .stringValue("2,3")
// compareOne(a: .stringValue("5,1"), b: .stringValue("6")) == .stringValue("6")
// compareOne(a: .stringValue("1"), b: .intValue(1)) == nil
func compareOne(a: Value, b: Value) -> Value? {
// Your code here
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareTwo(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareTwo(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareTwo(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareTwo(a:.stringValue("1"), b:.intValue(1)) == nil
func compareTwo(a: Value, b: Value) -> Value? {
// Your code here
}
```
} // missing return in global function expected to return 'Value?'
} // missing return in global function expected to return 'Value?'
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)):
return a > b?.intValue(a) : a < b?.intValue(b) : nil
case (.doubleValue(let a),.doubleValue(let b)):
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil
case (.stringValue(let a),.stringValue(let b)):
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil
default:
return nil
}
}
func compareTwo(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)):
return a > b?.intValue(a) : a < b?.intValue(b) : nil
case (.doubleValue(let a),.doubleValue(let b)):
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil
case (.stringValue(let a),.stringValue(let b)):
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil
default:
return nil
}
}
func compareThree(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)):
return a > b?.intValue(a) : a < b?.intValue(b) : nil
case (.doubleValue(let a),.doubleValue(let b)):
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil
case (.stringValue(let a),.stringValue(let b)):
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil
default:
return nil
}
}
```swift
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// compareOne(a: .intValue(1), b: .doubleValue(2.5)) == .doubleValue(2.5)
// compareOne(a: .intValue(1), b: .stringValue("2,3")) == .stringValue("2,3")
// compareOne(a: .stringValue("5,1"), b: .stringValue("6")) == .stringValue("6")
// compareOne(a: .stringValue("1"), b: .intValue(1)) == nil
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)):
return a > b?.intValue(a) : a < b?.intValue(b) : nil
case (.doubleValue(let a),.doubleValue(let b)):
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil
case (.stringValue(let a),.stringValue(let b)):
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil
default:
return nil
}
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareTwo(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareTwo(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareTwo(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareTwo(a:.stringValue("1"), b:.intValue(1)) == nil
func compareTwo(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)):
return a > b?.intValue(a) : a < b?.intValue(b) : nil
case (.doubleValue(let a),.doubleValue(let b)):
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil
case (.stringValue(let a),.stringValue(let b)):
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil
default:
return nil
}
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareThree(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareThree(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareThree(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareThree(a:.stringValue("1"), b:.intValue(1)) == nil
func compareThree(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)):
return a > b?.intValue(a) : a < b?.intValue(b) : nil
case (.doubleValue(let a),.doubleValue(let b)):
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil
case (.stringValue(let a),.stringValue(let b)):
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil
default:
return nil
}
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareFour(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareFour(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareFour(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareFour(a:.stringValue("1"), b:.intValue(1)) == nil
func compareFour(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)):
return a > b?.intValue(a) : a < b?.intValue(b) : nil
case (.doubleValue(let a),.doubleValue(let b)):
return a > b?.doubleValue(a) : a < b?.doubleValue(b
return a > b?.intValue(a) : a < b?.intValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // expected expression
return a > b?.intValue(a) : a < b?.intValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // value of type 'Int' has no member 'intValue'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // cannot use optional chaining on non-optional value of type 'Int'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // cannot use optional chaining on non-optional value of type 'Double'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // value of type 'Double' has no member 'doubleValue'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // expected expression
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // value of type 'String' has no member 'stringValue'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // value of optional type 'String?' must be unwrapped to a value of type 'String'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // cannot use optional chaining on non-optional value of type 'String'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // expected expression
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // value of type 'Int' has no member 'intValue'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // cannot use optional chaining on non-optional value of type 'Int'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // expected expression
return a > b?.intValue(a) : a < b?.intValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // expected expression
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // value of type 'Double' has no member 'doubleValue'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // cannot use optional chaining on non-optional value of type 'Double'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // cannot use optional chaining on non-optional value of type 'String'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // value of optional type 'String?' must be unwrapped to a value of type 'String'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // value of type 'String' has no member 'stringValue'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // expected expression
return a > b?.intValue(a) : a < b?.intValue(b) : nil // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // value of type 'Int' has no member 'intValue'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // expected expression
return a > b?.intValue(a) : a < b?.intValue(b) : nil // cannot use optional chaining on non-optional value of type 'Int'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // expected expression
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // value of type 'Double' has no member 'doubleValue'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // cannot use optional chaining on non-optional value of type 'Double'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // expected expression
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // value of type 'String' has no member 'stringValue'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // value of optional type 'String?' must be unwrapped to a value of type 'String'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // cannot use optional chaining on non-optional value of type 'String'
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
func compareOne(a: Value, b: Value) -> Value? {
// Your code here
}
func compareTwo(a: Value, b: Value) -> Value? {
// Your code here
}
```swift
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// compareOne(a: .intValue(1), b: .doubleValue(2.5)) == .doubleValue(2.5)
// compareOne(a: .intValue(1), b: .stringValue("2,3")) == .stringValue("2,3")
// compareOne(a: .stringValue("5,1"), b: .stringValue("6")) == .stringValue("6")
// compareOne(a: .stringValue("1"), b: .intValue(1)) == nil
func compareOne(a: Value, b: Value) -> Value? {
// Your code here
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareTwo(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareTwo(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareTwo(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareTwo(a:.stringValue("1"), b:.intValue(1)) == nil
func compareTwo(a: Value, b: Value) -> Value? {
// Your code here
}
```
} // missing return in global function expected to return 'Value?'
} // missing return in global function expected to return 'Value?'
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
func compareOne(a: Value, b: Value) -> Value? {
// Your code here
}
func compareTwo(a: Value, b: Value) -> Value? {
// Your code here
}
func compareThree(a: Value, b: Value) -> Value? {
// Your code here
}
func compareFour(a: Value, b: Value) -> Value? {
// Your code here
}
```swift
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// compareOne(a: .intValue(1), b: .doubleValue(2.5)) == .doubleValue(2.5)
// compareOne(a: .intValue(1), b: .stringValue("2,3")) == .stringValue("2,3")
// compareOne(a: .stringValue("5,1"), b: .stringValue("6")) == .stringValue("6")
// compareOne(a: .stringValue("1"), b: .intValue(1)) == nil
func compareOne(a: Value, b: Value) -> Value? {
// Your code here
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareTwo(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareTwo(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareTwo(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareTwo(a:.stringValue("1"), b:.intValue(1)) == nil
func compareTwo(a: Value, b: Value) -> Value? {
// Your code here
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareThree(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareThree(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareThree(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareThree(a:.stringValue("1"), b:.intValue(1)) == nil
func compareThree(a: Value, b: Value) -> Value? {
// Your code here
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareFour(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareFour(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareFour(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareFour(a:.stringValue("1"), b:.intValue(1)) == nil
func compareFour(a: Value, b: Value) -> Value? {
// Your code here
}
```
} // missing return in global function expected to return 'Value?'
} // missing return in global function expected to return 'Value?'
} // missing return in global function expected to return 'Value?'
} // missing return in global function expected to return 'Value?'
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)):
return a > b?.intValue(a) : a < b?.intValue(b) : nil
case (.doubleValue(let a),.doubleValue(let b)):
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil
case (.stringValue(let a),.stringValue(let b)):
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil
default:
return nil
}
}
func compareTwo(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)):
return a > b?.intValue(a) : a < b?.intValue(b) : nil
case (.doubleValue(let a),.doubleValue(let b)):
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil
case (.stringValue(let a),.stringValue(let b)):
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil
default:
return nil
}
}
func compareThree(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)):
return a > b?.intValue(a) : a < b?.intValue(b) : nil
case (.doubleValue(let a),.doubleValue(let b)):
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil
case (.stringValue(let a),.stringValue(let b)):
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil
default:
return nil
}
}
```swift
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// compareOne(a: .intValue(1), b: .doubleValue(2.5)) == .doubleValue(2.5)
// compareOne(a: .intValue(1), b: .stringValue("2,3")) == .stringValue("2,3")
// compareOne(a: .stringValue("5,1"), b: .stringValue("6")) == .stringValue("6")
// compareOne(a: .stringValue("1"), b: .intValue(1)) == nil
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)):
return a > b?.intValue(a) : a < b?.intValue(b) : nil
case (.doubleValue(let a),.doubleValue(let b)):
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil
case (.stringValue(let a),.stringValue(let b)):
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil
default:
return nil
}
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareTwo(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareTwo(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareTwo(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareTwo(a:.stringValue("1"), b:.intValue(1)) == nil
func compareTwo(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)):
return a > b?.intValue(a) : a < b?.intValue(b) : nil
case (.doubleValue(let a),.doubleValue(let b)):
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil
case (.stringValue(let a),.stringValue(let b)):
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil
default:
return nil
}
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareThree(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareThree(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareThree(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareThree(a:.stringValue("1"), b:.intValue(1)) == nil
func compareThree(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)):
return a > b?.intValue(a) : a < b?.intValue(b) : nil
case (.doubleValue(let a),.doubleValue(let b)):
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil
case (.stringValue(let a),.stringValue(let b)):
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil
default:
return nil
}
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareFour(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareFour(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareFour(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareFour(a:.stringValue("1"), b:.intValue(1)) == nil
func compareFour(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)):
return a > b?.intValue(a) : a < b?.intValue(b) : nil
case (.doubleValue(let a),.doubleValue(let b)):
return a > b?.doubleValue(a) : a < b?.doubleValue(b
return a > b?.intValue(a) : a < b?.intValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // expected expression
return a > b?.intValue(a) : a < b?.intValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // value of type 'Int' has no member 'intValue'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // cannot use optional chaining on non-optional value of type 'Int'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // cannot use optional chaining on non-optional value of type 'Double'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // value of type 'Double' has no member 'doubleValue'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // expected expression
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // value of type 'String' has no member 'stringValue'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // value of optional type 'String?' must be unwrapped to a value of type 'String'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // cannot use optional chaining on non-optional value of type 'String'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // expected expression
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // value of type 'Int' has no member 'intValue'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // cannot use optional chaining on non-optional value of type 'Int'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // expected expression
return a > b?.intValue(a) : a < b?.intValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // expected expression
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // value of type 'Double' has no member 'doubleValue'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // cannot use optional chaining on non-optional value of type 'Double'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // cannot use optional chaining on non-optional value of type 'String'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // value of optional type 'String?' must be unwrapped to a value of type 'String'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // value of type 'String' has no member 'stringValue'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // expected expression
return a > b?.intValue(a) : a < b?.intValue(b) : nil // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // value of type 'Int' has no member 'intValue'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // expected expression
return a > b?.intValue(a) : a < b?.intValue(b) : nil // cannot use optional chaining on non-optional value of type 'Int'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // expected expression
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // value of type 'Double' has no member 'doubleValue'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // cannot use optional chaining on non-optional value of type 'Double'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // expected expression
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // value of type 'String' has no member 'stringValue'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // value of optional type 'String?' must be unwrapped to a value of type 'String'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // cannot use optional chaining on non-optional value of type 'String'
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)):
return a > b?.intValue(a) : a < b?.intValue(b) : nil
case (.doubleValue(let a),.doubleValue(let b)):
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil
case (.stringValue(let a),.stringValue(let b)):
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil
default:
return nil
}
}
func compareTwo(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)):
return a > b?.intValue(a) : a < b?.intValue(b) : nil
case (.doubleValue(let a),.doubleValue(let b)):
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil
case (.stringValue(let a),.stringValue(let b)):
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil
default:
return nil
}
}
func compareThree(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)):
return a > b?.intValue(a) : a < b?.intValue(b) : nil
case (.doubleValue(let a),.doubleValue(let b)):
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil
case (.stringValue(let a),.stringValue(let b)):
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil
default:
return nil
}
}
```swift
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// compareOne(a: .intValue(1), b: .doubleValue(2.5)) == .doubleValue(2.5)
// compareOne(a: .intValue(1), b: .stringValue("2,3")) == .stringValue("2,3")
// compareOne(a: .stringValue("5,1"), b: .stringValue("6")) == .stringValue("6")
// compareOne(a: .stringValue("1"), b: .intValue(1)) == nil
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)):
return a > b?.intValue(a) : a < b?.intValue(b) : nil
case (.doubleValue(let a),.doubleValue(let b)):
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil
case (.stringValue(let a),.stringValue(let b)):
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil
default:
return nil
}
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareTwo(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareTwo(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareTwo(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareTwo(a:.stringValue("1"), b:.intValue(1)) == nil
func compareTwo(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)):
return a > b?.intValue(a) : a < b?.intValue(b) : nil
case (.doubleValue(let a),.doubleValue(let b)):
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil
case (.stringValue(let a),.stringValue(let b)):
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil
default:
return nil
}
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareThree(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareThree(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareThree(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareThree(a:.stringValue("1"), b:.intValue(1)) == nil
func compareThree(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)):
return a > b?.intValue(a) : a < b?.intValue(b) : nil
case (.doubleValue(let a),.doubleValue(let b)):
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil
case (.stringValue(let a),.stringValue(let b)):
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil
default:
return nil
}
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareFour(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareFour(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareFour(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareFour(a:.stringValue("1"), b:.intValue(1)) == nil
func compareFour(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)):
return a > b?.intValue(a) : a < b?.intValue(b) : nil
case (.doubleValue(let a),.doubleValue(let b)):
return a > b?.doubleValue(a) : a < b?.doubleValue(b
return a > b?.intValue(a) : a < b?.intValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // expected expression
return a > b?.intValue(a) : a < b?.intValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // value of type 'Int' has no member 'intValue'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // cannot use optional chaining on non-optional value of type 'Int'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // cannot use optional chaining on non-optional value of type 'Double'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // value of type 'Double' has no member 'doubleValue'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // expected expression
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // value of type 'String' has no member 'stringValue'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // value of optional type 'String?' must be unwrapped to a value of type 'String'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // cannot use optional chaining on non-optional value of type 'String'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // expected expression
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // value of type 'Int' has no member 'intValue'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // cannot use optional chaining on non-optional value of type 'Int'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // expected expression
return a > b?.intValue(a) : a < b?.intValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // expected expression
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // value of type 'Double' has no member 'doubleValue'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // cannot use optional chaining on non-optional value of type 'Double'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // cannot use optional chaining on non-optional value of type 'String'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // value of optional type 'String?' must be unwrapped to a value of type 'String'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // value of type 'String' has no member 'stringValue'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // expected expression
return a > b?.intValue(a) : a < b?.intValue(b) : nil // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // value of type 'Int' has no member 'intValue'
return a > b?.intValue(a) : a < b?.intValue(b) : nil // expected expression
return a > b?.intValue(a) : a < b?.intValue(b) : nil // cannot use optional chaining on non-optional value of type 'Int'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // expected expression
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // value of type 'Double' has no member 'doubleValue'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil // cannot use optional chaining on non-optional value of type 'Double'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // expected expression
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // consecutive statements on a line must be separated by ';'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // cannot convert return expression of type 'Bool' to return type 'Value?'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // value of type 'String' has no member 'stringValue'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // value of optional type 'String?' must be unwrapped to a value of type 'String'
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil // cannot use optional chaining on non-optional value of type 'String'
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
func compareOne(a: Value, b: Value) -> Value? {
// Your code here
}
func compareTwo(a: Value, b: Value) -> Value? {
// Your code here
}
func compareThree(a: Value, b: Value) -> Value? {
// Your code here
}
func compareFour(a: Value, b: Value) -> Value? {
// Your code here
}
func compareFive(a: Value, b: Value) -> Value? {
// Your code here
}
func compareSix(a: Value, b: Value) -> Value? {
// Your code here
}
```swift
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// compareOne(a: .intValue(1), b: .doubleValue(2.5)) == .doubleValue(2.5)
// compareOne(a: .intValue(1), b: .stringValue("2,3")) == .stringValue("2,3")
// compareOne(a: .stringValue("5,1"), b: .stringValue("6")) == .stringValue("6")
// compareOne(a: .stringValue("1"), b: .intValue(1)) == nil
func compareOne(a: Value, b: Value) -> Value? {
// Your code here
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareTwo(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareTwo(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareTwo(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareTwo(a:.stringValue("1"), b:.intValue(1)) == nil
func compareTwo(a: Value, b: Value) -> Value? {
// Your code here
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareThree(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareThree(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareThree(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareThree(a:.stringValue("1"), b:.intValue(1)) == nil
func compareThree(a: Value, b: Value) -> Value? {
// Your code here
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareFour(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareFour(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareFour(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareFour(a:.stringValue("1"), b:.intValue(1)) == nil
func compareFour(a: Value, b: Value) -> Value? {
// Your code here
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareFive(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareFive(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareFive(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareFive(a:.stringValue("1"), b:.intValue(1)) == nil
func compareFive(a: Value, b: Value) -> Value? {
// Your code here
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareSix(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareSix(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareSix(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareSix(a:.stringValue("1"), b:.intValue(1)) == nil
func compareSix(a: Value, b: Value) -> Value? {
// Your code here
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as
} // missing return in global function expected to return 'Value?'
} // missing return in global function expected to return 'Value?'
} // missing return in global function expected to return 'Value?'
} // missing return in global function expected to return 'Value?'
} // missing return in global function expected to return 'Value?'
} // missing return in global function expected to return 'Value?'
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
func compareOne(a: Value, b: Value) -> Value? {
// Your code here
}
func compareTwo(a: Value, b: Value) -> Value? {
// Your code here
}
```swift
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// compareOne(a: .intValue(1), b: .doubleValue(2.5)) == .doubleValue(2.5)
// compareOne(a: .intValue(1), b: .stringValue("2,3")) == .stringValue("2,3")
// compareOne(a: .stringValue("5,1"), b: .stringValue("6")) == .stringValue("6")
// compareOne(a: .stringValue("1"), b: .intValue(1)) == nil
func compareOne(a: Value, b: Value) -> Value? {
// Your code here
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareTwo(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareTwo(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareTwo(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareTwo(a:.stringValue("1"), b:.intValue(1)) == nil
func compareTwo(a: Value, b: Value) -> Value? {
// Your code here
}
```
} // missing return in global function expected to return 'Value?'
} // missing return in global function expected to return 'Value?'
func isEqualToSumEven(n: Int) -> Bool {
// Write your code here
}
```swift
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// isEqualToSumEven(n: 4) == false
// isEqualToSumEven(n: 6) == false
// isEqualToSumEven(n: 8) == true
func isEqualToSumEven(n: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isEqualToSumEven(n: Int) -> Bool {
// Write your code here
}
```swift
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// isEqualToSumEven(n: 4) == false
// isEqualToSumEven(n: 6) == false
// isEqualToSumEven(n: 8) == true
func isEqualToSumEven(n: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isEqualToSumEven(n: Int) -> Bool {
// Write your code here
}
```swift
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// isEqualToSumEven(n: 4) == false
// isEqualToSumEven(n: 6) == false
// isEqualToSumEven(n: 8) == true
func isEqualToSumEven(n: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isEqualToSumEven(n: Int) -> Bool {
// Write your code here
}
```swift
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// isEqualToSumEven(n: 4) == false
// isEqualToSumEven(n: 6) == false
// isEqualToSumEven(n: 8) == true
func isEqualToSumEven(n: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isEqualToSumEven(n: Int) -> Bool {
// Write your code here
}
```swift
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// isEqualToSumEven(n: 4) == false
// isEqualToSumEven(n: 6) == false
// isEqualToSumEven(n: 8) == true
func isEqualToSumEven(n: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isEqualToSumEven(n: Int) -> Bool {
// Write your code here
}
```swift
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// isEqualToSumEven(n: 4) == false
// isEqualToSumEven(n: 6) == false
// isEqualToSumEven(n: 8) == true
func isEqualToSumEven(n: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isEqualToSumEven(n: Int) -> Bool {
if n < 4 {
return false
}
if n % 2!= 0 {
return false
}
var n = n
var sum = 0
for i in 1...4 {
if n - 2 * i < 0 {
return false
}
sum += 2 * i
n -= 2 * i
}
return sum == n
}
```swift
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// isEqualToSumEven(n: 4) == false
// isEqualToSumEven(n: 6) == false
// isEqualToSumEven(n: 8) == true
func isEqualToSumEven(n: Int) -> Bool {
if n < 4 {
return false
}
if n % 2!= 0 {
return false
}
var n = n
var sum = 0
for i in 1...4 {
if n - 2 * i < 0 {
return false
}
sum += 2 * i
n -= 2 * i
}
return sum == n
}
```
if n % 2!= 0 { // '=' must have consistent whitespace on both sides
if n % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if n % 2!= 0 { // expression is not assignable: binary operator returns immutable value
if n % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
func isEqualToSumEven(n: Int) -> Bool {
// Write your code here
}
```swift
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// isEqualToSumEven(n: 4) == false
// isEqualToSumEven(n: 6) == false
// isEqualToSumEven(n: 8) == true
func isEqualToSumEven(n: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isEqualToSumEven(n: Int) -> Bool {
// Write your code here
}
```swift
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// isEqualToSumEven(n: 4) == false
// isEqualToSumEven(n: 6) == false
// isEqualToSumEven(n: 8) == true
func isEqualToSumEven(n: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isEqualToSumEven(n: Int) -> Bool {
var sum = 0
var i = 2
while sum < n {
sum += i
i += 2
}
return sum == n
}
```swift
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// isEqualToSumEven(n: 4) == false
// isEqualToSumEven(n: 6) == false
// isEqualToSumEven(n: 8) == true
func isEqualToSumEven(n: Int) -> Bool {
var sum = 0
var i = 2
while sum < n {
sum += i
i += 2
}
return sum == n
}
```
// XCTAssertTrue failed
func specialFactorial(n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
```swift
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// The function will receive an integer as input and should return the special
// factorial of this integer.
// specialFactorial(n: 4) == 288
func specialFactorial(n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
```
// XCTAssertTrue failed
func specialFactorial(n: Int) -> Int {
guard n > 0 else { return 0 }
return n * specialFactorial(n: n - 1)
}
```swift
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// The function will receive an integer as input and should return the special
// factorial of this integer.
// specialFactorial(n: 4) == 288
func specialFactorial(n: Int) -> Int {
guard n > 0 else { return 0 }
return n * specialFactorial(n: n - 1)
}
```
// XCTAssertTrue failed
func specialFactorial(n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
```swift
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// The function will receive an integer as input and should return the special
// factorial of this integer.
// specialFactorial(n: 4) == 288
func specialFactorial(n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
```
// XCTAssertTrue failed
func specialFactorial(n: Int) -> Int {
// your code here
}
```swift
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// The function will receive an integer as input and should return the special
// factorial of this integer.
// specialFactorial(n: 4) == 288
func specialFactorial(n: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func specialFactorial(n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
```swift
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// The function will receive an integer as input and should return the special
// factorial of this integer.
// specialFactorial(n: 4) == 288
func specialFactorial(n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
```
// XCTAssertTrue failed
func specialFactorial(n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
```swift
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// The function will receive an integer as input and should return the special
// factorial of this integer.
// specialFactorial(n: 4) == 288
func specialFactorial(n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
```
// XCTAssertTrue failed
func specialFactorial(n: Int) -> Int {
return n > 0? n * specialFactorial(n: n - 1) : 1
}
```swift
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// The function will receive an integer as input and should return the special
// factorial of this integer.
// specialFactorial(n: 4) == 288
func specialFactorial(n: Int) -> Int {
return n > 0? n * specialFactorial(n: n - 1) : 1
}
```
return n > 0? n * specialFactorial(n: n - 1) : 1 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
return n > 0? n * specialFactorial(n: n - 1) : 1 // consecutive statements on a line must be separated by ';'
return n > 0? n * specialFactorial(n: n - 1) : 1 // result of operator '*' is unused
return n > 0? n * specialFactorial(n: n - 1) : 1 // expected expression
return n > 0? n * specialFactorial(n: n - 1) : 1 // cannot use optional chaining on non-optional value of type 'Int'
return n > 0? n * specialFactorial(n: n - 1) : 1 // cannot convert return expression of type 'Bool' to return type 'Int'
return n > 0? n * specialFactorial(n: n - 1) : 1 // consecutive statements on a line must be separated by ';'
func specialFactorial(n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
```swift
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// The function will receive an integer as input and should return the special
// factorial of this integer.
// specialFactorial(n: 4) == 288
func specialFactorial(n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
```
// XCTAssertTrue failed
func specialFactorial(n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
```swift
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// The function will receive an integer as input and should return the special
// factorial of this integer.
// specialFactorial(n: 4) == 288
func specialFactorial(n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
```
// XCTAssertTrue failed
func specialFactorial(n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
```swift
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// The function will receive an integer as input and should return the special
// factorial of this integer.
// specialFactorial(n: 4) == 288
func specialFactorial(n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
```
// XCTAssertTrue failed
func fixSpaces(text: String) -> String {
var result = ""
for char in text {
if char == " " {
if result.last == " " {
result.removeLast()
result.append("-")
} else {
result.append("_")
}
} else {
result.append(char)
}
}
return result
}
```swift
// Given a string text, replace all spaces in it with underscores,
// and if a string has more than 2 consecutive spaces,
// then replace all consecutive spaces with -
// fixSpaces(text: " Example") == "Example"
// fixSpaces(text: " Example 1") == "Example_1"
// fixSpaces(text: " Example 2") == "_Example_2"
// fixSpaces(text: " Example 3") == "_Example-3"
func fixSpaces(text: String) -> String {
var result = ""
for char in text {
if char == " " {
if result.last == " " {
result.removeLast()
result.append("-")
} else {
result.append("_")
}
} else {
result.append(char)
}
}
return result
}
```
// XCTAssertTrue failed
func fixSpaces(text: String) -> String {
var result = ""
for char in text {
if char == " " {
if result.last == " " {
result.removeLast()
result += "-"
} else {
result += "_"
}
} else {
result += String(char)
}
}
return result
}
```swift
// Given a string text, replace all spaces in it with underscores,
// and if a string has more than 2 consecutive spaces,
// then replace all consecutive spaces with -
// fixSpaces(text: " Example") == "Example"
// fixSpaces(text: " Example 1") == "Example_1"
// fixSpaces(text: " Example 2") == "_Example_2"
// fixSpaces(text: " Example 3") == "_Example-3"
func fixSpaces(text: String) -> String {
var result = ""
for char in text {
if char == " " {
if result.last == " " {
result.removeLast()
result += "-"
} else {
result += "_"
}
} else {
result += String(char)
}
}
return result
}
```
// XCTAssertTrue failed
func fixSpaces(text: String) -> String {
var result = ""
for char in text {
if char == " " {
if result.last == " " {
result.removeLast()
result += "-"
} else {
result += "_"
}
} else {
result += String(char)
}
}
return result
}
```swift
// Given a string text, replace all spaces in it with underscores,
// and if a string has more than 2 consecutive spaces,
// then replace all consecutive spaces with -
// fixSpaces(text: " Example") == "Example"
// fixSpaces(text: " Example 1") == "Example_1"
// fixSpaces(text: " Example 2") == "_Example_2"
// fixSpaces(text: " Example 3") == "_Example-3"
func fixSpaces(text: String) -> String {
var result = ""
for char in text {
if char == " " {
if result.last == " " {
result.removeLast()
result += "-"
} else {
result += "_"
}
} else {
result += String(char)
}
}
return result
}
```
// XCTAssertTrue failed
func fixSpaces(text: String) -> String {
var result = ""
for char in text {
if char == " " {
if result.last == " " {
result.removeLast()
result += "-"
} else {
result += "_"
}
} else {
result += String(char)
}
}
return result
}
```swift
// Given a string text, replace all spaces in it with underscores,
// and if a string has more than 2 consecutive spaces,
// then replace all consecutive spaces with -
// fixSpaces(text: " Example") == "Example"
// fixSpaces(text: " Example 1") == "Example_1"
// fixSpaces(text: " Example 2") == "_Example_2"
// fixSpaces(text: " Example 3") == "_Example-3"
func fixSpaces(text: String) -> String {
var result = ""
for char in text {
if char == " " {
if result.last == " " {
result.removeLast()
result += "-"
} else {
result += "_"
}
} else {
result += String(char)
}
}
return result
}
```
// XCTAssertTrue failed
func fixSpaces(text: String) -> String {
return ""
}
```swift
// Given a string text, replace all spaces in it with underscores,
// and if a string has more than 2 consecutive spaces,
// then replace all consecutive spaces with -
// fixSpaces(text: " Example") == "Example"
// fixSpaces(text: " Example 1") == "Example_1"
// fixSpaces(text: " Example 2") == "_Example_2"
// fixSpaces(text: " Example 3") == "_Example-3"
func fixSpaces(text: String) -> String {
return ""
}
```
// XCTAssertTrue failed
func fixSpaces(text: String) -> String {
var result = ""
for char in text {
if char == " " {
if result.last == " " {
result.removeLast()
result += "-"
} else {
result += "_"
}
} else {
result += String(char)
}
}
return result
}
```swift
// Given a string text, replace all spaces in it with underscores,
// and if a string has more than 2 consecutive spaces,
// then replace all consecutive spaces with -
// fixSpaces(text: " Example") == "Example"
// fixSpaces(text: " Example 1") == "Example_1"
// fixSpaces(text: " Example 2") == "_Example_2"
// fixSpaces(text: " Example 3") == "_Example-3"
func fixSpaces(text: String) -> String {
var result = ""
for char in text {
if char == " " {
if result.last == " " {
result.removeLast()
result += "-"
} else {
result += "_"
}
} else {
result += String(char)
}
}
return result
}
```
// XCTAssertTrue failed
func fixSpaces(text: String) -> String {
var result = ""
var count = 0
for char in text {
if char == " " {
count += 1
} else {
if count == 0 {
result.append(char)
} else if count == 1 {
result.append("_")
result.append(char)
count = 0
} else if count == 2 {
result.append("-")
result.append(char)
count = 0
} else {
result.append(char)
count = 0
}
}
}
return result
}
```swift
// Given a string text, replace all spaces in it with underscores,
// and if a string has more than 2 consecutive spaces,
// then replace all consecutive spaces with -
// fixSpaces(text: " Example") == "Example"
// fixSpaces(text: " Example 1") == "Example_1"
// fixSpaces(text: " Example 2") == "_Example_2"
// fixSpaces(text: " Example 3") == "_Example-3"
func fixSpaces(text: String) -> String {
var result = ""
var count = 0
for char in text {
if char == " " {
count += 1
} else {
if count == 0 {
result.append(char)
} else if count == 1 {
result.append("_")
result.append(char)
count = 0
} else if count == 2 {
result.append("-")
result.append(char)
count = 0
} else {
result.append(char)
count = 0
}
}
}
return result
}
```
// XCTAssertTrue failed
func fixSpaces(text: String) -> String {
var result = ""
for char in text {
if char == " " {
if result.last == " " {
result.removeLast()
result += "-"
} else {
result += "_"
}
} else {
result += String(char)
}
}
return result
}
```swift
// Given a string text, replace all spaces in it with underscores,
// and if a string has more than 2 consecutive spaces,
// then replace all consecutive spaces with -
// fixSpaces(text: " Example") == "Example"
// fixSpaces(text: " Example 1") == "Example_1"
// fixSpaces(text: " Example 2") == "_Example_2"
// fixSpaces(text: " Example 3") == "_Example-3"
func fixSpaces(text: String) -> String {
var result = ""
for char in text {
if char == " " {
if result.last == " " {
result.removeLast()
result += "-"
} else {
result += "_"
}
} else {
result += String(char)
}
}
return result
}
```
// XCTAssertTrue failed
func fixSpaces(text: String) -> String {
var result = ""
var count = 0
for char in text {
if char == " " {
count += 1
} else {
if count > 1 {
result += "-"
} else {
result += "_"
}
count = 0
}
result += String(char)
}
return result
}
```swift
// Given a string text, replace all spaces in it with underscores,
// and if a string has more than 2 consecutive spaces,
// then replace all consecutive spaces with -
// fixSpaces(text: " Example") == "Example"
// fixSpaces(text: " Example 1") == "Example_1"
// fixSpaces(text: " Example 2") == "_Example_2"
// fixSpaces(text: " Example 3") == "_Example-3"
func fixSpaces(text: String) -> String {
var result = ""
var count = 0
for char in text {
if char == " " {
count += 1
} else {
if count > 1 {
result += "-"
} else {
result += "_"
}
count = 0
}
result += String(char)
}
return result
}
```
// XCTAssertTrue failed
func fixSpaces(text: String) -> String {
var result = ""
for char in text {
if char == " " {
if result.last == " " {
result.removeLast()
result.append("-")
} else {
result.append("_")
}
} else {
result.append(char)
}
}
return result
}
```swift
// Given a string text, replace all spaces in it with underscores,
// and if a string has more than 2 consecutive spaces,
// then replace all consecutive spaces with -
// fixSpaces(text: " Example") == "Example"
// fixSpaces(text: " Example 1") == "Example_1"
// fixSpaces(text: " Example 2") == "_Example_2"
// fixSpaces(text: " Example 3") == "_Example-3"
func fixSpaces(text: String) -> String {
var result = ""
for char in text {
if char == " " {
if result.last == " " {
result.removeLast()
result.append("-")
} else {
result.append("_")
}
} else {
result.append(char)
}
}
return result
}
```
// XCTAssertTrue failed
func fileNameCheck(fileName: String) -> String {
// Write your code here
}
```swift
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// fileNameCheck(fileName: "example.txt") == "Yes"
// fileNameCheck(fileName: "1example.dll") == "No"
func fileNameCheck(fileName: String) -> String {
// Write your code here
}
```
} // missing return in global function expected to return 'String'
func fileNameCheck(fileName: String) -> String {
// Write your code here
}
```swift
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// fileNameCheck(fileName: "example.txt") == "Yes"
// fileNameCheck(fileName: "1example.dll") == "No"
func fileNameCheck(fileName: String) -> String {
// Write your code here
}
```
} // missing return in global function expected to return 'String'
func fileNameCheck(fileName: String) -> String {
// Write your code here
}
```swift
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// fileNameCheck(fileName: "example.txt") == "Yes"
// fileNameCheck(fileName: "1example.dll") == "No"
func fileNameCheck(fileName: String) -> String {
// Write your code here
}
```
} // missing return in global function expected to return 'String'
func fileNameCheck(fileName: String) -> String {
return ""
}
```swift
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// fileNameCheck(fileName: "example.txt") == "Yes"
// fileNameCheck(fileName: "1example.dll") == "No"
func fileNameCheck(fileName: String) -> String {
return ""
}
```
// XCTAssertTrue failed
func fileNameCheck(fileName: String) -> String {
// Write your code here
}
```swift
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// fileNameCheck(fileName: "example.txt") == "Yes"
// fileNameCheck(fileName: "1example.dll") == "No"
func fileNameCheck(fileName: String) -> String {
// Write your code here
}
```
} // missing return in global function expected to return 'String'
func fileNameCheck(fileName: String) -> String {
// Your code here
}
```swift
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// fileNameCheck(fileName: "example.txt") == "Yes"
// fileNameCheck(fileName: "1example.dll") == "No"
func fileNameCheck(fileName: String) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func fileNameCheck(fileName: String) -> String {
return "Yes"
}
```swift
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// fileNameCheck(fileName: "example.txt") == "Yes"
// fileNameCheck(fileName: "1example.dll") == "No"
func fileNameCheck(fileName: String) -> String {
return "Yes"
}
```
// XCTAssertTrue failed
func fileNameCheck(fileName: String) -> String {
// Your code here
}
```swift
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// fileNameCheck(fileName: "example.txt") == "Yes"
// fileNameCheck(fileName: "1example.dll") == "No"
func fileNameCheck(fileName: String) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func fileNameCheck(fileName: String) -> String {
return "Yes"
}
```swift
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// fileNameCheck(fileName: "example.txt") == "Yes"
// fileNameCheck(fileName: "1example.dll") == "No"
func fileNameCheck(fileName: String) -> String {
return "Yes"
}
```
// XCTAssertTrue failed
func fileNameCheck(fileName: String) -> String {
// Your code goes here
}
```swift
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// fileNameCheck(fileName: "example.txt") == "Yes"
// fileNameCheck(fileName: "1example.dll") == "No"
func fileNameCheck(fileName: String) -> String {
// Your code goes here
}
```
} // missing return in global function expected to return 'String'
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
var result = ""
for word in words {
if isPrime(word.count) {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
```swift
// You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// Example 2:
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
// wordsInSentence(sentence: "This is a test") == "is"
// wordsInSentence(sentence: "lets go for swimming") == "go for"
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
var result = ""
for word in words {
if isPrime(word.count) {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
```
if isPrime(word.count) { // cannot find 'isPrime' in scope
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
var result = ""
for word in words {
if primes.contains(word.count) {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
```swift
// You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// Example 2:
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
// wordsInSentence(sentence: "This is a test") == "is"
// wordsInSentence(sentence: "lets go for swimming") == "go for"
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
var result = ""
for word in words {
if primes.contains(word.count) {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
```
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
var result = ""
for word in words {
if primes.contains(word.count) {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
```swift
// You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// Example 2:
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
// wordsInSentence(sentence: "This is a test") == "is"
// wordsInSentence(sentence: "lets go for swimming") == "go for"
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
var result = ""
for word in words {
if primes.contains(word.count) {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
```
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
var result = ""
for word in words {
if primes.contains(word.count) {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
```swift
// You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// Example 2:
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
// wordsInSentence(sentence: "This is a test") == "is"
// wordsInSentence(sentence: "lets go for swimming") == "go for"
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
var result = ""
for word in words {
if primes.contains(word.count) {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
```
func wordsInSentence(sentence: String) -> String {
var result = ""
let words = sentence.split(separator: " ")
for word in words {
if isPrime(word.count) {
result += "\(word) "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
if n <= 3 {
return true
}
if n % 2 == 0 || n % 3 == 0 {
return false
}
var i = 5
while i * i <= n {
if n % i == 0 || n % (i + 2) == 0 {
return false
}
i += 6
}
return true
}
```swift
// You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// Example 2:
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
// wordsInSentence(sentence: "This is a test") == "is"
// wordsInSentence(sentence: "lets go for swimming") == "go for"
func wordsInSentence(sentence: String) -> String {
var result = ""
let words = sentence.split(separator: " ")
for word in words {
if isPrime(word.count) {
result += "\(word) "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
if n <= 3 {
return true
}
if n % 2 == 0 || n % 3 == 0 {
return false
}
var i = 5
while i * i <= n {
if n % i == 0 || n % (i + 2) == 0 {
return false
}
i += 6
}
return true
}
```
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
var result = ""
for word in words {
if isPrime(word.count) {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
if n <= 3 {
return true
}
if n % 2 == 0 || n % 3 == 0 {
return false
}
var i = 5
while i * i <= n {
if n % i == 0 || n % (i + 2) == 0 {
return false
}
i += 6
}
return true
}
```swift
// You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// Example 2:
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
// wordsInSentence(sentence: "This is a test") == "is"
// wordsInSentence(sentence: "lets go for swimming") == "go for"
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
var result = ""
for word in words {
if isPrime(word.count) {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
if n <= 3 {
return true
}
if n % 2 == 0 || n % 3 == 0 {
return false
}
var i = 5
while i * i <= n {
if n % i == 0 || n % (i + 2) == 0 {
return false
}
i += 6
}
return true
}
```
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
var result = ""
for word in words {
if primes.contains(word.count) {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
```swift
// You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// Example 2:
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
// wordsInSentence(sentence: "This is a test") == "is"
// wordsInSentence(sentence: "lets go for swimming") == "go for"
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
var result = ""
for word in words {
if primes.contains(word.count) {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
```
func wordsInSentence(sentence: String) -> String {
return ""
}
```swift
// You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// Example 2:
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
// wordsInSentence(sentence: "This is a test") == "is"
// wordsInSentence(sentence: "lets go for swimming") == "go for"
func wordsInSentence(sentence: String) -> String {
return ""
}
```
// XCTAssertTrue failed
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
let primeNumbers = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
var result = ""
for word in words {
if primeNumbers.contains(word.count) {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
```swift
// You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// Example 2:
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
// wordsInSentence(sentence: "This is a test") == "is"
// wordsInSentence(sentence: "lets go for swimming") == "go for"
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
let primeNumbers = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
var result = ""
for word in words {
if primeNumbers.contains(word.count) {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
```
func wordsInSentence(sentence: String) -> String {
return ""
}
```swift
// You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// Example 2:
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
// wordsInSentence(sentence: "This is a test") == "is"
// wordsInSentence(sentence: "lets go for swimming") == "go for"
func wordsInSentence(sentence: String) -> String {
return ""
}
```
// XCTAssertTrue failed
func simplify(x: String, n: String) -> Bool {
// Your code goes here
}
```swift
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a whole number and false
// otherwise. Both x and n, are string representation of a fraction, and have the following format,
// <numerator>/<denominator> where both numerator and denominator are positive whole numbers.
// You can assume that x, and n are valid fractions, and do not have zero as denominator.
// simplify(x: "1/5", n: "5/1") == true
// simplify(x: "1/6", n: "2/1") == false
// simplify(x: "7/10", n: "10/2") == false
func simplify(x: String, n: String) -> Bool {
// Your code goes here
}
```
} // missing return in global function expected to return 'Bool'
func simplify(x: String, n: String) -> Bool {
// your code here
}
```swift
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a whole number and false
// otherwise. Both x and n, are string representation of a fraction, and have the following format,
// <numerator>/<denominator> where both numerator and denominator are positive whole numbers.
// You can assume that x, and n are valid fractions, and do not have zero as denominator.
// simplify(x: "1/5", n: "5/1") == true
// simplify(x: "1/6", n: "2/1") == false
// simplify(x: "7/10", n: "10/2") == false
func simplify(x: String, n: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func simplify(x: String, n: String) -> Bool {
let x = x.split(separator: "/")
let n = n.split(separator: "/")
let xNumerator = Int(x[0])!
let xDenominator = Int(x[1])!
let nNumerator = Int(n[0])!
let nDenominator = Int(n[1])!
let xResult = xNumerator * nDenominator
let nResult = nNumerator * xDenominator
return xResult == nResult
}
```swift
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a whole number and false
// otherwise. Both x and n, are string representation of a fraction, and have the following format,
// <numerator>/<denominator> where both numerator and denominator are positive whole numbers.
// You can assume that x, and n are valid fractions, and do not have zero as denominator.
// simplify(x: "1/5", n: "5/1") == true
// simplify(x: "1/6", n: "2/1") == false
// simplify(x: "7/10", n: "10/2") == false
func simplify(x: String, n: String) -> Bool {
let x = x.split(separator: "/")
let n = n.split(separator: "/")
let xNumerator = Int(x[0])!
let xDenominator = Int(x[1])!
let nNumerator = Int(n[0])!
let nDenominator = Int(n[1])!
let xResult = xNumerator * nDenominator
let nResult = nNumerator * xDenominator
return xResult == nResult
}
```
// XCTAssertTrue failed
func simplify(x: String, n: String) -> Bool {
return false
}
```swift
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a whole number and false
// otherwise. Both x and n, are string representation of a fraction, and have the following format,
// <numerator>/<denominator> where both numerator and denominator are positive whole numbers.
// You can assume that x, and n are valid fractions, and do not have zero as denominator.
// simplify(x: "1/5", n: "5/1") == true
// simplify(x: "1/6", n: "2/1") == false
// simplify(x: "7/10", n: "10/2") == false
func simplify(x: String, n: String) -> Bool {
return false
}
```
// XCTAssertTrue failed
func simplify(x: String, n: String) -> Bool {
let x = x.split(separator: "/")
let n = n.split(separator: "/")
let xNumerator = Int(String(x[0]))!
let xDenominator = Int(String(x[1]))!
let nNumerator = Int(String(n[0]))!
let nDenominator = Int(String(n[1]))!
let xProduct = xNumerator * nDenominator
let nProduct = nNumerator * xDenominator
return xProduct == nProduct
}
```swift
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a whole number and false
// otherwise. Both x and n, are string representation of a fraction, and have the following format,
// <numerator>/<denominator> where both numerator and denominator are positive whole numbers.
// You can assume that x, and n are valid fractions, and do not have zero as denominator.
// simplify(x: "1/5", n: "5/1") == true
// simplify(x: "1/6", n: "2/1") == false
// simplify(x: "7/10", n: "10/2") == false
func simplify(x: String, n: String) -> Bool {
let x = x.split(separator: "/")
let n = n.split(separator: "/")
let xNumerator = Int(String(x[0]))!
let xDenominator = Int(String(x[1]))!
let nNumerator = Int(String(n[0]))!
let nDenominator = Int(String(n[1]))!
let xProduct = xNumerator * nDenominator
let nProduct = nNumerator * xDenominator
return xProduct == nProduct
}
```
// XCTAssertTrue failed
func simplify(x: String, n: String) -> Bool {
// Your code goes here
}
```swift
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a whole number and false
// otherwise. Both x and n, are string representation of a fraction, and have the following format,
// <numerator>/<denominator> where both numerator and denominator are positive whole numbers.
// You can assume that x, and n are valid fractions, and do not have zero as denominator.
// simplify(x: "1/5", n: "5/1") == true
// simplify(x: "1/6", n: "2/1") == false
// simplify(x: "7/10", n: "10/2") == false
func simplify(x: String, n: String) -> Bool {
// Your code goes here
}
```
} // missing return in global function expected to return 'Bool'
func simplify(x: String, n: String) -> Bool {
return true
}
```swift
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a whole number and false
// otherwise. Both x and n, are string representation of a fraction, and have the following format,
// <numerator>/<denominator> where both numerator and denominator are positive whole numbers.
// You can assume that x, and n are valid fractions, and do not have zero as denominator.
// simplify(x: "1/5", n: "5/1") == true
// simplify(x: "1/6", n: "2/1") == false
// simplify(x: "7/10", n: "10/2") == false
func simplify(x: String, n: String) -> Bool {
return true
}
```
// XCTAssertTrue failed
func simplify(x: String, n: String) -> Bool {
return true
}
```swift
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a whole number and false
// otherwise. Both x and n, are string representation of a fraction, and have the following format,
// <numerator>/<denominator> where both numerator and denominator are positive whole numbers.
// You can assume that x, and n are valid fractions, and do not have zero as denominator.
// simplify(x: "1/5", n: "5/1") == true
// simplify(x: "1/6", n: "2/1") == false
// simplify(x: "7/10", n: "10/2") == false
func simplify(x: String, n: String) -> Bool {
return true
}
```
// XCTAssertTrue failed
func simplify(x: String, n: String) -> Bool {
// your code here
}
```swift
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a whole number and false
// otherwise. Both x and n, are string representation of a fraction, and have the following format,
// <numerator>/<denominator> where both numerator and denominator are positive whole numbers.
// You can assume that x, and n are valid fractions, and do not have zero as denominator.
// simplify(x: "1/5", n: "5/1") == true
// simplify(x: "1/6", n: "2/1") == false
// simplify(x: "7/10", n: "10/2") == false
func simplify(x: String, n: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func simplify(x: String, n: String) -> Bool {
let x = x.split(separator: "/")
let n = n.split(separator: "/")
let xNumerator = Int(x[0])!
let xDenominator = Int(x[1])!
let nNumerator = Int(n[0])!
let nDenominator = Int(n[1])!
let xProduct = xNumerator * nDenominator
let nProduct = nNumerator * xDenominator
return xProduct == nProduct
}
```swift
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a whole number and false
// otherwise. Both x and n, are string representation of a fraction, and have the following format,
// <numerator>/<denominator> where both numerator and denominator are positive whole numbers.
// You can assume that x, and n are valid fractions, and do not have zero as denominator.
// simplify(x: "1/5", n: "5/1") == true
// simplify(x: "1/6", n: "2/1") == false
// simplify(x: "7/10", n: "10/2") == false
func simplify(x: String, n: String) -> Bool {
let x = x.split(separator: "/")
let n = n.split(separator: "/")
let xNumerator = Int(x[0])!
let xDenominator = Int(x[1])!
let nNumerator = Int(n[0])!
let nDenominator = Int(n[1])!
let xProduct = xNumerator * nDenominator
let nProduct = nNumerator * xDenominator
return xProduct == nProduct
}
```
// XCTAssertTrue failed
func orderByPoints(nums: [Int]) -> [Int] {
// Your code here
}
```swift
// Write a function which sorts the given array of integers
// in ascending order according to the sum of their digits.
// Note: if there are several items with similar sum of their digits,
// order them based on their index in original array.
// For example:
// orderByPoints(nums: [1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]
// orderByPoints(nums: [] as [Int]) == [] as [Int]
func orderByPoints(nums: [Int]) -> [Int] {
// Your code here
}
```
} // missing return in global function expected to return '[Int]'
func orderByPoints(nums: [Int]) -> [Int] {
// TODO: Write your code here
}
```swift
// Write a function which sorts the given array of integers
// in ascending order according to the sum of their digits.
// Note: if there are several items with similar sum of their digits,
// order them based on their index in original array.
// For example:
// orderByPoints(nums: [1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]
// orderByPoints(nums: [] as [Int]) == [] as [Int]
func orderByPoints(nums: [Int]) -> [Int] {
// TODO: Write your code here
}
```
} // missing return in global function expected to return '[Int]'
func orderByPoints(nums: [Int]) -> [Int] {
// your code here
}
```swift
// Write a function which sorts the given array of integers
// in ascending order according to the sum of their digits.
// Note: if there are several items with similar sum of their digits,
// order them based on their index in original array.
// For example:
// orderByPoints(nums: [1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]
// orderByPoints(nums: [] as [Int]) == [] as [Int]
func orderByPoints(nums: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func orderByPoints(nums: [Int]) -> [Int] {
// Your code here
}
```swift
// Write a function which sorts the given array of integers
// in ascending order according to the sum of their digits.
// Note: if there are several items with similar sum of their digits,
// order them based on their index in original array.
// For example:
// orderByPoints(nums: [1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]
// orderByPoints(nums: [] as [Int]) == [] as [Int]
func orderByPoints(nums: [Int]) -> [Int] {
// Your code here
}
```
} // missing return in global function expected to return '[Int]'
func orderByPoints(nums: [Int]) -> [Int] {
// Your code here
}
```swift
// Write a function which sorts the given array of integers
// in ascending order according to the sum of their digits.
// Note: if there are several items with similar sum of their digits,
// order them based on their index in original array.
// For example:
// orderByPoints(nums: [1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]
// orderByPoints(nums: [] as [Int]) == [] as [Int]
func orderByPoints(nums: [Int]) -> [Int] {
// Your code here
}
```
} // missing return in global function expected to return '[Int]'
func orderByPoints(nums: [Int]) -> [Int] {
// your code here
}
```swift
// Write a function which sorts the given array of integers
// in ascending order according to the sum of their digits.
// Note: if there are several items with similar sum of their digits,
// order them based on their index in original array.
// For example:
// orderByPoints(nums: [1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]
// orderByPoints(nums: [] as [Int]) == [] as [Int]
func orderByPoints(nums: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func orderByPoints(nums: [Int]) -> [Int] {
return nums.sorted { (a, b) -> Bool in
let sumA = a.digits.reduce(0, +)
let sumB = b.digits.reduce(0, +)
if sumA == sumB {
return a < b
}
return sumA < sumB
}
}
```swift
// Write a function which sorts the given array of integers
// in ascending order according to the sum of their digits.
// Note: if there are several items with similar sum of their digits,
// order them based on their index in original array.
// For example:
// orderByPoints(nums: [1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]
// orderByPoints(nums: [] as [Int]) == [] as [Int]
func orderByPoints(nums: [Int]) -> [Int] {
return nums.sorted { (a, b) -> Bool in
let sumA = a.digits.reduce(0, +)
let sumB = b.digits.reduce(0, +)
if sumA == sumB {
return a < b
}
return sumA < sumB
}
}
```
let sumA = a.digits.reduce(0, +) // value of type 'Int' has no member 'digits'
func orderByPoints(nums: [Int]) -> [Int] {
// Your code goes here
}
```swift
// Write a function which sorts the given array of integers
// in ascending order according to the sum of their digits.
// Note: if there are several items with similar sum of their digits,
// order them based on their index in original array.
// For example:
// orderByPoints(nums: [1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]
// orderByPoints(nums: [] as [Int]) == [] as [Int]
func orderByPoints(nums: [Int]) -> [Int] {
// Your code goes here
}
```
} // missing return in global function expected to return '[Int]'
func orderByPoints(nums: [Int]) -> [Int] {
// Your code here
}
```swift
// Write a function which sorts the given array of integers
// in ascending order according to the sum of their digits.
// Note: if there are several items with similar sum of their digits,
// order them based on their index in original array.
// For example:
// orderByPoints(nums: [1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]
// orderByPoints(nums: [] as [Int]) == [] as [Int]
func orderByPoints(nums: [Int]) -> [Int] {
// Your code here
}
```
} // missing return in global function expected to return '[Int]'
func orderByPoints(nums: [Int]) -> [Int] {
// your code here
}
```swift
// Write a function which sorts the given array of integers
// in ascending order according to the sum of their digits.
// Note: if there are several items with similar sum of their digits,
// order them based on their index in original array.
// For example:
// orderByPoints(nums: [1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]
// orderByPoints(nums: [] as [Int]) == [] as [Int]
func orderByPoints(nums: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 10 % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```swift
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 10 % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 {
count += 1
}
}
return count
}
```swift
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 {
count += 1
}
}
return count
}
```
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // cannot convert value of type 'Int' to expected argument type 'Bool'
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // use of '=' in a boolean context, did you mean '=='?
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // cannot convert value of type 'Int' to expected argument type 'Bool'
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // '=' must have consistent whitespace on both sides
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // cannot force unwrap value of non-optional type 'Int'
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // '=' must have consistent whitespace on both sides
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // expression is not assignable: '&&' returns immutable value
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // '=' must have consistent whitespace on both sides
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // cannot convert value of type 'Int' to expected argument type 'Bool'
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // expression is not assignable: '&&' returns immutable value
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // cannot force unwrap value of non-optional type 'Int'
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // integer literal value '0' cannot be used as a boolean; did you mean 'false'?
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // cannot force unwrap value of non-optional type 'Int'
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // '=' must have consistent whitespace on both sides
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // cannot force unwrap value of non-optional type 'Int'
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // expression is not assignable: '&&' returns immutable value
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // expression is not assignable: '&&' returns immutable value
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // cannot convert value of type 'Int' to expected argument type 'Bool'
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // cannot force unwrap value of non-optional type 'Int'
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // expression is not assignable: '&&' returns immutable value
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // expression is not assignable: '&&' returns immutable value
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // '=' must have consistent whitespace on both sides
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // cannot force unwrap value of non-optional type 'Int'
if num > 10 && num % 10!= 0 && num % 10!= 5 && num % 10!= 6 && num % 10!= 7 && num % 10!= 8 && num % 10!= 9 { // '=' must have consistent whitespace on both sides
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 10 % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```swift
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 10 % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 10 % 2 == 1 && num % 2 == 1 {
count += 1
}
}
return count
}
```swift
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 10 % 2 == 1 && num % 2 == 1 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 10 % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```swift
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 10 % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 10 % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```swift
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 10 % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 10 % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```swift
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 10 % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 10 % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```swift
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 10 % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 10 % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```swift
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 10 % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 10 % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```swift
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 10 % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func getMaxTriples(n: Int) -> Int {
var count = 0
for i in 1...n {
for j in i+1...n {
for k in j+1...n {
if (i+j+k)%3 == 0 {
count += 1
}
}
}
}
return count
}
```swift
// You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// Explanation:
// a = [1, 3, 7, 13, 21]
// The only valid triple is (1, 7, 13).
// getMaxTriples(n: 5) == 1
func getMaxTriples(n: Int) -> Int {
var count = 0
for i in 1...n {
for j in i+1...n {
for k in j+1...n {
if (i+j+k)%3 == 0 {
count += 1
}
}
}
}
return count
}
```
// Fatal error: Range requires lowerBound <= upperBound
func getMaxTriples(n: Int) -> Int {
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
var count = 0
for i in 0..<n {
for j in i+1..<n {
for k in j+1..<n {
if a[i] + a[j] + a[k] % 3 == 0 {
count += 1
}
}
}
}
return count
}
```swift
// You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// Explanation:
// a = [1, 3, 7, 13, 21]
// The only valid triple is (1, 7, 13).
// getMaxTriples(n: 5) == 1
func getMaxTriples(n: Int) -> Int {
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
var count = 0
for i in 0..<n {
for j in i+1..<n {
for k in j+1..<n {
if a[i] + a[j] + a[k] % 3 == 0 {
count += 1
}
}
}
}
return count
}
```
// XCTAssertTrue failed
func getMaxTriples(n: Int) -> Int {
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
var count = 0
for i in 0..<a.count {
for j in i + 1..<a.count {
for k in j + 1..<a.count {
if a[i] + a[j] + a[k] % 3 == 0 {
count += 1
}
}
}
}
return count
}
```swift
// You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// Explanation:
// a = [1, 3, 7, 13, 21]
// The only valid triple is (1, 7, 13).
// getMaxTriples(n: 5) == 1
func getMaxTriples(n: Int) -> Int {
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
var count = 0
for i in 0..<a.count {
for j in i + 1..<a.count {
for k in j + 1..<a.count {
if a[i] + a[j] + a[k] % 3 == 0 {
count += 1
}
}
}
}
return count
}
```
// XCTAssertTrue failed
func getMaxTriples(n: Int) -> Int {
var count = 0
for i in 1...n {
for j in i+1...n {
for k in j+1...n {
if i+j+k % 3 == 0 {
count += 1
}
}
}
}
return count
}
```swift
// You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// Explanation:
// a = [1, 3, 7, 13, 21]
// The only valid triple is (1, 7, 13).
// getMaxTriples(n: 5) == 1
func getMaxTriples(n: Int) -> Int {
var count = 0
for i in 1...n {
for j in i+1...n {
for k in j+1...n {
if i+j+k % 3 == 0 {
count += 1
}
}
}
}
return count
}
```
// Fatal error: Range requires lowerBound <= upperBound
func getMaxTriples(n: Int) -> Int {
var count = 0
for i in 1...n {
for j in i+1...n {
for k in j+1...n {
if (i + j + k) % 3 == 0 {
count += 1
}
}
}
}
return count
}
```swift
// You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// Explanation:
// a = [1, 3, 7, 13, 21]
// The only valid triple is (1, 7, 13).
// getMaxTriples(n: 5) == 1
func getMaxTriples(n: Int) -> Int {
var count = 0
for i in 1...n {
for j in i+1...n {
for k in j+1...n {
if (i + j + k) % 3 == 0 {
count += 1
}
}
}
}
return count
}
```
// Fatal error: Range requires lowerBound <= upperBound
func getMaxTriples(n: Int) -> Int {
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
var count = 0
for i in 0..<a.count {
for j in i + 1..<a.count {
for k in j + 1..<a.count {
if a[i] + a[j] + a[k] % 3 == 0 {
count += 1
}
}
}
}
return count
}
```swift
// You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// Explanation:
// a = [1, 3, 7, 13, 21]
// The only valid triple is (1, 7, 13).
// getMaxTriples(n: 5) == 1
func getMaxTriples(n: Int) -> Int {
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
var count = 0
for i in 0..<a.count {
for j in i + 1..<a.count {
for k in j + 1..<a.count {
if a[i] + a[j] + a[k] % 3 == 0 {
count += 1
}
}
}
}
return count
}
```
// XCTAssertTrue failed
func getMaxTriples(n: Int) -> Int {
var count = 0
for i in 1...n {
for j in i+1...n {
for k in j+1...n {
if (i+j+k)%3 == 0 {
count += 1
}
}
}
}
return count
}
```swift
// You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// Explanation:
// a = [1, 3, 7, 13, 21]
// The only valid triple is (1, 7, 13).
// getMaxTriples(n: 5) == 1
func getMaxTriples(n: Int) -> Int {
var count = 0
for i in 1...n {
for j in i+1...n {
for k in j+1...n {
if (i+j+k)%3 == 0 {
count += 1
}
}
}
}
return count
}
```
// Fatal error: Range requires lowerBound <= upperBound
func getMaxTriples(n: Int) -> Int {
var count = 0
for i in 1...n {
for j in i+1...n {
for k in j+1...n {
if i+j+k % 3 == 0 {
count += 1
}
}
}
}
return count
}
```swift
// You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// Explanation:
// a = [1, 3, 7, 13, 21]
// The only valid triple is (1, 7, 13).
// getMaxTriples(n: 5) == 1
func getMaxTriples(n: Int) -> Int {
var count = 0
for i in 1...n {
for j in i+1...n {
for k in j+1...n {
if i+j+k % 3 == 0 {
count += 1
}
}
}
}
return count
}
```
// Fatal error: Range requires lowerBound <= upperBound
func getMaxTriples(n: Int) -> Int {
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
var count = 0
for i in 0..<a.count {
for j in i + 1..<a.count {
for k in j + 1..<a.count {
if a[i] + a[j] + a[k] % 3 == 0 {
count += 1
}
}
}
}
return count
}
```swift
// You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// Explanation:
// a = [1, 3, 7, 13, 21]
// The only valid triple is (1, 7, 13).
// getMaxTriples(n: 5) == 1
func getMaxTriples(n: Int) -> Int {
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
var count = 0
for i in 0..<a.count {
for j in i + 1..<a.count {
for k in j + 1..<a.count {
if a[i] + a[j] + a[k] % 3 == 0 {
count += 1
}
}
}
}
return count
}
```
// XCTAssertTrue failed
func getMaxTriples(n: Int) -> Int {
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
var count = 0
for i in 0..<a.count {
for j in i+1..<a.count {
for k in j+1..<a.count {
if a[i] + a[j] + a[k] % 3 == 0 {
count += 1
}
}
}
}
return count
}
```swift
// You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// Explanation:
// a = [1, 3, 7, 13, 21]
// The only valid triple is (1, 7, 13).
// getMaxTriples(n: 5) == 1
func getMaxTriples(n: Int) -> Int {
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
var count = 0
for i in 0..<a.count {
for j in i+1..<a.count {
for k in j+1..<a.count {
if a[i] + a[j] + a[k] % 3 == 0 {
count += 1
}
}
}
}
return count
}
```
// XCTAssertTrue failed
func sortedListSum(lst: [String]) -> [String] {
var result = [String]()
for i in lst {
if i.count % 2 == 0 {
result.append(i)
}
}
result.sort { $0.count < $1.count }
return result
}
```swift
// Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// sortedListSum(lst: ["aa", "a", "aaa"]) == ["aa"]
// sortedListSum(lst: ["ab", "a", "aaa", "cd"]) == ["ab", "cd"]
func sortedListSum(lst: [String]) -> [String] {
var result = [String]()
for i in lst {
if i.count % 2 == 0 {
result.append(i)
}
}
result.sort { $0.count < $1.count }
return result
}
```
// XCTAssertTrue failed
func sortedListSum(lst: [String]) -> [String] {
var result = [String]()
for i in lst {
if i.count % 2 == 0 {
result.append(i)
}
}
result.sort()
return result
}
```swift
// Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// sortedListSum(lst: ["aa", "a", "aaa"]) == ["aa"]
// sortedListSum(lst: ["ab", "a", "aaa", "cd"]) == ["ab", "cd"]
func sortedListSum(lst: [String]) -> [String] {
var result = [String]()
for i in lst {
if i.count % 2 == 0 {
result.append(i)
}
}
result.sort()
return result
}
```
// XCTAssertTrue failed
func sortedListSum(lst: [String]) -> [String] {
var result = [String]()
for i in lst {
if i.count % 2 == 0 {
result.append(i)
}
}
return result.sorted(by: <)
}
```swift
// Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// sortedListSum(lst: ["aa", "a", "aaa"]) == ["aa"]
// sortedListSum(lst: ["ab", "a", "aaa", "cd"]) == ["ab", "cd"]
func sortedListSum(lst: [String]) -> [String] {
var result = [String]()
for i in lst {
if i.count % 2 == 0 {
result.append(i)
}
}
return result.sorted(by: <)
}
```
// XCTAssertTrue failed
func sortedListSum(lst: [String]) -> [String] {
var result = [String]()
for i in 0..<lst.count {
if lst[i].count % 2 == 0 {
result.append(lst[i])
}
}
result.sort { $0.count < $1.count }
return result
}
```swift
// Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// sortedListSum(lst: ["aa", "a", "aaa"]) == ["aa"]
// sortedListSum(lst: ["ab", "a", "aaa", "cd"]) == ["ab", "cd"]
func sortedListSum(lst: [String]) -> [String] {
var result = [String]()
for i in 0..<lst.count {
if lst[i].count % 2 == 0 {
result.append(lst[i])
}
}
result.sort { $0.count < $1.count }
return result
}
```
// XCTAssertTrue failed
func sortedListSum(lst: [String]) -> [String] {
var result: [String] = []
for item in lst {
if item.count % 2 == 0 {
result.append(item)
}
}
return result.sorted(by: { $0.count < $1.count })
}
```swift
// Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// sortedListSum(lst: ["aa", "a", "aaa"]) == ["aa"]
// sortedListSum(lst: ["ab", "a", "aaa", "cd"]) == ["ab", "cd"]
func sortedListSum(lst: [String]) -> [String] {
var result: [String] = []
for item in lst {
if item.count % 2 == 0 {
result.append(item)
}
}
return result.sorted(by: { $0.count < $1.count })
}
```
// XCTAssertTrue failed
func sortedListSum(lst: [String]) -> [String] {
var result = [String]()
for i in lst {
if i.count % 2 == 0 {
result.append(i)
}
}
result.sort()
return result
}
```swift
// Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// sortedListSum(lst: ["aa", "a", "aaa"]) == ["aa"]
// sortedListSum(lst: ["ab", "a", "aaa", "cd"]) == ["ab", "cd"]
func sortedListSum(lst: [String]) -> [String] {
var result = [String]()
for i in lst {
if i.count % 2 == 0 {
result.append(i)
}
}
result.sort()
return result
}
```
// XCTAssertTrue failed
func sortedListSum(lst: [String]) -> [String] {
var result: [String] = []
for i in lst {
if i.count % 2 == 0 {
result.append(i)
}
}
return result.sorted(by: { $0.count < $1.count })
}
```swift
// Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// sortedListSum(lst: ["aa", "a", "aaa"]) == ["aa"]
// sortedListSum(lst: ["ab", "a", "aaa", "cd"]) == ["ab", "cd"]
func sortedListSum(lst: [String]) -> [String] {
var result: [String] = []
for i in lst {
if i.count % 2 == 0 {
result.append(i)
}
}
return result.sorted(by: { $0.count < $1.count })
}
```
// XCTAssertTrue failed
func sortedListSum(lst: [String]) -> [String] {
var result = [String]()
for item in lst {
if item.count % 2 == 0 {
result.append(item)
}
}
result.sort()
return result
}
```swift
// Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// sortedListSum(lst: ["aa", "a", "aaa"]) == ["aa"]
// sortedListSum(lst: ["ab", "a", "aaa", "cd"]) == ["ab", "cd"]
func sortedListSum(lst: [String]) -> [String] {
var result = [String]()
for item in lst {
if item.count % 2 == 0 {
result.append(item)
}
}
result.sort()
return result
}
```
// XCTAssertTrue failed
func sortedListSum(lst: [String]) -> [String] {
var result: [String] = []
var temp: [String] = []
for i in lst {
if i.count % 2 == 0 {
result.append(i)
} else {
temp.append(i)
}
}
temp.sort()
result.append(contentsOf: temp)
return result
}
```swift
// Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// sortedListSum(lst: ["aa", "a", "aaa"]) == ["aa"]
// sortedListSum(lst: ["ab", "a", "aaa", "cd"]) == ["ab", "cd"]
func sortedListSum(lst: [String]) -> [String] {
var result: [String] = []
var temp: [String] = []
for i in lst {
if i.count % 2 == 0 {
result.append(i)
} else {
temp.append(i)
}
}
temp.sort()
result.append(contentsOf: temp)
return result
}
```
// XCTAssertTrue failed
func sortedListSum(lst: [String]) -> [String] {
var result = [String]()
for word in lst {
if word.count % 2 == 0 {
result.append(word)
}
}
return result.sorted(by: { $0.count < $1.count })
}
```swift
// Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// sortedListSum(lst: ["aa", "a", "aaa"]) == ["aa"]
// sortedListSum(lst: ["ab", "a", "aaa", "cd"]) == ["ab", "cd"]
func sortedListSum(lst: [String]) -> [String] {
var result = [String]()
for word in lst {
if word.count % 2 == 0 {
result.append(word)
}
}
return result.sorted(by: { $0.count < $1.count })
}
```
// XCTAssertTrue failed
func xOrY(n: Int, x: Int, y: Int) -> Int {
if isPrime(n) {
return x
} else {
return y
}
}
```swift
// A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// xOrY(n: 7, x: 34, y: 12) == 34
// xOrY(n: 15, x: 8, y: 5) == 5
func xOrY(n: Int, x: Int, y: Int) -> Int {
if isPrime(n) {
return x
} else {
return y
}
}
```
if isPrime(n) { // cannot find 'isPrime' in scope
func xOrY(n: Int, x: Int, y: Int) -> Int {
return 0
}
```swift
// A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// xOrY(n: 7, x: 34, y: 12) == 34
// xOrY(n: 15, x: 8, y: 5) == 5
func xOrY(n: Int, x: Int, y: Int) -> Int {
return 0
}
```
// XCTAssertTrue failed
func xOrY(n: Int, x: Int, y: Int) -> Int {
if n.isPrime {
return x
}
return y
}
```swift
// A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// xOrY(n: 7, x: 34, y: 12) == 34
// xOrY(n: 15, x: 8, y: 5) == 5
func xOrY(n: Int, x: Int, y: Int) -> Int {
if n.isPrime {
return x
}
return y
}
```
if n.isPrime { // value of type 'Int' has no member 'isPrime'
func xOrY(n: Int, x: Int, y: Int) -> Int {
if isPrime(n) {
return x
} else {
return y
}
}
```swift
// A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// xOrY(n: 7, x: 34, y: 12) == 34
// xOrY(n: 15, x: 8, y: 5) == 5
func xOrY(n: Int, x: Int, y: Int) -> Int {
if isPrime(n) {
return x
} else {
return y
}
}
```
if isPrime(n) { // cannot find 'isPrime' in scope
func xOrY(n: Int, x: Int, y: Int) -> Int {
if isPrime(n: n) {
return x
} else {
return y
}
}
```swift
// A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// xOrY(n: 7, x: 34, y: 12) == 34
// xOrY(n: 15, x: 8, y: 5) == 5
func xOrY(n: Int, x: Int, y: Int) -> Int {
if isPrime(n: n) {
return x
} else {
return y
}
}
```
if isPrime(n: n) { // cannot find 'isPrime' in scope
func xOrY(n: Int, x: Int, y: Int) -> Int {
if n.isPrime {
return x
} else {
return y
}
}
```swift
// A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// xOrY(n: 7, x: 34, y: 12) == 34
// xOrY(n: 15, x: 8, y: 5) == 5
func xOrY(n: Int, x: Int, y: Int) -> Int {
if n.isPrime {
return x
} else {
return y
}
}
```
if n.isPrime { // value of type 'Int' has no member 'isPrime'
func xOrY(n: Int, x: Int, y: Int) -> Int {
if isPrime(n) {
return x
} else {
return y
}
}
```swift
// A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// xOrY(n: 7, x: 34, y: 12) == 34
// xOrY(n: 15, x: 8, y: 5) == 5
func xOrY(n: Int, x: Int, y: Int) -> Int {
if isPrime(n) {
return x
} else {
return y
}
}
```
if isPrime(n) { // cannot find 'isPrime' in scope
func xOrY(n: Int, x: Int, y: Int) -> Int {
return 0
}
```swift
// A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// xOrY(n: 7, x: 34, y: 12) == 34
// xOrY(n: 15, x: 8, y: 5) == 5
func xOrY(n: Int, x: Int, y: Int) -> Int {
return 0
}
```
// XCTAssertTrue failed
func xOrY(n: Int, x: Int, y: Int) -> Int {
return 0
}
```swift
// A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// xOrY(n: 7, x: 34, y: 12) == 34
// xOrY(n: 15, x: 8, y: 5) == 5
func xOrY(n: Int, x: Int, y: Int) -> Int {
return 0
}
```
// XCTAssertTrue failed
func xOrY(n: Int, x: Int, y: Int) -> Int {
return 0
}
```swift
// A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// xOrY(n: 7, x: 34, y: 12) == 34
// xOrY(n: 15, x: 8, y: 5) == 5
func xOrY(n: Int, x: Int, y: Int) -> Int {
return 0
}
```
// XCTAssertTrue failed
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num > 0 && num % 2!= 0 {
sum += Int(num * num)
}
}
return sum
}
```swift
// Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// If the input array is empty, return 0.
// doubleTheDifference(lst: [1, 3, 2, 0]) == 10
// doubleTheDifference(lst: [-1, -2, 0]) == 0
// doubleTheDifference(lst: [9, -2]) == 81
// doubleTheDifference(lst: [0]) == 0
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num > 0 && num % 2!= 0 {
sum += Int(num * num)
}
}
return sum
}
```
if num > 0 && num % 2!= 0 { // cannot force unwrap value of non-optional type 'Double'
if num > 0 && num % 2!= 0 { // '=' must have consistent whitespace on both sides
if num > 0 && num % 2!= 0 { // cannot convert value of type 'Double' to expected argument type 'Bool'
if num > 0 && num % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if num > 0 && num % 2!= 0 { // expression is not assignable: '&&' returns immutable value
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num > 0 && num % 2!= 0 {
sum += Int(num * num)
}
}
return sum
}
```swift
// Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// If the input array is empty, return 0.
// doubleTheDifference(lst: [1, 3, 2, 0]) == 10
// doubleTheDifference(lst: [-1, -2, 0]) == 0
// doubleTheDifference(lst: [9, -2]) == 81
// doubleTheDifference(lst: [0]) == 0
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num > 0 && num % 2!= 0 {
sum += Int(num * num)
}
}
return sum
}
```
if num > 0 && num % 2!= 0 { // cannot force unwrap value of non-optional type 'Double'
if num > 0 && num % 2!= 0 { // '=' must have consistent whitespace on both sides
if num > 0 && num % 2!= 0 { // cannot convert value of type 'Double' to expected argument type 'Bool'
if num > 0 && num % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if num > 0 && num % 2!= 0 { // expression is not assignable: '&&' returns immutable value
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num > 0 && num % 2!= 0 {
sum += Int(num * num)
}
}
return sum
}
```swift
// Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// If the input array is empty, return 0.
// doubleTheDifference(lst: [1, 3, 2, 0]) == 10
// doubleTheDifference(lst: [-1, -2, 0]) == 0
// doubleTheDifference(lst: [9, -2]) == 81
// doubleTheDifference(lst: [0]) == 0
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num > 0 && num % 2!= 0 {
sum += Int(num * num)
}
}
return sum
}
```
if num > 0 && num % 2!= 0 { // cannot force unwrap value of non-optional type 'Double'
if num > 0 && num % 2!= 0 { // '=' must have consistent whitespace on both sides
if num > 0 && num % 2!= 0 { // cannot convert value of type 'Double' to expected argument type 'Bool'
if num > 0 && num % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if num > 0 && num % 2!= 0 { // expression is not assignable: '&&' returns immutable value
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num > 0 && num % 2!= 0 {
sum += Int(num * num)
}
}
return sum
}
```swift
// Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// If the input array is empty, return 0.
// doubleTheDifference(lst: [1, 3, 2, 0]) == 10
// doubleTheDifference(lst: [-1, -2, 0]) == 0
// doubleTheDifference(lst: [9, -2]) == 81
// doubleTheDifference(lst: [0]) == 0
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num > 0 && num % 2!= 0 {
sum += Int(num * num)
}
}
return sum
}
```
if num > 0 && num % 2!= 0 { // cannot force unwrap value of non-optional type 'Double'
if num > 0 && num % 2!= 0 { // '=' must have consistent whitespace on both sides
if num > 0 && num % 2!= 0 { // cannot convert value of type 'Double' to expected argument type 'Bool'
if num > 0 && num % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if num > 0 && num % 2!= 0 { // expression is not assignable: '&&' returns immutable value
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num > 0 && num % 2!= 0 {
sum += Int(num * num)
}
}
return sum
}
```swift
// Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// If the input array is empty, return 0.
// doubleTheDifference(lst: [1, 3, 2, 0]) == 10
// doubleTheDifference(lst: [-1, -2, 0]) == 0
// doubleTheDifference(lst: [9, -2]) == 81
// doubleTheDifference(lst: [0]) == 0
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num > 0 && num % 2!= 0 {
sum += Int(num * num)
}
}
return sum
}
```
if num > 0 && num % 2!= 0 { // cannot force unwrap value of non-optional type 'Double'
if num > 0 && num % 2!= 0 { // '=' must have consistent whitespace on both sides
if num > 0 && num % 2!= 0 { // cannot convert value of type 'Double' to expected argument type 'Bool'
if num > 0 && num % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if num > 0 && num % 2!= 0 { // expression is not assignable: '&&' returns immutable value
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for i in lst {
if i > 0 && i % 2!= 0 {
sum += Int(i * i)
}
}
return sum
}
```swift
// Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// If the input array is empty, return 0.
// doubleTheDifference(lst: [1, 3, 2, 0]) == 10
// doubleTheDifference(lst: [-1, -2, 0]) == 0
// doubleTheDifference(lst: [9, -2]) == 81
// doubleTheDifference(lst: [0]) == 0
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for i in lst {
if i > 0 && i % 2!= 0 {
sum += Int(i * i)
}
}
return sum
}
```
if i > 0 && i % 2!= 0 { // '=' must have consistent whitespace on both sides
if i > 0 && i % 2!= 0 { // cannot force unwrap value of non-optional type 'Double'
if i > 0 && i % 2!= 0 { // expression is not assignable: '&&' returns immutable value
if i > 0 && i % 2!= 0 { // cannot convert value of type 'Double' to expected argument type 'Bool'
if i > 0 && i % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num > 0 && num % 2 == 1 {
sum += Int(num * num)
}
}
return sum
}
```swift
// Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// If the input array is empty, return 0.
// doubleTheDifference(lst: [1, 3, 2, 0]) == 10
// doubleTheDifference(lst: [-1, -2, 0]) == 0
// doubleTheDifference(lst: [9, -2]) == 81
// doubleTheDifference(lst: [0]) == 0
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num > 0 && num % 2 == 1 {
sum += Int(num * num)
}
}
return sum
}
```
if num > 0 && num % 2 == 1 { // '%' is unavailable: For floating point numbers use truncatingRemainder instead
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num > 0 && num % 2!= 0 {
sum += Int(num * num)
}
}
return sum
}
```swift
// Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// If the input array is empty, return 0.
// doubleTheDifference(lst: [1, 3, 2, 0]) == 10
// doubleTheDifference(lst: [-1, -2, 0]) == 0
// doubleTheDifference(lst: [9, -2]) == 81
// doubleTheDifference(lst: [0]) == 0
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num > 0 && num % 2!= 0 {
sum += Int(num * num)
}
}
return sum
}
```
if num > 0 && num % 2!= 0 { // cannot force unwrap value of non-optional type 'Double'
if num > 0 && num % 2!= 0 { // '=' must have consistent whitespace on both sides
if num > 0 && num % 2!= 0 { // cannot convert value of type 'Double' to expected argument type 'Bool'
if num > 0 && num % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if num > 0 && num % 2!= 0 { // expression is not assignable: '&&' returns immutable value
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num > 0 && num % 2!= 0 {
sum += Int(num * num)
}
}
return sum
}
```swift
// Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// If the input array is empty, return 0.
// doubleTheDifference(lst: [1, 3, 2, 0]) == 10
// doubleTheDifference(lst: [-1, -2, 0]) == 0
// doubleTheDifference(lst: [9, -2]) == 81
// doubleTheDifference(lst: [0]) == 0
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num > 0 && num % 2!= 0 {
sum += Int(num * num)
}
}
return sum
}
```
if num > 0 && num % 2!= 0 { // cannot force unwrap value of non-optional type 'Double'
if num > 0 && num % 2!= 0 { // '=' must have consistent whitespace on both sides
if num > 0 && num % 2!= 0 { // cannot convert value of type 'Double' to expected argument type 'Bool'
if num > 0 && num % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if num > 0 && num % 2!= 0 { // expression is not assignable: '&&' returns immutable value
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num > 0 && num % 2!= 0 {
sum += Int(num * num)
}
}
return sum
}
```swift
// Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// If the input array is empty, return 0.
// doubleTheDifference(lst: [1, 3, 2, 0]) == 10
// doubleTheDifference(lst: [-1, -2, 0]) == 0
// doubleTheDifference(lst: [9, -2]) == 81
// doubleTheDifference(lst: [0]) == 0
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num > 0 && num % 2!= 0 {
sum += Int(num * num)
}
}
return sum
}
```
if num > 0 && num % 2!= 0 { // cannot force unwrap value of non-optional type 'Double'
if num > 0 && num % 2!= 0 { // '=' must have consistent whitespace on both sides
if num > 0 && num % 2!= 0 { // cannot convert value of type 'Double' to expected argument type 'Bool'
if num > 0 && num % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if num > 0 && num % 2!= 0 { // expression is not assignable: '&&' returns immutable value
func compare(game: [Int], guess: [Int]) -> [Int] {
var result = [Int]()
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```swift
// I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you have at that moment are
// definitely worth noting down and comparing.
// Your task is to determine if a person correctly guessed the results of a number of matches.
// You are given two arrays of scores and guesses of equal length, where each index shows a match.
// Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
// the value is 0, and if not, the value is the absolute difference between the guess and the score.
// example:
// compare(game: [1, 2, 3, 4, 5, 1], guess: [1, 2, 3, 4, 2, -2]) == [0, 0, 0, 0, 3, 3]
// compare(game: [0, 5, 0, 0, 0, 4], guess: [4, 1, 1, 0, 0, -2]) == [4, 4, 1, 0, 0, 6]
func compare(game: [Int], guess: [Int]) -> [Int] {
var result = [Int]()
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```
func compare(game: [Int], guess: [Int]) -> [Int] {
var result: [Int] = []
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```swift
// I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you have at that moment are
// definitely worth noting down and comparing.
// Your task is to determine if a person correctly guessed the results of a number of matches.
// You are given two arrays of scores and guesses of equal length, where each index shows a match.
// Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
// the value is 0, and if not, the value is the absolute difference between the guess and the score.
// example:
// compare(game: [1, 2, 3, 4, 5, 1], guess: [1, 2, 3, 4, 2, -2]) == [0, 0, 0, 0, 3, 3]
// compare(game: [0, 5, 0, 0, 0, 4], guess: [4, 1, 1, 0, 0, -2]) == [4, 4, 1, 0, 0, 6]
func compare(game: [Int], guess: [Int]) -> [Int] {
var result: [Int] = []
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```
func compare(game: [Int], guess: [Int]) -> [Int] {
var result = [Int]()
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```swift
// I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you have at that moment are
// definitely worth noting down and comparing.
// Your task is to determine if a person correctly guessed the results of a number of matches.
// You are given two arrays of scores and guesses of equal length, where each index shows a match.
// Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
// the value is 0, and if not, the value is the absolute difference between the guess and the score.
// example:
// compare(game: [1, 2, 3, 4, 5, 1], guess: [1, 2, 3, 4, 2, -2]) == [0, 0, 0, 0, 3, 3]
// compare(game: [0, 5, 0, 0, 0, 4], guess: [4, 1, 1, 0, 0, -2]) == [4, 4, 1, 0, 0, 6]
func compare(game: [Int], guess: [Int]) -> [Int] {
var result = [Int]()
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```
func compare(game: [Int], guess: [Int]) -> [Int] {
var result = [Int]()
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```swift
// I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you have at that moment are
// definitely worth noting down and comparing.
// Your task is to determine if a person correctly guessed the results of a number of matches.
// You are given two arrays of scores and guesses of equal length, where each index shows a match.
// Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
// the value is 0, and if not, the value is the absolute difference between the guess and the score.
// example:
// compare(game: [1, 2, 3, 4, 5, 1], guess: [1, 2, 3, 4, 2, -2]) == [0, 0, 0, 0, 3, 3]
// compare(game: [0, 5, 0, 0, 0, 4], guess: [4, 1, 1, 0, 0, -2]) == [4, 4, 1, 0, 0, 6]
func compare(game: [Int], guess: [Int]) -> [Int] {
var result = [Int]()
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```
func compare(game: [Int], guess: [Int]) -> [Int] {
var result = [Int]()
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```swift
// I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you have at that moment are
// definitely worth noting down and comparing.
// Your task is to determine if a person correctly guessed the results of a number of matches.
// You are given two arrays of scores and guesses of equal length, where each index shows a match.
// Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
// the value is 0, and if not, the value is the absolute difference between the guess and the score.
// example:
// compare(game: [1, 2, 3, 4, 5, 1], guess: [1, 2, 3, 4, 2, -2]) == [0, 0, 0, 0, 3, 3]
// compare(game: [0, 5, 0, 0, 0, 4], guess: [4, 1, 1, 0, 0, -2]) == [4, 4, 1, 0, 0, 6]
func compare(game: [Int], guess: [Int]) -> [Int] {
var result = [Int]()
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```
func compare(game: [Int], guess: [Int]) -> [Int] {
var result: [Int] = []
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```swift
// I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you have at that moment are
// definitely worth noting down and comparing.
// Your task is to determine if a person correctly guessed the results of a number of matches.
// You are given two arrays of scores and guesses of equal length, where each index shows a match.
// Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
// the value is 0, and if not, the value is the absolute difference between the guess and the score.
// example:
// compare(game: [1, 2, 3, 4, 5, 1], guess: [1, 2, 3, 4, 2, -2]) == [0, 0, 0, 0, 3, 3]
// compare(game: [0, 5, 0, 0, 0, 4], guess: [4, 1, 1, 0, 0, -2]) == [4, 4, 1, 0, 0, 6]
func compare(game: [Int], guess: [Int]) -> [Int] {
var result: [Int] = []
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```
func compare(game: [Int], guess: [Int]) -> [Int] {
var result: [Int] = []
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```swift
// I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you have at that moment are
// definitely worth noting down and comparing.
// Your task is to determine if a person correctly guessed the results of a number of matches.
// You are given two arrays of scores and guesses of equal length, where each index shows a match.
// Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
// the value is 0, and if not, the value is the absolute difference between the guess and the score.
// example:
// compare(game: [1, 2, 3, 4, 5, 1], guess: [1, 2, 3, 4, 2, -2]) == [0, 0, 0, 0, 3, 3]
// compare(game: [0, 5, 0, 0, 0, 4], guess: [4, 1, 1, 0, 0, -2]) == [4, 4, 1, 0, 0, 6]
func compare(game: [Int], guess: [Int]) -> [Int] {
var result: [Int] = []
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```
func compare(game: [Int], guess: [Int]) -> [Int] {
var result: [Int] = []
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```swift
// I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you have at that moment are
// definitely worth noting down and comparing.
// Your task is to determine if a person correctly guessed the results of a number of matches.
// You are given two arrays of scores and guesses of equal length, where each index shows a match.
// Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
// the value is 0, and if not, the value is the absolute difference between the guess and the score.
// example:
// compare(game: [1, 2, 3, 4, 5, 1], guess: [1, 2, 3, 4, 2, -2]) == [0, 0, 0, 0, 3, 3]
// compare(game: [0, 5, 0, 0, 0, 4], guess: [4, 1, 1, 0, 0, -2]) == [4, 4, 1, 0, 0, 6]
func compare(game: [Int], guess: [Int]) -> [Int] {
var result: [Int] = []
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```
func compare(game: [Int], guess: [Int]) -> [Int] {
var result = [Int]()
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```swift
// I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you have at that moment are
// definitely worth noting down and comparing.
// Your task is to determine if a person correctly guessed the results of a number of matches.
// You are given two arrays of scores and guesses of equal length, where each index shows a match.
// Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
// the value is 0, and if not, the value is the absolute difference between the guess and the score.
// example:
// compare(game: [1, 2, 3, 4, 5, 1], guess: [1, 2, 3, 4, 2, -2]) == [0, 0, 0, 0, 3, 3]
// compare(game: [0, 5, 0, 0, 0, 4], guess: [4, 1, 1, 0, 0, -2]) == [4, 4, 1, 0, 0, 6]
func compare(game: [Int], guess: [Int]) -> [Int] {
var result = [Int]()
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```
func compare(game: [Int], guess: [Int]) -> [Int] {
var result = [Int]()
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```swift
// I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you have at that moment are
// definitely worth noting down and comparing.
// Your task is to determine if a person correctly guessed the results of a number of matches.
// You are given two arrays of scores and guesses of equal length, where each index shows a match.
// Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
// the value is 0, and if not, the value is the absolute difference between the guess and the score.
// example:
// compare(game: [1, 2, 3, 4, 5, 1], guess: [1, 2, 3, 4, 2, -2]) == [0, 0, 0, 0, 3, 3]
// compare(game: [0, 5, 0, 0, 0, 4], guess: [4, 1, 1, 0, 0, -2]) == [4, 4, 1, 0, 0, 6]
func compare(game: [Int], guess: [Int]) -> [Int] {
var result = [Int]()
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```
func Strongest_Extension(className: String, extensions: [String]) -> String {
// your code here
}
```swift
// You will be given the name of a class (a string) and an array of extensions.
// The extensions are to be used to load additional classes to the class. The
// strength of the extension is as follows: Let CAP be the number of the uppercase
// letters in the extension's name, and let SM be the number of lowercase letters
// in the extension's name, the strength is given by the fraction CAP - SM.
// You should find the strongest extension and return a string in this
// format: ClassName.StrongestExtensionName.
// If there are two or more extensions with the same strength, you should
// choose the one that comes first in the array.
// For example, if you are given "Slices" as the class and an array of the
// extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
// return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
// (its strength is -1).
// Example:
// Strongest_Extension(className: "myClass", extensions: ["AA", "Be", "CC"]) == "my_class.AA"
func Strongest_Extension(className: String, extensions: [String]) -> String {
// your code here
}
```
} // missing return in global function expected to return 'String'
func Strongest_Extension(className: String, extensions: [String]) -> String {
// your code here
return ""
}
```swift
// You will be given the name of a class (a string) and an array of extensions.
// The extensions are to be used to load additional classes to the class. The
// strength of the extension is as follows: Let CAP be the number of the uppercase
// letters in the extension's name, and let SM be the number of lowercase letters
// in the extension's name, the strength is given by the fraction CAP - SM.
// You should find the strongest extension and return a string in this
// format: ClassName.StrongestExtensionName.
// If there are two or more extensions with the same strength, you should
// choose the one that comes first in the array.
// For example, if you are given "Slices" as the class and an array of the
// extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
// return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
// (its strength is -1).
// Example:
// Strongest_Extension(className: "myClass", extensions: ["AA", "Be", "CC"]) == "my_class.AA"
func Strongest_Extension(className: String, extensions: [String]) -> String {
// your code here
return ""
}
```
// XCTAssertTrue failed
func Strongest_Extension(className: String, extensions: [String]) -> String {
return ""
}
```swift
// You will be given the name of a class (a string) and an array of extensions.
// The extensions are to be used to load additional classes to the class. The
// strength of the extension is as follows: Let CAP be the number of the uppercase
// letters in the extension's name, and let SM be the number of lowercase letters
// in the extension's name, the strength is given by the fraction CAP - SM.
// You should find the strongest extension and return a string in this
// format: ClassName.StrongestExtensionName.
// If there are two or more extensions with the same strength, you should
// choose the one that comes first in the array.
// For example, if you are given "Slices" as the class and an array of the
// extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
// return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
// (its strength is -1).
// Example:
// Strongest_Extension(className: "myClass", extensions: ["AA", "Be", "CC"]) == "my_class.AA"
func Strongest_Extension(className: String, extensions: [String]) -> String {
return ""
}
```
// XCTAssertTrue failed
func Strongest_Extension(className: String, extensions: [String]) -> String {
return ""
}
```swift
// You will be given the name of a class (a string) and an array of extensions.
// The extensions are to be used to load additional classes to the class. The
// strength of the extension is as follows: Let CAP be the number of the uppercase
// letters in the extension's name, and let SM be the number of lowercase letters
// in the extension's name, the strength is given by the fraction CAP - SM.
// You should find the strongest extension and return a string in this
// format: ClassName.StrongestExtensionName.
// If there are two or more extensions with the same strength, you should
// choose the one that comes first in the array.
// For example, if you are given "Slices" as the class and an array of the
// extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
// return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
// (its strength is -1).
// Example:
// Strongest_Extension(className: "myClass", extensions: ["AA", "Be", "CC"]) == "my_class.AA"
func Strongest_Extension(className: String, extensions: [String]) -> String {
return ""
}
```
// XCTAssertTrue failed
func Strongest_Extension(className: String, extensions: [String]) -> String {
// your code here
}
```swift
// You will be given the name of a class (a string) and an array of extensions.
// The extensions are to be used to load additional classes to the class. The
// strength of the extension is as follows: Let CAP be the number of the uppercase
// letters in the extension's name, and let SM be the number of lowercase letters
// in the extension's name, the strength is given by the fraction CAP - SM.
// You should find the strongest extension and return a string in this
// format: ClassName.StrongestExtensionName.
// If there are two or more extensions with the same strength, you should
// choose the one that comes first in the array.
// For example, if you are given "Slices" as the class and an array of the
// extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
// return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
// (its strength is -1).
// Example:
// Strongest_Extension(className: "myClass", extensions: ["AA", "Be", "CC"]) == "my_class.AA"
func Strongest_Extension(className: String, extensions: [String]) -> String {
// your code here
}
```
} // missing return in global function expected to return 'String'
func Strongest_Extension(className: String, extensions: [String]) -> String {
return ""
}
```swift
// You will be given the name of a class (a string) and an array of extensions.
// The extensions are to be used to load additional classes to the class. The
// strength of the extension is as follows: Let CAP be the number of the uppercase
// letters in the extension's name, and let SM be the number of lowercase letters
// in the extension's name, the strength is given by the fraction CAP - SM.
// You should find the strongest extension and return a string in this
// format: ClassName.StrongestExtensionName.
// If there are two or more extensions with the same strength, you should
// choose the one that comes first in the array.
// For example, if you are given "Slices" as the class and an array of the
// extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
// return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
// (its strength is -1).
// Example:
// Strongest_Extension(className: "myClass", extensions: ["AA", "Be", "CC"]) == "my_class.AA"
func Strongest_Extension(className: String, extensions: [String]) -> String {
return ""
}
```
// XCTAssertTrue failed
func Strongest_Extension(className: String, extensions: [String]) -> String {
var strongest = ""
var strongestStrength = 0.0
for ext in extensions {
let strength = Double(ext.uppercased().filter { $0 >= "A" && $0 <= "Z" }.count) - Double(ext.lowercased().filter { $0 >= "a" && $0 <= "z" }.count)
if strength > strongestStrength {
strongest = ext
strongestStrength = strength
}
}
return className + "." + strongest
}
```swift
// You will be given the name of a class (a string) and an array of extensions.
// The extensions are to be used to load additional classes to the class. The
// strength of the extension is as follows: Let CAP be the number of the uppercase
// letters in the extension's name, and let SM be the number of lowercase letters
// in the extension's name, the strength is given by the fraction CAP - SM.
// You should find the strongest extension and return a string in this
// format: ClassName.StrongestExtensionName.
// If there are two or more extensions with the same strength, you should
// choose the one that comes first in the array.
// For example, if you are given "Slices" as the class and an array of the
// extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
// return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
// (its strength is -1).
// Example:
// Strongest_Extension(className: "myClass", extensions: ["AA", "Be", "CC"]) == "my_class.AA"
func Strongest_Extension(className: String, extensions: [String]) -> String {
var strongest = ""
var strongestStrength = 0.0
for ext in extensions {
let strength = Double(ext.uppercased().filter { $0 >= "A" && $0 <= "Z" }.count) - Double(ext.lowercased().filter { $0 >= "a" && $0 <= "z" }.count)
if strength > strongestStrength {
strongest = ext
strongestStrength = strength
}
}
return className + "." + strongest
}
```
// XCTAssertTrue failed
func Strongest_Extension(className: String, extensions: [String]) -> String {
var strongest = ""
var strongestStrength = 0.0
for extension in extensions {
let strength = calculateStrength(extension)
if strength > strongestStrength {
strongest = extension
strongestStrength = strength
}
}
return "\(className).\(strongest)"
}
func calculateStrength(_ extension: String) -> Double {
let upperCase = extension.uppercased().filter { $0.isUppercase }
let lowerCase = extension.lowercased().filter { $0.isLowercase }
let strength = Double(upperCase.count) - Double(lowerCase.count)
return strength
}
```swift
// You will be given the name of a class (a string) and an array of extensions.
// The extensions are to be used to load additional classes to the class. The
// strength of the extension is as follows: Let CAP be the number of the uppercase
// letters in the extension's name, and let SM be the number of lowercase letters
// in the extension's name, the strength is given by the fraction CAP - SM.
// You should find the strongest extension and return a string in this
// format: ClassName.StrongestExtensionName.
// If there are two or more extensions with the same strength, you should
// choose the one that comes first in the array.
// For example, if you are given "Slices" as the class and an array of the
// extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
// return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
// (its strength is -1).
// Example:
// Strongest_Extension(className: "myClass", extensions: ["AA", "Be", "CC"]) == "my_class.AA"
func Strongest_Extension(className: String, extensions: [String]) -> String {
var strongest = ""
var strongestStrength = 0.0
for extension in extensions {
let strength = calculateStrength(extension)
if strength > strongestStrength {
strongest = extension
strongestStrength = strength
}
}
return "\(className).\(strongest)"
}
func calculateStrength(_ extension: String) -> Double {
let upperCase = extension.uppercased().filter { $0.isUppercase }
let lowerCase = extension.lowercased().filter { $0.isLowercase }
let strength = Double(upperCase.count) - Double(lowerCase.count)
return strength
}
```
for extension in extensions { // expected '{' to start the body of for-each loop
for extension in extensions { // expected Sequence expression for for-each loop
for extension in extensions { // expected pattern
let strength = calculateStrength(extension) // expected expression in list of expressions
let strength = calculateStrength(extension) // declaration is only valid at file scope
let strength = calculateStrength(extension) // consecutive statements on a line must be separated by ';'
let strength = calculateStrength(extension) // expected type name in extension declaration
let strength = calculateStrength(extension) // missing argument for parameter #1 in call
let strength = calculateStrength(extension) // expected '{' in extension
strongest = extension // expected expression in assignment
strongest = extension // declaration is only valid at file scope
strongestStrength = strength // cannot find type 'strongestStrength' in scope
strongestStrength = strength // expected '{' in extension
let upperCase = extension.uppercased().filter { $0.isUppercase } // expected '{' in extension
let upperCase = extension.uppercased().filter { $0.isUppercase } // expected type name in extension declaration
let upperCase = extension.uppercased().filter { $0.isUppercase } // declaration is only valid at file scope
let upperCase = extension.uppercased().filter { $0.isUppercase } // consecutive statements on a line must be separated by ';'
let upperCase = extension.uppercased().filter { $0.isUppercase } // expected initial value after '='
let lowerCase = extension.lowercased().filter { $0.isLowercase } // expected initial value after '='
let lowerCase = extension.lowercased().filter { $0.isLowercase } // expected '{' in extension
let lowerCase = extension.lowercased().filter { $0.isLowercase } // expected type name in extension declaration
let lowerCase = extension.lowercased().filter { $0.isLowercase } // declaration is only valid at file scope
let lowerCase = extension.lowercased().filter { $0.isLowercase } // consecutive statements on a line must be separated by ';'
func Strongest_Extension(className: String, extensions: [String]) -> String {
// Your code here
return ""
}
```swift
// You will be given the name of a class (a string) and an array of extensions.
// The extensions are to be used to load additional classes to the class. The
// strength of the extension is as follows: Let CAP be the number of the uppercase
// letters in the extension's name, and let SM be the number of lowercase letters
// in the extension's name, the strength is given by the fraction CAP - SM.
// You should find the strongest extension and return a string in this
// format: ClassName.StrongestExtensionName.
// If there are two or more extensions with the same strength, you should
// choose the one that comes first in the array.
// For example, if you are given "Slices" as the class and an array of the
// extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
// return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
// (its strength is -1).
// Example:
// Strongest_Extension(className: "myClass", extensions: ["AA", "Be", "CC"]) == "my_class.AA"
func Strongest_Extension(className: String, extensions: [String]) -> String {
// Your code here
return ""
}
```
// XCTAssertTrue failed
func Strongest_Extension(className: String, extensions: [String]) -> String {
var strongest = ""
var strongestStrength = 0.0
for ext in extensions {
let strength = ext.strength()
if strength > strongestStrength {
strongest = ext
strongestStrength = strength
}
}
return "\(className).\(strongest)"
}
extension String {
func strength() -> Double {
let upper = self.filter { $0.isUppercase }
let lower = self.filter { $0.isLowercase }
return Double(upper.count - lower.count)
}
}
```swift
// You will be given the name of a class (a string) and an array of extensions.
// The extensions are to be used to load additional classes to the class. The
// strength of the extension is as follows: Let CAP be the number of the uppercase
// letters in the extension's name, and let SM be the number of lowercase letters
// in the extension's name, the strength is given by the fraction CAP - SM.
// You should find the strongest extension and return a string in this
// format: ClassName.StrongestExtensionName.
// If there are two or more extensions with the same strength, you should
// choose the one that comes first in the array.
// For example, if you are given "Slices" as the class and an array of the
// extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
// return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
// (its strength is -1).
// Example:
// Strongest_Extension(className: "myClass", extensions: ["AA", "Be", "CC"]) == "my_class.AA"
func Strongest_Extension(className: String, extensions: [String]) -> String {
var strongest = ""
var strongestStrength = 0.0
for ext in extensions {
let strength = ext.strength()
if strength > strongestStrength {
strongest = ext
strongestStrength = strength
}
}
return "\(className).\(strongest)"
}
extension String {
func strength() -> Double {
let upper = self.filter { $0.isUppercase }
let lower = self.filter { $0.isLowercase }
return Double(upper.count - lower.count)
}
}
```
// XCTAssertTrue failed
func cycpatternCheck(a: String, b: String) -> Bool {
// your code here
}
```swift
// You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// cycpatternCheck(a: "abcd", b: "abd") == false
// cycpatternCheck(a: "hello", b: "ell") == true
// cycpatternCheck(a: "whassup", b: "psus") == false
// cycpatternCheck(a: "abab", b: "baa") == true
// cycpatternCheck(a: "efef", b: "eeff") == false
// cycpatternCheck(a: "himenss", b: "simen") == true
func cycpatternCheck(a: String, b: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func cycpatternCheck(a: String, b: String) -> Bool {
return false
}
```swift
// You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// cycpatternCheck(a: "abcd", b: "abd") == false
// cycpatternCheck(a: "hello", b: "ell") == true
// cycpatternCheck(a: "whassup", b: "psus") == false
// cycpatternCheck(a: "abab", b: "baa") == true
// cycpatternCheck(a: "efef", b: "eeff") == false
// cycpatternCheck(a: "himenss", b: "simen") == true
func cycpatternCheck(a: String, b: String) -> Bool {
return false
}
```
// XCTAssertTrue failed
func cycpatternCheck(a: String, b: String) -> Bool {
let b = b.reversed()
return a.contains(b)
}
```swift
// You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// cycpatternCheck(a: "abcd", b: "abd") == false
// cycpatternCheck(a: "hello", b: "ell") == true
// cycpatternCheck(a: "whassup", b: "psus") == false
// cycpatternCheck(a: "abab", b: "baa") == true
// cycpatternCheck(a: "efef", b: "eeff") == false
// cycpatternCheck(a: "himenss", b: "simen") == true
func cycpatternCheck(a: String, b: String) -> Bool {
let b = b.reversed()
return a.contains(b)
}
```
// XCTAssertTrue failed
func cycpatternCheck(a: String, b: String) -> Bool {
let a = Array(a)
let b = Array(b)
var b = b
for _ in 0..<a.count {
if b == a {
return true
}
b.append(b.removeFirst())
}
return false
}
```swift
// You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// cycpatternCheck(a: "abcd", b: "abd") == false
// cycpatternCheck(a: "hello", b: "ell") == true
// cycpatternCheck(a: "whassup", b: "psus") == false
// cycpatternCheck(a: "abab", b: "baa") == true
// cycpatternCheck(a: "efef", b: "eeff") == false
// cycpatternCheck(a: "himenss", b: "simen") == true
func cycpatternCheck(a: String, b: String) -> Bool {
let a = Array(a)
let b = Array(b)
var b = b
for _ in 0..<a.count {
if b == a {
return true
}
b.append(b.removeFirst())
}
return false
}
```
var b = b // invalid redeclaration of 'b'
func cycpatternCheck(a: String, b: String) -> Bool {
// your code here
}
```swift
// You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// cycpatternCheck(a: "abcd", b: "abd") == false
// cycpatternCheck(a: "hello", b: "ell") == true
// cycpatternCheck(a: "whassup", b: "psus") == false
// cycpatternCheck(a: "abab", b: "baa") == true
// cycpatternCheck(a: "efef", b: "eeff") == false
// cycpatternCheck(a: "himenss", b: "simen") == true
func cycpatternCheck(a: String, b: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func cycpatternCheck(a: String, b: String) -> Bool {
let b = b.count == 1? b + b : b
return a.contains(b)
}
```swift
// You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// cycpatternCheck(a: "abcd", b: "abd") == false
// cycpatternCheck(a: "hello", b: "ell") == true
// cycpatternCheck(a: "whassup", b: "psus") == false
// cycpatternCheck(a: "abab", b: "baa") == true
// cycpatternCheck(a: "efef", b: "eeff") == false
// cycpatternCheck(a: "himenss", b: "simen") == true
func cycpatternCheck(a: String, b: String) -> Bool {
let b = b.count == 1? b + b : b
return a.contains(b)
}
```
let b = b.count == 1? b + b : b // consecutive statements on a line must be separated by ';'
let b = b.count == 1? b + b : b // consecutive statements on a line must be separated by ';'
let b = b.count == 1? b + b : b // expected expression
let b = b.count == 1? b + b : b // cannot use optional chaining on non-optional value of type 'Int'
func cycpatternCheck(a: String, b: String) -> Bool {
let a = Array(a)
let b = Array(b)
for i in 0..<a.count {
var j = 0
var k = i
while j < b.count {
if a[k]!= b[j] {
break
}
j += 1
k += 1
if k == a.count {
k = 0
}
}
if j == b.count {
return true
}
}
return false
}
```swift
// You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// cycpatternCheck(a: "abcd", b: "abd") == false
// cycpatternCheck(a: "hello", b: "ell") == true
// cycpatternCheck(a: "whassup", b: "psus") == false
// cycpatternCheck(a: "abab", b: "baa") == true
// cycpatternCheck(a: "efef", b: "eeff") == false
// cycpatternCheck(a: "himenss", b: "simen") == true
func cycpatternCheck(a: String, b: String) -> Bool {
let a = Array(a)
let b = Array(b)
for i in 0..<a.count {
var j = 0
var k = i
while j < b.count {
if a[k]!= b[j] {
break
}
j += 1
k += 1
if k == a.count {
k = 0
}
}
if j == b.count {
return true
}
}
return false
}
```
if a[k]!= b[j] { // '=' must have consistent whitespace on both sides
if a[k]!= b[j] { // cannot force unwrap value of non-optional type 'String.Element' (aka 'Character')
if a[k]!= b[j] { // use of '=' in a boolean context, did you mean '=='?
func cycpatternCheck(a: String, b: String) -> Bool {
return false
}
```swift
// You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// cycpatternCheck(a: "abcd", b: "abd") == false
// cycpatternCheck(a: "hello", b: "ell") == true
// cycpatternCheck(a: "whassup", b: "psus") == false
// cycpatternCheck(a: "abab", b: "baa") == true
// cycpatternCheck(a: "efef", b: "eeff") == false
// cycpatternCheck(a: "himenss", b: "simen") == true
func cycpatternCheck(a: String, b: String) -> Bool {
return false
}
```
// XCTAssertTrue failed
func cycpatternCheck(a: String, b: String) -> Bool {
return false
}
```swift
// You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// cycpatternCheck(a: "abcd", b: "abd") == false
// cycpatternCheck(a: "hello", b: "ell") == true
// cycpatternCheck(a: "whassup", b: "psus") == false
// cycpatternCheck(a: "abab", b: "baa") == true
// cycpatternCheck(a: "efef", b: "eeff") == false
// cycpatternCheck(a: "himenss", b: "simen") == true
func cycpatternCheck(a: String, b: String) -> Bool {
return false
}
```
// XCTAssertTrue failed
func cycpatternCheck(a: String, b: String) -> Bool {
return false
}
```swift
// You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// cycpatternCheck(a: "abcd", b: "abd") == false
// cycpatternCheck(a: "hello", b: "ell") == true
// cycpatternCheck(a: "whassup", b: "psus") == false
// cycpatternCheck(a: "abab", b: "baa") == true
// cycpatternCheck(a: "efef", b: "eeff") == false
// cycpatternCheck(a: "himenss", b: "simen") == true
func cycpatternCheck(a: String, b: String) -> Bool {
return false
}
```
// XCTAssertTrue failed
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = num
while num!= 0 {
let digit = num % 10
if digit % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```swift
// Given an integer. return a tuple that has the number of even and odd digits respectively.
// Example:
// evenOddCount(num: -12) == (1, 1)
// evenOddCount(num: 123) == (1, 2)
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = num
while num!= 0 {
let digit = num % 10
if digit % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```
while num!= 0 { // '=' must have consistent whitespace on both sides
while num!= 0 { // cannot force unwrap value of non-optional type 'Int'
while num!= 0 { // use of '=' in a boolean context, did you mean '=='?
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = num
while num!= 0 {
let digit = num % 10
if digit % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```swift
// Given an integer. return a tuple that has the number of even and odd digits respectively.
// Example:
// evenOddCount(num: -12) == (1, 1)
// evenOddCount(num: 123) == (1, 2)
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = num
while num!= 0 {
let digit = num % 10
if digit % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```
while num!= 0 { // '=' must have consistent whitespace on both sides
while num!= 0 { // cannot force unwrap value of non-optional type 'Int'
while num!= 0 { // use of '=' in a boolean context, did you mean '=='?
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = num
while num!= 0 {
let remainder = num % 10
if remainder % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```swift
// Given an integer. return a tuple that has the number of even and odd digits respectively.
// Example:
// evenOddCount(num: -12) == (1, 1)
// evenOddCount(num: 123) == (1, 2)
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = num
while num!= 0 {
let remainder = num % 10
if remainder % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```
while num!= 0 { // '=' must have consistent whitespace on both sides
while num!= 0 { // cannot force unwrap value of non-optional type 'Int'
while num!= 0 { // use of '=' in a boolean context, did you mean '=='?
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = num
while num!= 0 {
let digit = num % 10
if digit % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```swift
// Given an integer. return a tuple that has the number of even and odd digits respectively.
// Example:
// evenOddCount(num: -12) == (1, 1)
// evenOddCount(num: 123) == (1, 2)
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = num
while num!= 0 {
let digit = num % 10
if digit % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```
while num!= 0 { // '=' must have consistent whitespace on both sides
while num!= 0 { // cannot force unwrap value of non-optional type 'Int'
while num!= 0 { // use of '=' in a boolean context, did you mean '=='?
func evenOddCount(num: Int) -> (Int, Int) {
var even = 0
var odd = 0
var num = num
while num!= 0 {
let digit = num % 10
if digit % 2 == 0 {
even += 1
} else {
odd += 1
}
num /= 10
}
return (even, odd)
}
```swift
// Given an integer. return a tuple that has the number of even and odd digits respectively.
// Example:
// evenOddCount(num: -12) == (1, 1)
// evenOddCount(num: 123) == (1, 2)
func evenOddCount(num: Int) -> (Int, Int) {
var even = 0
var odd = 0
var num = num
while num!= 0 {
let digit = num % 10
if digit % 2 == 0 {
even += 1
} else {
odd += 1
}
num /= 10
}
return (even, odd)
}
```
while num!= 0 { // '=' must have consistent whitespace on both sides
while num!= 0 { // cannot force unwrap value of non-optional type 'Int'
while num!= 0 { // use of '=' in a boolean context, did you mean '=='?
func evenOddCount(num: Int) -> (Int, Int) {
var even = 0
var odd = 0
var num = num
while num!= 0 {
let digit = num % 10
if digit % 2 == 0 {
even += 1
} else {
odd += 1
}
num /= 10
}
return (even, odd)
}
```swift
// Given an integer. return a tuple that has the number of even and odd digits respectively.
// Example:
// evenOddCount(num: -12) == (1, 1)
// evenOddCount(num: 123) == (1, 2)
func evenOddCount(num: Int) -> (Int, Int) {
var even = 0
var odd = 0
var num = num
while num!= 0 {
let digit = num % 10
if digit % 2 == 0 {
even += 1
} else {
odd += 1
}
num /= 10
}
return (even, odd)
}
```
while num!= 0 { // '=' must have consistent whitespace on both sides
while num!= 0 { // cannot force unwrap value of non-optional type 'Int'
while num!= 0 { // use of '=' in a boolean context, did you mean '=='?
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = num
while num!= 0 {
let digit = num % 10
if digit % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```swift
// Given an integer. return a tuple that has the number of even and odd digits respectively.
// Example:
// evenOddCount(num: -12) == (1, 1)
// evenOddCount(num: 123) == (1, 2)
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = num
while num!= 0 {
let digit = num % 10
if digit % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```
while num!= 0 { // '=' must have consistent whitespace on both sides
while num!= 0 { // cannot force unwrap value of non-optional type 'Int'
while num!= 0 { // use of '=' in a boolean context, did you mean '=='?
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = num
while num!= 0 {
let digit = num % 10
if digit % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```swift
// Given an integer. return a tuple that has the number of even and odd digits respectively.
// Example:
// evenOddCount(num: -12) == (1, 1)
// evenOddCount(num: 123) == (1, 2)
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = num
while num!= 0 {
let digit = num % 10
if digit % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```
while num!= 0 { // '=' must have consistent whitespace on both sides
while num!= 0 { // cannot force unwrap value of non-optional type 'Int'
while num!= 0 { // use of '=' in a boolean context, did you mean '=='?
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = num
while num!= 0 {
let remainder = num % 10
if remainder % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```swift
// Given an integer. return a tuple that has the number of even and odd digits respectively.
// Example:
// evenOddCount(num: -12) == (1, 1)
// evenOddCount(num: 123) == (1, 2)
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = num
while num!= 0 {
let remainder = num % 10
if remainder % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```
while num!= 0 { // '=' must have consistent whitespace on both sides
while num!= 0 { // cannot force unwrap value of non-optional type 'Int'
while num!= 0 { // use of '=' in a boolean context, did you mean '=='?
func evenOddCount(num: Int) -> (Int, Int) {
var even = 0
var odd = 0
var num = num
while num!= 0 {
let digit = num % 10
if digit % 2 == 0 {
even += 1
} else {
odd += 1
}
num /= 10
}
return (even, odd)
}
```swift
// Given an integer. return a tuple that has the number of even and odd digits respectively.
// Example:
// evenOddCount(num: -12) == (1, 1)
// evenOddCount(num: 123) == (1, 2)
func evenOddCount(num: Int) -> (Int, Int) {
var even = 0
var odd = 0
var num = num
while num!= 0 {
let digit = num % 10
if digit % 2 == 0 {
even += 1
} else {
odd += 1
}
num /= 10
}
return (even, odd)
}
```
while num!= 0 { // '=' must have consistent whitespace on both sides
while num!= 0 { // cannot force unwrap value of non-optional type 'Int'
while num!= 0 { // use of '=' in a boolean context, did you mean '=='?
func intToMiniRoman(number: Int) -> String {
// Your code here
}
```swift
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// intToMiniRoman(number: 19) == "xix"
// intToMiniRoman(number: 152) == "clii"
// intToMiniRoman(number: 426) == "cdxxvi"
func intToMiniRoman(number: Int) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func intToMiniRoman(number: Int) -> String {
// TODO: Implement this function.
return ""
}
```swift
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// intToMiniRoman(number: 19) == "xix"
// intToMiniRoman(number: 152) == "clii"
// intToMiniRoman(number: 426) == "cdxxvi"
func intToMiniRoman(number: Int) -> String {
// TODO: Implement this function.
return ""
}
```
// XCTAssertTrue failed
func intToMiniRoman(number: Int) -> String {
var result = ""
var num = number
var roman = ["M": 1000, "CM": 900, "D": 500, "CD": 400, "C": 100, "XC": 90, "L": 50, "XL": 40, "X": 10, "IX": 9, "V": 5, "IV": 4, "I": 1]
for (key, value) in roman {
while num >= value {
result += key
num -= value
}
}
return result
}
```swift
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// intToMiniRoman(number: 19) == "xix"
// intToMiniRoman(number: 152) == "clii"
// intToMiniRoman(number: 426) == "cdxxvi"
func intToMiniRoman(number: Int) -> String {
var result = ""
var num = number
var roman = ["M": 1000, "CM": 900, "D": 500, "CD": 400, "C": 100, "XC": 90, "L": 50, "XL": 40, "X": 10, "IX": 9, "V": 5, "IV": 4, "I": 1]
for (key, value) in roman {
while num >= value {
result += key
num -= value
}
}
return result
}
```
var roman = ["M": 1000, "CM": 900, "D": 500, "CD": 400, "C": 100, "XC": 90, "L": 50, "XL": 40, "X": 10, "IX": 9, "V": 5, "IV": 4, "I": 1] // variable 'roman' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
```swift
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// intToMiniRoman(number: 19) == "xix"
// intToMiniRoman(number: 152) == "clii"
// intToMiniRoman(number: 426) == "cdxxvi"
func intToMiniRoman(number: Int) -> String {
let romanNumerals = [
1: "i",
5: "v",
10: "x",
50: "l",
100: "c",
500: "d",
1000: "m"
]
var result = ""
var number = number
var romanNumeral = ""
var romanNumeralValue = 0
var romanNumeralValueToSubtract = 0
var romanNumeralValueToSubtractFrom = 0
var romanNumeralValueToSubtractFromIndex = 0
var romanNumeralValueToSubtractFromIndexToSubtract = 0
var romanNumeralValueToSubtractFromIndexToSubtractFrom = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndex = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtract = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtractFrom = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtractFromIndex = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtract = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFrom = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndex = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtract = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFrom = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndex = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtract = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFrom = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndex = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtract = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFrom = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndex = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtract = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFrom = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndex = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtract = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFrom = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndex = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtract = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFrom = 0
var romanNumeralValueToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndexToSubtractFromIndex = 0
var roman
XCTAssertTrue(intToMiniRoman(number: 19) == "xix") // cannot find 'intToMiniRoman' in scope
XCTAssertTrue(intToMiniRoman(number: 152) == "clii") // cannot find 'intToMiniRoman' in scope
XCTAssertTrue(intToMiniRoman(number: 251) == "ccli") // cannot find 'intToMiniRoman' in scope
XCTAssertTrue(intToMiniRoman(number: 426) == "cdxxvi") // cannot find 'intToMiniRoman' in scope
XCTAssertTrue(intToMiniRoman(number: 500) == "d") // cannot find 'intToMiniRoman' in scope
XCTAssertTrue(intToMiniRoman(number: 1) == "i") // cannot find 'intToMiniRoman' in scope
XCTAssertTrue(intToMiniRoman(number: 4) == "iv") // cannot find 'intToMiniRoman' in scope
XCTAssertTrue(intToMiniRoman(number: 43) == "xliii") // cannot find 'intToMiniRoman' in scope
XCTAssertTrue(intToMiniRoman(number: 90) == "xc") // cannot find 'intToMiniRoman' in scope
XCTAssertTrue(intToMiniRoman(number: 94) == "xciv") // cannot find 'intToMiniRoman' in scope
XCTAssertTrue(intToMiniRoman(number: 532) == "dxxxii") // cannot find 'intToMiniRoman' in scope
XCTAssertTrue(intToMiniRoman(number: 900) == "cm") // cannot find 'intToMiniRoman' in scope
XCTAssertTrue(intToMiniRoman(number: 994) == "cmxciv") // cannot find 'intToMiniRoman' in scope
XCTAssertTrue(intToMiniRoman(number: 1000) == "m") // cannot find 'intToMiniRoman' in scope
func intToMiniRoman(number: Int) -> String {
// Write your code here.
}
```swift
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// intToMiniRoman(number: 19) == "xix"
// intToMiniRoman(number: 152) == "clii"
// intToMiniRoman(number: 426) == "cdxxvi"
func intToMiniRoman(number: Int) -> String {
// Write your code here.
}
```
} // missing return in global function expected to return 'String'
func intToMiniRoman(number: Int) -> String {
var result = ""
var num = number
while num > 0 {
if num >= 1000 {
result += "m"
num -= 1000
} else if num >= 900 {
result += "cm"
num -= 900
} else if num >= 500 {
result += "d"
num -= 500
} else if num >= 400 {
result += "cd"
num -= 400
} else if num >= 100 {
result += "c"
num -= 100
} else if num >= 90 {
result += "xc"
num -= 90
} else if num >= 50 {
result += "l"
num -= 50
} else if num >= 40 {
result += "xl"
num -= 40
} else if num >= 10 {
result += "x"
num -= 10
} else if num >= 9 {
result += "ix"
num -= 9
} else if num >= 5 {
result += "v"
num -= 5
} else if num >= 4 {
result += "iv"
num -= 4
} else if num >= 1 {
result += "i"
num -= 1
}
}
return result
}
```swift
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// intToMiniRoman(number: 19) == "xix"
// intToMiniRoman(number: 152) == "clii"
// intToMiniRoman(number: 426) == "cdxxvi"
func intToMiniRoman(number: Int) -> String {
var result = ""
var num = number
while num > 0 {
if num >= 1000 {
result += "m"
num -= 1000
} else if num >= 900 {
result += "cm"
num -= 900
} else if num >= 500 {
result += "d"
num -= 500
} else if num >= 400 {
result += "cd"
num -= 400
} else if num >= 100 {
result += "c"
num -= 100
} else if num >= 90 {
result += "xc"
num -= 90
} else if num >= 50 {
result += "l"
num -= 50
} else if num >= 40 {
result += "xl"
num -= 40
} else if num >= 10 {
result += "x"
num -= 10
} else if num >= 9 {
result += "ix"
num -= 9
} else if num >= 5 {
result += "v"
num -= 5
} else if num >= 4 {
result += "iv"
num -= 4
} else if num >= 1 {
result += "i"
num -= 1
}
}
return result
}
```
func intToMiniRoman(number: Int) -> String {
var result = ""
var num = number
var roman = [
"M": 1000,
"CM": 900,
"D": 500,
"CD": 400,
"C": 100,
"XC": 90,
"L": 50,
"XL": 40,
"X": 10,
"IX": 9,
"V": 5,
"IV": 4,
"I": 1
]
for (key, value) in roman {
while num >= value {
result += key
num -= value
}
}
return result
}
```swift
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// intToMiniRoman(number: 19) == "xix"
// intToMiniRoman(number: 152) == "clii"
// intToMiniRoman(number: 426) == "cdxxvi"
func intToMiniRoman(number: Int) -> String {
var result = ""
var num = number
var roman = [
"M": 1000,
"CM": 900,
"D": 500,
"CD": 400,
"C": 100,
"XC": 90,
"L": 50,
"XL": 40,
"X": 10,
"IX": 9,
"V": 5,
"IV": 4,
"I": 1
]
for (key, value) in roman {
while num >= value {
result += key
num -= value
}
}
return result
}
```
var roman = [ // variable 'roman' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func intToMiniRoman(number: Int) -> String {
var result = ""
var num = number
var roman = [
"M": 1000,
"CM": 900,
"D": 500,
"CD": 400,
"C": 100,
"XC": 90,
"L": 50,
"XL": 40,
"X": 10,
"IX": 9,
"V": 5,
"IV": 4,
"I": 1
]
for (key, value) in roman {
while num >= value {
result += key
num -= value
}
}
return result
}
```swift
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// intToMiniRoman(number: 19) == "xix"
// intToMiniRoman(number: 152) == "clii"
// intToMiniRoman(number: 426) == "cdxxvi"
func intToMiniRoman(number: Int) -> String {
var result = ""
var num = number
var roman = [
"M": 1000,
"CM": 900,
"D": 500,
"CD": 400,
"C": 100,
"XC": 90,
"L": 50,
"XL": 40,
"X": 10,
"IX": 9,
"V": 5,
"IV": 4,
"I": 1
]
for (key, value) in roman {
while num >= value {
result += key
num -= value
}
}
return result
}
```
var roman = [ // variable 'roman' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func intToMiniRoman(number: Int) -> String {
var roman = ""
var num = number
while num > 0 {
if num >= 1000 {
roman += "m" * (num / 1000)
num %= 1000
} else if num >= 900 {
roman += "cm"
num -= 900
} else if num >= 500 {
roman += "d"
num -= 500
} else if num >= 400 {
roman += "cd"
num -= 400
} else if num >= 100 {
roman += "c" * (num / 100)
num %= 100
} else if num >= 90 {
roman += "xc"
num -= 90
} else if num >= 50 {
roman += "l"
num -= 50
} else if num >= 40 {
roman += "xl"
num -= 40
} else if num >= 10 {
roman += "x" * (num / 10)
num %= 10
} else if num >= 9 {
roman += "ix"
num -= 9
} else if num >= 5 {
roman += "v"
num -= 5
} else if num >= 4 {
roman += "iv"
num -= 4
} else if num >= 1 {
roman += "i" * num
num = 0
}
}
return roman
}
```swift
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// intToMiniRoman(number: 19) == "xix"
// intToMiniRoman(number: 152) == "clii"
// intToMiniRoman(number: 426) == "cdxxvi"
func intToMiniRoman(number: Int) -> String {
var roman = ""
var num = number
while num > 0 {
if num >= 1000 {
roman += "m" * (num / 1000)
num %= 1000
} else if num >= 900 {
roman += "cm"
num -= 900
} else if num >= 500 {
roman += "d"
num -= 500
} else if num >= 400 {
roman += "cd"
num -= 400
} else if num >= 100 {
roman += "c" * (num / 100)
num %= 100
} else if num >= 90 {
roman += "xc"
num -= 90
} else if num >= 50 {
roman += "l"
num -= 50
} else if num >= 40 {
roman += "xl"
num -= 40
} else if num >= 10 {
roman += "x" * (num / 10)
num %= 10
} else if num >= 9 {
roman += "ix"
num -= 9
} else if num >= 5 {
roman += "v"
num -= 5
} else if num >= 4 {
roman += "iv"
num -= 4
} else if num >= 1 {
roman += "i" * num
num = 0
}
}
return roman
}
```
roman += "m" * (num / 1000) // binary operator '+=' cannot be applied to operands of type 'String' and 'Int'
roman += "m" * (num / 1000) // binary operator '*' cannot be applied to operands of type 'String' and 'Int'
roman += "c" * (num / 100) // binary operator '+=' cannot be applied to operands of type 'String' and 'Int'
roman += "c" * (num / 100) // binary operator '*' cannot be applied to operands of type 'String' and 'Int'
roman += "x" * (num / 10) // binary operator '+=' cannot be applied to operands of type 'String' and 'Int'
roman += "x" * (num / 10) // binary operator '*' cannot be applied to operands of type 'String' and 'Int'
roman += "i" * num // binary operator '+=' cannot be applied to operands of type 'String' and 'Int'
roman += "i" * num // binary operator '*' cannot be applied to operands of type 'String' and 'Int'
func intToMiniRoman(number: Int) -> String {
var result = ""
var num = number
while num > 0 {
if num >= 1000 {
result += "m" * (num / 1000)
num %= 1000
} else if num >= 500 {
result += "d"
if num >= 900 {
result += "cm"
num -= 900
} else {
result += "c" * (num / 500)
num %= 500
}
} else if num >= 100 {
result += "c" * (num / 100)
num %= 100
} else if num >= 50 {
result += "l"
if num >= 90 {
result += "xc"
num -= 90
} else {
result += "x" * (num / 50)
num %= 50
}
} else if num >= 10 {
result += "x" * (num / 10)
num %= 10
} else if num >= 5 {
result += "v"
if num >= 9 {
result += "ix"
num -= 9
} else {
result += "i" * (num / 5)
num %= 5
}
} else {
result += "i" * num
num = 0
}
}
return result
}
```swift
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// intToMiniRoman(number: 19) == "xix"
// intToMiniRoman(number: 152) == "clii"
// intToMiniRoman(number: 426) == "cdxxvi"
func intToMiniRoman(number: Int) -> String {
var result = ""
var num = number
while num > 0 {
if num >= 1000 {
result += "m" * (num / 1000)
num %= 1000
} else if num >= 500 {
result += "d"
if num >= 900 {
result += "cm"
num -= 900
} else {
result += "c" * (num / 500)
num %= 500
}
} else if num >= 100 {
result += "c" * (num / 100)
num %= 100
} else if num >= 50 {
result += "l"
if num >= 90 {
result += "xc"
num -= 90
} else {
result += "x" * (num / 50)
num %= 50
}
} else if num >= 10 {
result += "x" * (num / 10)
num %= 10
} else if num >= 5 {
result += "v"
if num >= 9 {
result += "ix"
num -= 9
} else {
result += "i" * (num / 5)
num %= 5
}
} else {
result += "i" * num
num = 0
}
}
return result
}
```
result += "m" * (num / 1000) // binary operator '*' cannot be applied to operands of type 'String' and 'Int'
result += "m" * (num / 1000) // binary operator '+=' cannot be applied to operands of type 'String' and 'Int'
result += "c" * (num / 500) // binary operator '*' cannot be applied to operands of type 'String' and 'Int'
result += "c" * (num / 500) // binary operator '+=' cannot be applied to operands of type 'String' and 'Int'
result += "c" * (num / 100) // binary operator '+=' cannot be applied to operands of type 'String' and 'Int'
result += "c" * (num / 100) // binary operator '*' cannot be applied to operands of type 'String' and 'Int'
result += "x" * (num / 50) // binary operator '+=' cannot be applied to operands of type 'String' and 'Int'
result += "x" * (num / 50) // binary operator '*' cannot be applied to operands of type 'String' and 'Int'
result += "x" * (num / 10) // binary operator '+=' cannot be applied to operands of type 'String' and 'Int'
result += "x" * (num / 10) // binary operator '*' cannot be applied to operands of type 'String' and 'Int'
result += "i" * (num / 5) // binary operator '*' cannot be applied to operands of type 'String' and 'Int'
result += "i" * (num / 5) // binary operator '+=' cannot be applied to operands of type 'String' and 'Int'
result += "i" * num // binary operator '*' cannot be applied to operands of type 'String' and 'Int'
result += "i" * num // binary operator '+=' cannot be applied to operands of type 'String' and 'Int'
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Your code here
}
```swift
// Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// rightAngleTriangle(a: 3, b: 4, c: 5) == true
// rightAngleTriangle(a: 1, b: 2, c: 3) == false
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
return (a * a + b * b == c * c) || (a * a + c * c == b * b) || (b * b + c * c == a * a)
}
```swift
// Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// rightAngleTriangle(a: 3, b: 4, c: 5) == true
// rightAngleTriangle(a: 1, b: 2, c: 3) == false
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
return (a * a + b * b == c * c) || (a * a + c * c == b * b) || (b * b + c * c == a * a)
}
```
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
return a * a + b * b == c * c || a * a + c * c == b * b || b * b + c * c == a * a
}
```swift
// Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// rightAngleTriangle(a: 3, b: 4, c: 5) == true
// rightAngleTriangle(a: 1, b: 2, c: 3) == false
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
return a * a + b * b == c * c || a * a + c * c == b * b || b * b + c * c == a * a
}
```
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Your code here
}
```swift
// Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// rightAngleTriangle(a: 3, b: 4, c: 5) == true
// rightAngleTriangle(a: 1, b: 2, c: 3) == false
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
return (a * a + b * b == c * c) || (a * a + c * c == b * b) || (b * b + c * c == a * a)
}
```swift
// Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// rightAngleTriangle(a: 3, b: 4, c: 5) == true
// rightAngleTriangle(a: 1, b: 2, c: 3) == false
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
return (a * a + b * b == c * c) || (a * a + c * c == b * b) || (b * b + c * c == a * a)
}
```
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Your code here
}
```swift
// Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// rightAngleTriangle(a: 3, b: 4, c: 5) == true
// rightAngleTriangle(a: 1, b: 2, c: 3) == false
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
return (a * a) + (b * b) == (c * c)
}
```swift
// Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// rightAngleTriangle(a: 3, b: 4, c: 5) == true
// rightAngleTriangle(a: 1, b: 2, c: 3) == false
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
return (a * a) + (b * b) == (c * c)
}
```
// XCTAssertTrue failed
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
return (a * a + b * b == c * c) || (a * a + c * c == b * b) || (b * b + c * c == a * a)
}
```swift
// Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// rightAngleTriangle(a: 3, b: 4, c: 5) == true
// rightAngleTriangle(a: 1, b: 2, c: 3) == false
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
return (a * a + b * b == c * c) || (a * a + c * c == b * b) || (b * b + c * c == a * a)
}
```
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
return a * a + b * b == c * c
}
```swift
// Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// rightAngleTriangle(a: 3, b: 4, c: 5) == true
// rightAngleTriangle(a: 1, b: 2, c: 3) == false
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
return a * a + b * b == c * c
}
```
// XCTAssertTrue failed
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
return a * a + b * b == c * c || a * a + c * c == b * b || b * b + c * c == a * a
}
```swift
// Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// rightAngleTriangle(a: 3, b: 4, c: 5) == true
// rightAngleTriangle(a: 1, b: 2, c: 3) == false
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
return a * a + b * b == c * c || a * a + c * c == b * b || b * b + c * c == a * a
}
```
func findMax(words: [String]) -> String {
// Write your code here
}
```swift
// Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// findMax(words: ["name", "of", "string"]) == "string"
// findMax(words: ["name", "enam", "game"]) == "enam"
// findMax(words: ["aaaaaaa", "bb", "cc"]) == "aaaaaaa"
func findMax(words: [String]) -> String {
// Write your code here
}
```
} // missing return in global function expected to return 'String'
func findMax(words: [String]) -> String {
// Write your code here
}
```swift
// Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// findMax(words: ["name", "of", "string"]) == "string"
// findMax(words: ["name", "enam", "game"]) == "enam"
// findMax(words: ["aaaaaaa", "bb", "cc"]) == "aaaaaaa"
func findMax(words: [String]) -> String {
// Write your code here
}
```
} // missing return in global function expected to return 'String'
func findMax(words: [String]) -> String {
// Write your code here
}
```swift
// Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// findMax(words: ["name", "of", "string"]) == "string"
// findMax(words: ["name", "enam", "game"]) == "enam"
// findMax(words: ["aaaaaaa", "bb", "cc"]) == "aaaaaaa"
func findMax(words: [String]) -> String {
// Write your code here
}
```
} // missing return in global function expected to return 'String'
func findMax(words: [String]) -> String {
// Your code here
}
```swift
// Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// findMax(words: ["name", "of", "string"]) == "string"
// findMax(words: ["name", "enam", "game"]) == "enam"
// findMax(words: ["aaaaaaa", "bb", "cc"]) == "aaaaaaa"
func findMax(words: [String]) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func findMax(words: [String]) -> String {
// Write your code here
}
```swift
// Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// findMax(words: ["name", "of", "string"]) == "string"
// findMax(words: ["name", "enam", "game"]) == "enam"
// findMax(words: ["aaaaaaa", "bb", "cc"]) == "aaaaaaa"
func findMax(words: [String]) -> String {
// Write your code here
}
```
} // missing return in global function expected to return 'String'
func findMax(words: [String]) -> String {
// Write your code here
}
```swift
// Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// findMax(words: ["name", "of", "string"]) == "string"
// findMax(words: ["name", "enam", "game"]) == "enam"
// findMax(words: ["aaaaaaa", "bb", "cc"]) == "aaaaaaa"
func findMax(words: [String]) -> String {
// Write your code here
}
```
} // missing return in global function expected to return 'String'
func findMax(words: [String]) -> String {
// your code here
}
```swift
// Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// findMax(words: ["name", "of", "string"]) == "string"
// findMax(words: ["name", "enam", "game"]) == "enam"
// findMax(words: ["aaaaaaa", "bb", "cc"]) == "aaaaaaa"
func findMax(words: [String]) -> String {
// your code here
}
```
} // missing return in global function expected to return 'String'
func findMax(words: [String]) -> String {
// Your code goes here
}
```swift
// Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// findMax(words: ["name", "of", "string"]) == "string"
// findMax(words: ["name", "enam", "game"]) == "enam"
// findMax(words: ["aaaaaaa", "bb", "cc"]) == "aaaaaaa"
func findMax(words: [String]) -> String {
// Your code goes here
}
```
} // missing return in global function expected to return 'String'
func findMax(words: [String]) -> String {
var max = ""
var maxCount = 0
for word in words {
let count = Set(word).count
if count > maxCount {
max = word
maxCount = count
}
}
return max
}
```swift
// Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// findMax(words: ["name", "of", "string"]) == "string"
// findMax(words: ["name", "enam", "game"]) == "enam"
// findMax(words: ["aaaaaaa", "bb", "cc"]) == "aaaaaaa"
func findMax(words: [String]) -> String {
var max = ""
var maxCount = 0
for word in words {
let count = Set(word).count
if count > maxCount {
max = word
maxCount = count
}
}
return max
}
```
// XCTAssertTrue failed
func findMax(words: [String]) -> String {
var max = 0
var maxWord = ""
for word in words {
if word.count > max {
max = word.count
maxWord = word
}
}
return maxWord
}
```swift
// Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// findMax(words: ["name", "of", "string"]) == "string"
// findMax(words: ["name", "enam", "game"]) == "enam"
// findMax(words: ["aaaaaaa", "bb", "cc"]) == "aaaaaaa"
func findMax(words: [String]) -> String {
var max = 0
var maxWord = ""
for word in words {
if word.count > max {
max = word.count
maxWord = word
}
}
return maxWord
}
```
// XCTAssertTrue failed
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
return [0, 0]
}
```swift
// You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
// eat(number: 5, need: 6, remaining: 10) == [11, 4]
// eat(number: 4, need: 8, remaining: 9) == [12, 1]
// eat(number: 1, need: 10, remaining: 10) == [11, 0]
// eat(number: 2, need: 11, remaining: 5) == [7, 0]
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
return [0, 0]
}
```
// XCTAssertTrue failed
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```swift
// You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
// eat(number: 5, need: 6, remaining: 10) == [11, 4]
// eat(number: 4, need: 8, remaining: 9) == [12, 1]
// eat(number: 1, need: 10, remaining: 10) == [11, 0]
// eat(number: 2, need: 11, remaining: 5) == [7, 0]
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```swift
// You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
// eat(number: 5, need: 6, remaining: 10) == [11, 4]
// eat(number: 4, need: 8, remaining: 9) == [12, 1]
// eat(number: 1, need: 10, remaining: 10) == [11, 0]
// eat(number: 2, need: 11, remaining: 5) == [7, 0]
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
return [number + need, remaining - need]
}
```swift
// You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
// eat(number: 5, need: 6, remaining: 10) == [11, 4]
// eat(number: 4, need: 8, remaining: 9) == [12, 1]
// eat(number: 1, need: 10, remaining: 10) == [11, 0]
// eat(number: 2, need: 11, remaining: 5) == [7, 0]
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
return [number + need, remaining - need]
}
```
// XCTAssertTrue failed
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
return [0, 0]
}
```swift
// You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
// eat(number: 5, need: 6, remaining: 10) == [11, 4]
// eat(number: 4, need: 8, remaining: 9) == [12, 1]
// eat(number: 1, need: 10, remaining: 10) == [11, 0]
// eat(number: 2, need: 11, remaining: 5) == [7, 0]
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
return [0, 0]
}
```
// XCTAssertTrue failed
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
return [0, 0]
}
```swift
// You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
// eat(number: 5, need: 6, remaining: 10) == [11, 4]
// eat(number: 4, need: 8, remaining: 9) == [12, 1]
// eat(number: 1, need: 10, remaining: 10) == [11, 0]
// eat(number: 2, need: 11, remaining: 5) == [7, 0]
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
return [0, 0]
}
```
// XCTAssertTrue failed
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
var result = [Int]()
var number = number
var need = need
var remaining = remaining
if number + remaining >= need {
number += remaining
remaining = 0
} else {
remaining -= (need - number)
number = need
}
result.append(number)
result.append(remaining)
return result
}
```swift
// You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
// eat(number: 5, need: 6, remaining: 10) == [11, 4]
// eat(number: 4, need: 8, remaining: 9) == [12, 1]
// eat(number: 1, need: 10, remaining: 10) == [11, 0]
// eat(number: 2, need: 11, remaining: 5) == [7, 0]
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
var result = [Int]()
var number = number
var need = need
var remaining = remaining
if number + remaining >= need {
number += remaining
remaining = 0
} else {
remaining -= (need - number)
number = need
}
result.append(number)
result.append(remaining)
return result
}
```
var need = need // variable 'need' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```swift
// You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
// eat(number: 5, need: 6, remaining: 10) == [11, 4]
// eat(number: 4, need: 8, remaining: 9) == [12, 1]
// eat(number: 1, need: 10, remaining: 10) == [11, 0]
// eat(number: 2, need: 11, remaining: 5) == [7, 0]
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
var result = [Int]()
var total = number
var need = need
var remaining = remaining
if remaining >= need {
total += need
remaining -= need
} else {
total += remaining
need -= remaining
remaining = 0
total += need
}
result.append(total)
result.append(remaining)
return result
}
```swift
// You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
// eat(number: 5, need: 6, remaining: 10) == [11, 4]
// eat(number: 4, need: 8, remaining: 9) == [12, 1]
// eat(number: 1, need: 10, remaining: 10) == [11, 0]
// eat(number: 2, need: 11, remaining: 5) == [7, 0]
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
var result = [Int]()
var total = number
var need = need
var remaining = remaining
if remaining >= need {
total += need
remaining -= need
} else {
total += remaining
need -= remaining
remaining = 0
total += need
}
result.append(total)
result.append(remaining)
return result
}
```
// XCTAssertTrue failed
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
var result = [Int]()
var total = 0
var left = 0
if need > remaining {
total = number + remaining
left = 0
} else {
total = number + need
left = remaining - need
}
result.append(total)
result.append(left)
return result
}
```swift
// You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
// eat(number: 5, need: 6, remaining: 10) == [11, 4]
// eat(number: 4, need: 8, remaining: 9) == [12, 1]
// eat(number: 1, need: 10, remaining: 10) == [11, 0]
// eat(number: 2, need: 11, remaining: 5) == [7, 0]
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
var result = [Int]()
var total = 0
var left = 0
if need > remaining {
total = number + remaining
left = 0
} else {
total = number + need
left = remaining - need
}
result.append(total)
result.append(left)
return result
}
```
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = 0
var op = ""
for i in 0..<operators.count {
if i == 0 {
op = operators[i]
result = operands[i]
} else {
switch op {
case "+":
result += operands[i]
case "-":
result -= operands[i]
case "*":
result *= operands[i]
case "//":
result /= operands[i]
case "**":
result = Int(pow(Double(result), Double(operands[i])))
default:
break
}
op = operators[i]
}
}
return result
}
```swift
// Given two arrays operators, and operands. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = 0
var op = ""
for i in 0..<operators.count {
if i == 0 {
op = operators[i]
result = operands[i]
} else {
switch op {
case "+":
result += operands[i]
case "-":
result -= operands[i]
case "*":
result *= operands[i]
case "//":
result /= operands[i]
case "**":
result = Int(pow(Double(result), Double(operands[i])))
default:
break
}
op = operators[i]
}
}
return result
}
print(doAlgebra(operators: ["+", "*", "-"], operands: [2, 3, 4, 5]))
```
// XCTAssertTrue failed
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 1..<operands.count {
switch operators[i-1] {
case "+":
result += operands[i]
case "-":
result -= operands[i]
case "*":
result *= operands[i]
case "//":
result /= operands[i]
case "**":
result = Int(pow(Double(result), Double(operands[i])))
default:
break
}
}
return result
}
```swift
// Given two arrays operators, and operands. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 1..<operands.count {
switch operators[i-1] {
case "+":
result += operands[i]
case "-":
result -= operands[i]
case "*":
result *= operands[i]
case "//":
result /= operands[i]
case "**":
result = Int(pow(Double(result), Double(operands[i])))
default:
break
}
}
return result
}
```
// XCTAssertTrue failed
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 1..<operands.count {
let op = operators[i-1]
let op2 = operands[i]
switch op {
case "+":
result += op2
case "-":
result -= op2
case "*":
result *= op2
case "//":
result /= op2
case "**":
result = result.power(op2)
default:
break
}
}
return result
}
```swift
// Given two arrays operators, and operands. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 1..<operands.count {
let op = operators[i-1]
let op2 = operands[i]
switch op {
case "+":
result += op2
case "-":
result -= op2
case "*":
result *= op2
case "//":
result /= op2
case "**":
result = result.power(op2)
default:
break
}
}
return result
}
```
result = result.power(op2) // value of type 'Int' has no member 'power'
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 1..<operands.count {
switch operators[i - 1] {
case "+":
result += operands[i]
case "-":
result -= operands[i]
case "*":
result *= operands[i]
case "//":
result /= operands[i]
case "**":
result = Int(pow(Double(result), Double(operands[i])))
default:
break
}
}
return result
}
```swift
// Given two arrays operators, and operands. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 1..<operands.count {
switch operators[i - 1] {
case "+":
result += operands[i]
case "-":
result -= operands[i]
case "*":
result *= operands[i]
case "//":
result /= operands[i]
case "**":
result = Int(pow(Double(result), Double(operands[i])))
default:
break
}
}
return result
}
```
// XCTAssertTrue failed
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 0..<operators.count {
switch operators[i] {
case "+":
result += operands[i + 1]
case "-":
result -= operands[i + 1]
case "*":
result *= operands[i + 1]
case "//":
result /= operands[i + 1]
case "**":
result = Int(pow(Double(result), Double(operands[i + 1])))
default:
break
}
}
return result
}
```swift
// Given two arrays operators, and operands. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 0..<operators.count {
switch operators[i] {
case "+":
result += operands[i + 1]
case "-":
result -= operands[i + 1]
case "*":
result *= operands[i + 1]
case "//":
result /= operands[i + 1]
case "**":
result = Int(pow(Double(result), Double(operands[i + 1])))
default:
break
}
}
return result
}
```
// XCTAssertTrue failed
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 1..<operands.count {
if operators[i - 1] == "+" {
result += operands[i]
} else if operators[i - 1] == "-" {
result -= operands[i]
} else if operators[i - 1] == "*" {
result *= operands[i]
} else if operators[i - 1] == "//" {
result /= operands[i]
} else if operators[i - 1] == "**" {
result = Int(pow(Double(result), Double(operands[i])))
}
}
return result
}
```swift
// Given two arrays operators, and operands. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 1..<operands.count {
if operators[i - 1] == "+" {
result += operands[i]
} else if operators[i - 1] == "-" {
result -= operands[i]
} else if operators[i - 1] == "*" {
result *= operands[i]
} else if operators[i - 1] == "//" {
result /= operands[i]
} else if operators[i - 1] == "**" {
result = Int(pow(Double(result), Double(operands[i])))
}
}
return result
}
print(doAlgebra(operators: ["+", "*", "-"], operands: [2, 3, 4, 5]))
```
// XCTAssertTrue failed
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 1..<operands.count {
switch operators[i - 1] {
case "+":
result += operands[i]
case "-":
result -= operands[i]
case "*":
result *= operands[i]
case "//":
result /= operands[i]
case "**":
result = Int(pow(Double(result), Double(operands[i])))
default:
break
}
}
return result
}
```swift
// Given two arrays operators, and operands. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 1..<operands.count {
switch operators[i - 1] {
case "+":
result += operands[i]
case "-":
result -= operands[i]
case "*":
result *= operands[i]
case "//":
result /= operands[i]
case "**":
result = Int(pow(Double(result), Double(operands[i])))
default:
break
}
}
return result
}
```
// XCTAssertTrue failed
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = 0
var op = ""
for i in 0..<operators.count {
if i == 0 {
op = operators[i]
result = operands[i]
} else {
switch op {
case "+":
result += operands[i]
case "-":
result -= operands[i]
case "*":
result *= operands[i]
case "//":
result /= operands[i]
case "**":
result = Int(pow(Double(result), Double(operands[i])))
default:
break
}
op = operators[i]
}
}
return result
}
func arrayPlusArray(arr: [Int]) -> [Int] {
var result = [Int]()
for i in arr {
result.append(i * 2)
}
return result
}
func doubleChar(str: String) -> String {
var result = ""
for i in str {
result += "\(i)\(i)"
}
return result
}
func sumFirstLast(arr: [Int]) -> Int {
var result = 0
if arr.count > 0 {
result = arr[0] + arr[arr.count - 1]
}
return result
}
```swift
// Given two arrays operators, and operands. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = 0
var op = ""
for i in 0..<operators.count {
if i == 0 {
op = operators[i]
result = operands[i]
} else {
switch op {
case "+":
result += operands[i]
case "-":
result -= operands[i]
case "*":
result *= operands[i]
case "//":
result /= operands[i]
case "**":
result = Int(pow(Double(result), Double(operands[i])))
default:
break
}
op = operators[i]
}
}
return result
}
// Given an array of integers, return a new array with each value doubled.
// For example:
// [1, 2, 3] --> [2, 4, 6]
func arrayPlusArray(arr: [Int]) -> [Int] {
var result = [Int]()
for i in arr {
result.append(i * 2)
}
return result
}
// Given a string, return a string where for every char in the original, there are two chars.
// doubleChar("The") --> "TThhee"
// doubleChar("AAbb") --> "AAAAbbbb"
// doubleChar("Hi-There") --> "HHii--HHeeerrrttt"
func doubleChar(str: String) -> String {
var result = ""
for i in str {
result += "\(i)\(i)"
}
return result
}
// Given an array of integers, return the sum of the first and last elements.
// Note: By first and last I mean the first and last elements of the given array and not the first and last elements of the given array.
// Example:
// [1, 2, 3] --> 1 + 3 = 4
// [13, 2, 9] --> 13 + 9 = 22
func sumFirstLast(arr: [Int]) -> Int {
var result = 0
if arr.count > 0 {
result = arr[0] + arr[arr.count - 1]
}
return result
}
// Given an array of integers, return the sum of the first and last elements.
// Note: By first and last I mean the first and last elements of the given array and not the first and last elements of the given array.
// Example:
// [1, 2, 3] --> 1 + 3 = 4
// [13, 2, 9] --> 13 + 9 = 22
func sumFirstLast(arr: [Int]) -> Int {
var result = 0
if arr.count > 0 {
result = arr[0] + arr[arr.count - 1]
}
return result
}
// Given an array of integers, return the sum of the first and last elements.
// Note: By first and last I mean the first and last elements of the given array and not the first and last elements of the given array.
// Example:
// [1, 2, 3] --> 1 + 3 = 4
// [13, 2, 9] --> 13 + 9 = 22
func sumFirstLast(arr: [Int]) -> Int {
var result = 0
if arr.count > 0 {
result = arr[0] + arr[arr.count - 1]
}
return result
}
// Given an array of integers, return the sum of the first and last elements.
// Note: By first and last I mean the first and last elements of the given array and not the first and last elements of the given array.
// Example:
// [1, 2, 3] --> 1 + 3 = 4
// [13, 2, 9] --> 13 + 9 = 22
func sumFirstLast(arr: [Int]) -> Int {
var result = 0
if arr.count > 0 {
result = arr[0] + arr[arr.count - 1]
}
return result
}
// Given an array of integers, return the sum of the first and last elements.
// Note: By first and last I mean the first and last elements of the given array and not the first and last elements of the given array.
// Example:
// [1, 2, 3] --> 1 + 3 = 4
// [13, 2,
// XCTAssertTrue failed
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 1..<operands.count {
if operators[i-1] == "+" {
result += operands[i]
} else if operators[i-1] == "-" {
result -= operands[i]
} else if operators[i-1] == "*" {
result *= operands[i]
} else if operators[i-1] == "//" {
result /= operands[i]
} else if operators[i-1] == "**" {
result = Int(pow(Double(result), Double(operands[i])))
}
}
return result
}
```swift
// Given two arrays operators, and operands. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 1..<operands.count {
if operators[i-1] == "+" {
result += operands[i]
} else if operators[i-1] == "-" {
result -= operands[i]
} else if operators[i-1] == "*" {
result *= operands[i]
} else if operators[i-1] == "//" {
result /= operands[i]
} else if operators[i-1] == "**" {
result = Int(pow(Double(result), Double(operands[i])))
}
}
return result
}
print(doAlgebra(operators: ["+", "*", "-"], operands: [2, 3, 4, 5]))
```
// XCTAssertTrue failed
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 1..<operands.count {
if operators[i-1] == "+" {
result += operands[i]
} else if operators[i-1] == "-" {
result -= operands[i]
} else if operators[i-1] == "*" {
result *= operands[i]
} else if operators[i-1] == "//" {
result /= operands[i]
} else if operators[i-1] == "**" {
result = Int(pow(Double(result), Double(operands[i])))
}
}
return result
}
```swift
// Given two arrays operators, and operands. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 1..<operands.count {
if operators[i-1] == "+" {
result += operands[i]
} else if operators[i-1] == "-" {
result -= operands[i]
} else if operators[i-1] == "*" {
result *= operands[i]
} else if operators[i-1] == "//" {
result /= operands[i]
} else if operators[i-1] == "**" {
result = Int(pow(Double(result), Double(operands[i])))
}
}
return result
}
```
// XCTAssertTrue failed
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result += char.isUppercase? char.lowercased() : char.uppercased()
} else {
result += String(char)
}
}
return result
}
```swift
// You are given a string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as it is.
// If the string contains no letters, reverse the string.
// The function should return the resulted string.
// Examples
// solve(s: "1234") == "4321"
// solve(s: "ab") == "AB"
// solve(s: "#a@C") == "#A@c"
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result += char.isUppercase? char.lowercased() : char.uppercased()
} else {
result += String(char)
}
}
return result
}
```
result += char.isUppercase? char.lowercased() : char.uppercased() // consecutive statements on a line must be separated by ';'
result += char.isUppercase? char.lowercased() : char.uppercased() // expected expression
result += char.isUppercase? char.lowercased() : char.uppercased() // binary operator '+=' cannot be applied to operands of type 'String' and 'Bool?'
result += char.isUppercase? char.lowercased() : char.uppercased() // result of call to 'lowercased()' is unused
result += char.isUppercase? char.lowercased() : char.uppercased() // consecutive statements on a line must be separated by ';'
result += char.isUppercase? char.lowercased() : char.uppercased() // cannot use optional chaining on non-optional value of type 'Bool'
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result.append(char.isUppercase? char.lowercased() : char.uppercased())
} else {
result.append(char)
}
}
return result
}
```swift
// You are given a string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as it is.
// If the string contains no letters, reverse the string.
// The function should return the resulted string.
// Examples
// solve(s: "1234") == "4321"
// solve(s: "ab") == "AB"
// solve(s: "#a@C") == "#A@c"
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result.append(char.isUppercase? char.lowercased() : char.uppercased())
} else {
result.append(char)
}
}
return result
}
```
result.append(char.isUppercase? char.lowercased() : char.uppercased()) // expected ',' separator
result.append(char.isUppercase? char.lowercased() : char.uppercased()) // no exact matches in call to instance method 'append'
result.append(char.isUppercase? char.lowercased() : char.uppercased()) // cannot use optional chaining on non-optional value of type 'Bool'
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result.append(char.isUppercase? char.lowercased() : char.uppercased())
} else {
result.append(char)
}
}
return result
}
```swift
// You are given a string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as it is.
// If the string contains no letters, reverse the string.
// The function should return the resulted string.
// Examples
// solve(s: "1234") == "4321"
// solve(s: "ab") == "AB"
// solve(s: "#a@C") == "#A@c"
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result.append(char.isUppercase? char.lowercased() : char.uppercased())
} else {
result.append(char)
}
}
return result
}
```
result.append(char.isUppercase? char.lowercased() : char.uppercased()) // expected ',' separator
result.append(char.isUppercase? char.lowercased() : char.uppercased()) // no exact matches in call to instance method 'append'
result.append(char.isUppercase? char.lowercased() : char.uppercased()) // cannot use optional chaining on non-optional value of type 'Bool'
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result += char.isUppercase? char.lowercased() : char.uppercased()
} else {
result += String(char)
}
}
return result
}
```swift
// You are given a string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as it is.
// If the string contains no letters, reverse the string.
// The function should return the resulted string.
// Examples
// solve(s: "1234") == "4321"
// solve(s: "ab") == "AB"
// solve(s: "#a@C") == "#A@c"
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result += char.isUppercase? char.lowercased() : char.uppercased()
} else {
result += String(char)
}
}
return result
}
```
result += char.isUppercase? char.lowercased() : char.uppercased() // consecutive statements on a line must be separated by ';'
result += char.isUppercase? char.lowercased() : char.uppercased() // expected expression
result += char.isUppercase? char.lowercased() : char.uppercased() // binary operator '+=' cannot be applied to operands of type 'String' and 'Bool?'
result += char.isUppercase? char.lowercased() : char.uppercased() // result of call to 'lowercased()' is unused
result += char.isUppercase? char.lowercased() : char.uppercased() // consecutive statements on a line must be separated by ';'
result += char.isUppercase? char.lowercased() : char.uppercased() // cannot use optional chaining on non-optional value of type 'Bool'
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result += char.isUppercase? String(char).lowercased() : String(char).uppercased()
} else {
result += String(char)
}
}
return result
}
```swift
// You are given a string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as it is.
// If the string contains no letters, reverse the string.
// The function should return the resulted string.
// Examples
// solve(s: "1234") == "4321"
// solve(s: "ab") == "AB"
// solve(s: "#a@C") == "#A@c"
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result += char.isUppercase? String(char).lowercased() : String(char).uppercased()
} else {
result += String(char)
}
}
return result
}
```
result += char.isUppercase? String(char).lowercased() : String(char).uppercased() // consecutive statements on a line must be separated by ';'
result += char.isUppercase? String(char).lowercased() : String(char).uppercased() // binary operator '+=' cannot be applied to operands of type 'String' and 'Bool?'
result += char.isUppercase? String(char).lowercased() : String(char).uppercased() // expected expression
result += char.isUppercase? String(char).lowercased() : String(char).uppercased() // result of call to 'lowercased()' is unused
result += char.isUppercase? String(char).lowercased() : String(char).uppercased() // cannot use optional chaining on non-optional value of type 'Bool'
result += char.isUppercase? String(char).lowercased() : String(char).uppercased() // consecutive statements on a line must be separated by ';'
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result += char.isUppercase? char.lowercased() : char.uppercased()
} else {
result += String(char)
}
}
return result
}
```swift
// You are given a string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as it is.
// If the string contains no letters, reverse the string.
// The function should return the resulted string.
// Examples
// solve(s: "1234") == "4321"
// solve(s: "ab") == "AB"
// solve(s: "#a@C") == "#A@c"
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result += char.isUppercase? char.lowercased() : char.uppercased()
} else {
result += String(char)
}
}
return result
}
```
result += char.isUppercase? char.lowercased() : char.uppercased() // consecutive statements on a line must be separated by ';'
result += char.isUppercase? char.lowercased() : char.uppercased() // expected expression
result += char.isUppercase? char.lowercased() : char.uppercased() // binary operator '+=' cannot be applied to operands of type 'String' and 'Bool?'
result += char.isUppercase? char.lowercased() : char.uppercased() // result of call to 'lowercased()' is unused
result += char.isUppercase? char.lowercased() : char.uppercased() // consecutive statements on a line must be separated by ';'
result += char.isUppercase? char.lowercased() : char.uppercased() // cannot use optional chaining on non-optional value of type 'Bool'
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result.append(char.isUppercase? char.lowercased() : char.uppercased())
} else {
result.append(char)
}
}
return result
}
```swift
// You are given a string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as it is.
// If the string contains no letters, reverse the string.
// The function should return the resulted string.
// Examples
// solve(s: "1234") == "4321"
// solve(s: "ab") == "AB"
// solve(s: "#a@C") == "#A@c"
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result.append(char.isUppercase? char.lowercased() : char.uppercased())
} else {
result.append(char)
}
}
return result
}
```
result.append(char.isUppercase? char.lowercased() : char.uppercased()) // expected ',' separator
result.append(char.isUppercase? char.lowercased() : char.uppercased()) // no exact matches in call to instance method 'append'
result.append(char.isUppercase? char.lowercased() : char.uppercased()) // cannot use optional chaining on non-optional value of type 'Bool'
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result += char.isUppercase? char.lowercased() : char.uppercased()
} else {
result += String(char)
}
}
return result
}
```swift
// You are given a string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as it is.
// If the string contains no letters, reverse the string.
// The function should return the resulted string.
// Examples
// solve(s: "1234") == "4321"
// solve(s: "ab") == "AB"
// solve(s: "#a@C") == "#A@c"
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result += char.isUppercase? char.lowercased() : char.uppercased()
} else {
result += String(char)
}
}
return result
}
```
result += char.isUppercase? char.lowercased() : char.uppercased() // consecutive statements on a line must be separated by ';'
result += char.isUppercase? char.lowercased() : char.uppercased() // expected expression
result += char.isUppercase? char.lowercased() : char.uppercased() // binary operator '+=' cannot be applied to operands of type 'String' and 'Bool?'
result += char.isUppercase? char.lowercased() : char.uppercased() // result of call to 'lowercased()' is unused
result += char.isUppercase? char.lowercased() : char.uppercased() // consecutive statements on a line must be separated by ';'
result += char.isUppercase? char.lowercased() : char.uppercased() // cannot use optional chaining on non-optional value of type 'Bool'
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result.append(char.isUppercase? char.lowercased() : char.uppercased())
} else {
result.append(char)
}
}
return result
}
```swift
// You are given a string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as it is.
// If the string contains no letters, reverse the string.
// The function should return the resulted string.
// Examples
// solve(s: "1234") == "4321"
// solve(s: "ab") == "AB"
// solve(s: "#a@C") == "#A@c"
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result.append(char.isUppercase? char.lowercased() : char.uppercased())
} else {
result.append(char)
}
}
return result
}
```
result.append(char.isUppercase? char.lowercased() : char.uppercased()) // expected ',' separator
result.append(char.isUppercase? char.lowercased() : char.uppercased()) // no exact matches in call to instance method 'append'
result.append(char.isUppercase? char.lowercased() : char.uppercased()) // cannot use optional chaining on non-optional value of type 'Bool'
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result += char.isUppercase? char.lowercased() : char.uppercased()
} else {
result += String(char)
}
}
return result
}
```swift
// You are given a string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as it is.
// If the string contains no letters, reverse the string.
// The function should return the resulted string.
// Examples
// solve(s: "1234") == "4321"
// solve(s: "ab") == "AB"
// solve(s: "#a@C") == "#A@c"
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result += char.isUppercase? char.lowercased() : char.uppercased()
} else {
result += String(char)
}
}
return result
}
```
result += char.isUppercase? char.lowercased() : char.uppercased() // consecutive statements on a line must be separated by ';'
result += char.isUppercase? char.lowercased() : char.uppercased() // expected expression
result += char.isUppercase? char.lowercased() : char.uppercased() // binary operator '+=' cannot be applied to operands of type 'String' and 'Bool?'
result += char.isUppercase? char.lowercased() : char.uppercased() // result of call to 'lowercased()' is unused
result += char.isUppercase? char.lowercased() : char.uppercased() // consecutive statements on a line must be separated by ';'
result += char.isUppercase? char.lowercased() : char.uppercased() // cannot use optional chaining on non-optional value of type 'Bool'
import CommonCrypto
func stringToMd5(text: String) -> String? {
guard!text.isEmpty else { return nil }
let data = text.data(using:.utf8)!
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
data.withUnsafeBytes {
_ = CC_MD5($0, CC_LONG(data.count), &digest)
}
return digest.map { String(format: "%02x", $0) }.joined()
}
```swift
// Given a string 'text', return its md5 hash equivalent string.
// If 'text' is an empty string, return nil.
// stringToMd5(text: "Hello world") == "3e25960a79dbc69b674cd4ec67a72c62"
func stringToMd5(text: String) -> String? {
guard!text.isEmpty else { return nil }
let data = text.data(using:.utf8)!
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
data.withUnsafeBytes {
_ = CC_MD5($0, CC_LONG(data.count), &digest)
}
return digest.map { String(format: "%02x", $0) }.joined()
}
```
guard!text.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
data.withUnsafeBytes { // 'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R` instead
_ = CC_MD5($0, CC_LONG(data.count), &digest) // 'CC_MD5' was deprecated in macOS 10.15: This function is cryptographically broken and should not be used in security contexts. Clients should migrate to SHA256 (or stronger).
import CommonCrypto
func stringToMd5(text: String) -> String? {
guard!text.isEmpty else { return nil }
let data = text.data(using:.utf8)!
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
data.withUnsafeBytes {
_ = CC_MD5($0, CC_LONG(data.count), &digest)
}
return digest.map { String(format: "%02x", $0) }.joined()
}
```swift
// Given a string 'text', return its md5 hash equivalent string.
// If 'text' is an empty string, return nil.
// stringToMd5(text: "Hello world") == "3e25960a79dbc69b674cd4ec67a72c62"
func stringToMd5(text: String) -> String? {
guard!text.isEmpty else { return nil }
let data = text.data(using:.utf8)!
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
data.withUnsafeBytes {
_ = CC_MD5($0, CC_LONG(data.count), &digest)
}
return digest.map { String(format: "%02x", $0) }.joined()
}
```
guard!text.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
data.withUnsafeBytes { // 'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R` instead
_ = CC_MD5($0, CC_LONG(data.count), &digest) // 'CC_MD5' was deprecated in macOS 10.15: This function is cryptographically broken and should not be used in security contexts. Clients should migrate to SHA256 (or stronger).
import CommonCrypto
func stringToMd5(text: String) -> String? {
guard!text.isEmpty else { return nil }
let data = text.data(using:.utf8)!
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
data.withUnsafeBytes {
_ = CC_MD5($0, CC_LONG(data.count), &digest)
}
return digest.map { String(format: "%02hhx", $0) }.joined()
}
```swift
// Given a string 'text', return its md5 hash equivalent string.
// If 'text' is an empty string, return nil.
// stringToMd5(text: "Hello world") == "3e25960a79dbc69b674cd4ec67a72c62"
func stringToMd5(text: String) -> String? {
guard!text.isEmpty else { return nil }
let data = text.data(using:.utf8)!
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
data.withUnsafeBytes {
_ = CC_MD5($0, CC_LONG(data.count), &digest)
}
return digest.map { String(format: "%02hhx", $0) }.joined()
}
```
guard!text.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
data.withUnsafeBytes { // 'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R` instead
_ = CC_MD5($0, CC_LONG(data.count), &digest) // 'CC_MD5' was deprecated in macOS 10.15: This function is cryptographically broken and should not be used in security contexts. Clients should migrate to SHA256 (or stronger).
import CommonCrypto
func stringToMd5(text: String) -> String? {
guard!text.isEmpty else { return nil }
let data = text.data(using:.utf8)!
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
data.withUnsafeBytes {
_ = CC_MD5($0, CC_LONG(data.count), &digest)
}
return digest.map { String(format: "%02x", $0) }.joined()
}
```swift
// Given a string 'text', return its md5 hash equivalent string.
// If 'text' is an empty string, return nil.
// stringToMd5(text: "Hello world") == "3e25960a79dbc69b674cd4ec67a72c62"
func stringToMd5(text: String) -> String? {
guard!text.isEmpty else { return nil }
let data = text.data(using:.utf8)!
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
data.withUnsafeBytes {
_ = CC_MD5($0, CC_LONG(data.count), &digest)
}
return digest.map { String(format: "%02x", $0) }.joined()
}
```
guard!text.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
data.withUnsafeBytes { // 'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R` instead
_ = CC_MD5($0, CC_LONG(data.count), &digest) // 'CC_MD5' was deprecated in macOS 10.15: This function is cryptographically broken and should not be used in security contexts. Clients should migrate to SHA256 (or stronger).
import CommonCrypto
func stringToMd5(text: String) -> String? {
guard!text.isEmpty else { return nil }
let data = text.data(using:.utf8)!
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
data.withUnsafeBytes {
_ = CC_MD5($0, CC_LONG(data.count), &digest)
}
return digest.map { String(format: "%02x", $0) }.joined()
}
```swift
// Given a string 'text', return its md5 hash equivalent string.
// If 'text' is an empty string, return nil.
// stringToMd5(text: "Hello world") == "3e25960a79dbc69b674cd4ec67a72c62"
func stringToMd5(text: String) -> String? {
guard!text.isEmpty else { return nil }
let data = text.data(using:.utf8)!
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
data.withUnsafeBytes {
_ = CC_MD5($0, CC_LONG(data.count), &digest)
}
return digest.map { String(format: "%02x", $0) }.joined()
}
```
guard!text.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
data.withUnsafeBytes { // 'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R` instead
_ = CC_MD5($0, CC_LONG(data.count), &digest) // 'CC_MD5' was deprecated in macOS 10.15: This function is cryptographically broken and should not be used in security contexts. Clients should migrate to SHA256 (or stronger).
import CommonCrypto
func stringToMd5(text: String) -> String? {
guard!text.isEmpty else { return nil }
let data = text.data(using:.utf8)!
let hash = data.withUnsafeBytes { (bytes: UnsafeRawBufferPointer) -> [UInt8] in
var hash = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
CC_MD5(bytes.baseAddress, CC_LONG(data.count), &hash)
return hash
}
return hash.map { String(format: "%02x", $0) }.joined()
}
```swift
// Given a string 'text', return its md5 hash equivalent string.
// If 'text' is an empty string, return nil.
// stringToMd5(text: "Hello world") == "3e25960a79dbc69b674cd4ec67a72c62"
func stringToMd5(text: String) -> String? {
guard!text.isEmpty else { return nil }
let data = text.data(using:.utf8)!
let hash = data.withUnsafeBytes { (bytes: UnsafeRawBufferPointer) -> [UInt8] in
var hash = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
CC_MD5(bytes.baseAddress, CC_LONG(data.count), &hash)
return hash
}
return hash.map { String(format: "%02x", $0) }.joined()
}
```
guard!text.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
CC_MD5(bytes.baseAddress, CC_LONG(data.count), &hash) // 'CC_MD5' was deprecated in macOS 10.15: This function is cryptographically broken and should not be used in security contexts. Clients should migrate to SHA256 (or stronger).
import CommonCrypto
func stringToMd5(text: String) -> String? {
guard!text.isEmpty else { return nil }
let data = text.data(using:.utf8)!
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
data.withUnsafeBytes {
_ = CC_MD5($0, CC_LONG(data.count), &digest)
}
return digest.map { String(format: "%02x", $0) }.joined()
}
```swift
// Given a string 'text', return its md5 hash equivalent string.
// If 'text' is an empty string, return nil.
// stringToMd5(text: "Hello world") == "3e25960a79dbc69b674cd4ec67a72c62"
func stringToMd5(text: String) -> String? {
guard!text.isEmpty else { return nil }
let data = text.data(using:.utf8)!
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
data.withUnsafeBytes {
_ = CC_MD5($0, CC_LONG(data.count), &digest)
}
return digest.map { String(format: "%02x", $0) }.joined()
}
```
guard!text.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
data.withUnsafeBytes { // 'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R` instead
_ = CC_MD5($0, CC_LONG(data.count), &digest) // 'CC_MD5' was deprecated in macOS 10.15: This function is cryptographically broken and should not be used in security contexts. Clients should migrate to SHA256 (or stronger).
import CommonCrypto
func stringToMd5(text: String) -> String? {
guard!text.isEmpty else { return nil }
let data = text.data(using:.utf8)!
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
data.withUnsafeBytes {
_ = CC_MD5($0, CC_LONG(data.count), &digest)
}
return digest.map { String(format: "%02x", $0) }.joined()
}
```swift
// Given a string 'text', return its md5 hash equivalent string.
// If 'text' is an empty string, return nil.
// stringToMd5(text: "Hello world") == "3e25960a79dbc69b674cd4ec67a72c62"
func stringToMd5(text: String) -> String? {
guard!text.isEmpty else { return nil }
let data = text.data(using:.utf8)!
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
data.withUnsafeBytes {
_ = CC_MD5($0, CC_LONG(data.count), &digest)
}
return digest.map { String(format: "%02x", $0) }.joined()
}
```
guard!text.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
data.withUnsafeBytes { // 'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R` instead
_ = CC_MD5($0, CC_LONG(data.count), &digest) // 'CC_MD5' was deprecated in macOS 10.15: This function is cryptographically broken and should not be used in security contexts. Clients should migrate to SHA256 (or stronger).
import CommonCrypto
func stringToMd5(text: String) -> String? {
guard!text.isEmpty else { return nil }
let data = text.data(using:.utf8)!
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
data.withUnsafeBytes {
_ = CC_MD5($0, CC_LONG(data.count), &digest)
}
return digest.map { String(format: "%02x", $0) }.joined()
}
```swift
// Given a string 'text', return its md5 hash equivalent string.
// If 'text' is an empty string, return nil.
// stringToMd5(text: "Hello world") == "3e25960a79dbc69b674cd4ec67a72c62"
func stringToMd5(text: String) -> String? {
guard!text.isEmpty else { return nil }
let data = text.data(using:.utf8)!
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
data.withUnsafeBytes {
_ = CC_MD5($0, CC_LONG(data.count), &digest)
}
return digest.map { String(format: "%02x", $0) }.joined()
}
```
guard!text.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
data.withUnsafeBytes { // 'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R` instead
_ = CC_MD5($0, CC_LONG(data.count), &digest) // 'CC_MD5' was deprecated in macOS 10.15: This function is cryptographically broken and should not be used in security contexts. Clients should migrate to SHA256 (or stronger).
import CommonCrypto
func stringToMd5(text: String) -> String? {
guard!text.isEmpty else { return nil }
let data = text.data(using:.utf8)!
let hash = data.withUnsafeBytes { (bytes: UnsafeRawBufferPointer) -> [UInt8] in
var hash = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
CC_MD5(bytes.baseAddress, CC_LONG(data.count), &hash)
return hash
}
return hash.map { String(format: "%02x", $0) }.joined()
}
```swift
// Given a string 'text', return its md5 hash equivalent string.
// If 'text' is an empty string, return nil.
// stringToMd5(text: "Hello world") == "3e25960a79dbc69b674cd4ec67a72c62"
func stringToMd5(text: String) -> String? {
guard!text.isEmpty else { return nil }
let data = text.data(using:.utf8)!
let hash = data.withUnsafeBytes { (bytes: UnsafeRawBufferPointer) -> [UInt8] in
var hash = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
CC_MD5(bytes.baseAddress, CC_LONG(data.count), &hash)
return hash
}
return hash.map { String(format: "%02x", $0) }.joined()
}
```
guard!text.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
CC_MD5(bytes.baseAddress, CC_LONG(data.count), &hash) // 'CC_MD5' was deprecated in macOS 10.15: This function is cryptographically broken and should not be used in security contexts. Clients should migrate to SHA256 (or stronger).
func generateIntegers(a: Int, b: Int) -> [Int] {
var result = [Int]()
for i in a...b {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```swift
// Given two positive integers a and b, return the even digits between a
// and b, in ascending order.
// For example:
// generateIntegers(a: 2, b: 8) == [2, 4, 6, 8]
// generateIntegers(a: 8, b: 2) == [2, 4, 6, 8]
// generateIntegers(a: 10, b: 14) == [] as [Int]
func generateIntegers(a: Int, b: Int) -> [Int] {
var result = [Int]()
for i in a...b {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```
// Fatal error: Range requires lowerBound <= upperBound
func generateIntegers(a: Int, b: Int) -> [Int] {
var result: [Int] = []
for i in a...b {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```swift
// Given two positive integers a and b, return the even digits between a
// and b, in ascending order.
// For example:
// generateIntegers(a: 2, b: 8) == [2, 4, 6, 8]
// generateIntegers(a: 8, b: 2) == [2, 4, 6, 8]
// generateIntegers(a: 10, b: 14) == [] as [Int]
func generateIntegers(a: Int, b: Int) -> [Int] {
var result: [Int] = []
for i in a...b {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```
// Fatal error: Range requires lowerBound <= upperBound
func generateIntegers(a: Int, b: Int) -> [Int] {
var result = [Int]()
for i in a...b {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```swift
// Given two positive integers a and b, return the even digits between a
// and b, in ascending order.
// For example:
// generateIntegers(a: 2, b: 8) == [2, 4, 6, 8]
// generateIntegers(a: 8, b: 2) == [2, 4, 6, 8]
// generateIntegers(a: 10, b: 14) == [] as [Int]
func generateIntegers(a: Int, b: Int) -> [Int] {
var result = [Int]()
for i in a...b {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```
// Fatal error: Range requires lowerBound <= upperBound
func generateIntegers(a: Int, b: Int) -> [Int] {
var result: [Int] = []
for i in a...b {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```swift
// Given two positive integers a and b, return the even digits between a
// and b, in ascending order.
// For example:
// generateIntegers(a: 2, b: 8) == [2, 4, 6, 8]
// generateIntegers(a: 8, b: 2) == [2, 4, 6, 8]
// generateIntegers(a: 10, b: 14) == [] as [Int]
func generateIntegers(a: Int, b: Int) -> [Int] {
var result: [Int] = []
for i in a...b {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```
// Fatal error: Range requires lowerBound <= upperBound
func generateIntegers(a: Int, b: Int) -> [Int] {
var result: [Int] = []
if a > b {
for i in a...b {
if i % 2 == 0 {
result.append(i)
}
}
} else {
for i in b...a {
if i % 2 == 0 {
result.append(i)
}
}
}
return result
}
```swift
// Given two positive integers a and b, return the even digits between a
// and b, in ascending order.
// For example:
// generateIntegers(a: 2, b: 8) == [2, 4, 6, 8]
// generateIntegers(a: 8, b: 2) == [2, 4, 6, 8]
// generateIntegers(a: 10, b: 14) == [] as [Int]
func generateIntegers(a: Int, b: Int) -> [Int] {
var result: [Int] = []
if a > b {
for i in a...b {
if i % 2 == 0 {
result.append(i)
}
}
} else {
for i in b...a {
if i % 2 == 0 {
result.append(i)
}
}
}
return result
}
```
// Fatal error: Range requires lowerBound <= upperBound
func generateIntegers(a: Int, b: Int) -> [Int] {
var result = [Int]()
for i in a...b {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```swift
// Given two positive integers a and b, return the even digits between a
// and b, in ascending order.
// For example:
// generateIntegers(a: 2, b: 8) == [2, 4, 6, 8]
// generateIntegers(a: 8, b: 2) == [2, 4, 6, 8]
// generateIntegers(a: 10, b: 14) == [] as [Int]
func generateIntegers(a: Int, b: Int) -> [Int] {
var result = [Int]()
for i in a...b {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```
// Fatal error: Range requires lowerBound <= upperBound
func generateIntegers(a: Int, b: Int) -> [Int] {
var result = [Int]()
for i in a...b {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```swift
// Given two positive integers a and b, return the even digits between a
// and b, in ascending order.
// For example:
// generateIntegers(a: 2, b: 8) == [2, 4, 6, 8]
// generateIntegers(a: 8, b: 2) == [2, 4, 6, 8]
// generateIntegers(a: 10, b: 14) == [] as [Int]
func generateIntegers(a: Int, b: Int) -> [Int] {
var result = [Int]()
for i in a...b {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```
// Fatal error: Range requires lowerBound <= upperBound
func generateIntegers(a: Int, b: Int) -> [Int] {
var result = [Int]()
for i in a...b {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```swift
// Given two positive integers a and b, return the even digits between a
// and b, in ascending order.
// For example:
// generateIntegers(a: 2, b: 8) == [2, 4, 6, 8]
// generateIntegers(a: 8, b: 2) == [2, 4, 6, 8]
// generateIntegers(a: 10, b: 14) == [] as [Int]
func generateIntegers(a: Int, b: Int) -> [Int] {
var result = [Int]()
for i in a...b {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```
// Fatal error: Range requires lowerBound <= upperBound
func generateIntegers(a: Int, b: Int) -> [Int] {
var result = [Int]()
for i in a...b {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```swift
// Given two positive integers a and b, return the even digits between a
// and b, in ascending order.
// For example:
// generateIntegers(a: 2, b: 8) == [2, 4, 6, 8]
// generateIntegers(a: 8, b: 2) == [2, 4, 6, 8]
// generateIntegers(a: 10, b: 14) == [] as [Int]
func generateIntegers(a: Int, b: Int) -> [Int] {
var result = [Int]()
for i in a...b {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```
// Fatal error: Range requires lowerBound <= upperBound
func generateIntegers(a: Int, b: Int) -> [Int] {
var result = [Int]()
for i in a...b {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```swift
// Given two positive integers a and b, return the even digits between a
// and b, in ascending order.
// For example:
// generateIntegers(a: 2, b: 8) == [2, 4, 6, 8]
// generateIntegers(a: 8, b: 2) == [2, 4, 6, 8]
// generateIntegers(a: 10, b: 14) == [] as [Int]
func generateIntegers(a: Int, b: Int) -> [Int] {
var result = [Int]()
for i in a...b {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```
// Fatal error: Range requires lowerBound <= upperBound