• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Vectors SleepSort

a guest Jun 1st, 2019 131 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. /*Sleep sort of vectors by length example*/
2.
3. //functional programming
4. sleepSort([i32] arr) =
5.   result = []
6.   threadsArr = map(arr, (elem, index) => (
7.     sleepFunc =
8.       sleep(elem)
9.       printfn("threadsArr[%i32] have slept for %i32", index, elem)
11.   ))
13.   result
14.
15. //object orientated and generic programming
16. type vec3<T : INumeric> =
17.   record
18.     T x
19.     T y
20.     T z
21.     vec3<T>(xi, yi, zi) =
22.       x = xi
23.       y = yi
24.       z = zi
25.     normalize() =
26.       len = math.sqrt(x*x + y*y + z*z)
27.       vec3<T>(x/len, y/len, z/len)
28.     print() =
29.       printfn("vector: x: %s y: %s z: %s", str(x), str(y), str(z))
31.       //semicolons are compulsory when write code in one line
32.       xs = ""; ys = ""; zs = "";
33.       scanf("vector: x: %s y: %s z: %s", xs, ys, zs, () => (print("Scanf error")))
34.       x = T(xs); y = T(ys); z = T(zs)
35.     operator implicit int():
36.       return floor(
37.           len = f32(math.sqrt(x*x + y*y + z*z))
38.           len
39.       )
40. main(argc, argv) =
41.   vectorCount = ""
42.   scanf("%i32", vectorCount)
43.   arr = [vec3<T>(0, 0, 0)] * vectorCount
44.   for vector in arr: