我正在寻找一个具有两个输入值和一个输出值的算法,并遵循以下模式:
输入_A:10 (当INPUT_B以非常小的步长从0增加到1时,它应该达到值' 1' 100 / 10 = 10次。)
Input_B => Output
0.025 => 0.25
...
0.05 => 0.50
...
0.075 => 0.75
...
0.1 => 1.00
...
0.125 => 0.25
...
0.15 => 0.50
...
0.175 => 0.75
...
0.2 => 1.00
....
0.9 => 1.00
....
0.95 => 0.50
...
输入_A:20 (当INPUT_B以非常小的步长从0增加到1时,它应该达到值' 1' 100 / 20 = 5次。)
Input_B => Output
0.025 => 0.50
...
0.05 => 1.00
...
0.075 => 0.50
...
0.1 => 1.00
...
0.125 => 0.50
...
0.15 => 1.00
...
0.175 => 0.50
...
0.2 => 1.00
....
0.9 => 1.00
....
0.9125 => 0.25
...
0.925 => 0.50
...
0.95 => 1.00
...
我想我设法创建了一个遵循第一个模式的算法。但我无法找到一个跟随两者的人。
myAlgorithm(Input_A,Input_B) {
return (Input_B && Input_B%0.1 == 0) ? 1 : Input_B%0.1 * Input_A;
}
答案 0 :(得分:1)
看来你需要这样的东西:
func readPropertyList() {
var propertyListForamt = PropertyListSerialization.PropertyListFormat.xml //Format of the Property List.
var plistData: [String: AnyObject] = [:] //Our data
let plistPath: String? = Bundle.main.path(forResource: "data", ofType: "plist")! //the path of the data
let plistXML = FileManager.default.contents(atPath: plistPath!)!
do {//convert the data to a dictionary and handle errors.
plistData = try PropertyListSerialization.propertyList(from: plistXML, options: .mutableContainersAndLeaves, format: &propertyListForamt) as! [String:AnyObject]
} catch {
print("Error reading plist: \(error), format: \(propertyListForamt)")
}
}