Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,39 @@
import Foundation
infix operator : MultiplicationPrecedence
infix operator × : MultiplicationPrecedence
public struct Vector {
public var x = 0.0
public var y = 0.0
public var z = 0.0
public init(x: Double, y: Double, z: Double) {
(self.x, self.y, self.z) = (x, y, z)
}
public static func (lhs: Vector, rhs: Vector) -> Double {
return lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z
}
public static func × (lhs: Vector, rhs: Vector) -> Vector {
return Vector(
x: lhs.y * rhs.z - lhs.z * rhs.y,
y: lhs.z * rhs.x - lhs.x * rhs.z,
z: lhs.x * rhs.y - lhs.y * rhs.x
)
}
}
let a = Vector(x: 3, y: 4, z: 5)
let b = Vector(x: 4, y: 3, z: 5)
let c = Vector(x: -5, y: -12, z: -13)
print("a: \(a)")
print("b: \(b)")
print("c: \(c)")
print()
print("a • b = \(a b)")
print("a × b = \(a × b)")
print("a • (b × c) = \(a (b × c))")
print("a × (b × c) = \(a × (b × c))")