내 시도입니다. 놀이터에서 이것을 실행 해보면, 원하는 결과를 얻을 수있을 것입니다. 나는 충분히 깨끗한 것을 만들었 으면 좋겠다. ...
//: Playground - noun: a place where people can play
import Cocoa
let range = Range(uncheckedBounds: (-50, 50))
func generateRandomCouple() -> (a: Int, b: Int) {
// This function will generate a pair of random integers
// (a, b) such that at least a or b is negative.
var first, second: Int
repeat {
first = Int(arc4random_uniform(UInt32(range.upperBound - range.lowerBound))) - range.upperBound
second = Int(arc4random_uniform(UInt32(range.upperBound - range.lowerBound))) - range.upperBound
}
while (first > 0 && second > 0);
// Essentially this loops until at least one of the two is less than zero.
return (first, second)
}
let couple = generateRandomCouple();
print("What is \(couple.a) + (\(couple.b))")
// at this point, either of the variables is negative
// I don't think you can do it in the playground, but here you would read
// her input and the expected answer would, naturally, be:
print(couple.a + couple.b)
어떤 경우라도, 설명을 요청할 수있다. 행운을 빕니다 !
명확한 숫자 조합을 원하십니까? 'a <0'또는 'b <0'중 하나 인 'a + b'조합? –
예. 기본적으로 숫자는 범위 내에서 -50에서 50 사이의 임의 숫자입니다. NumberB는 동일합니다. 그러나 두 개의 양수가 생성되면 음수 (NumberB = NumberB * -1)로 전환해야합니다. –
죄송합니다. 내 의견은 아무 이유없이 계속 전송되었습니다.) –