June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,27 @@
import extensions.
import system'routines.
import extensions'threading.
extension $op
{
sleepSort
[
self forEach(:n)
[
threadControl start:
[
var a := 1000 * n.
threadControl sleep(1000 * n).
console printLine(n).
].
]
]
}
program =
[
'program'arguments skipping:1; selectBy(%"convertorOp.toInt"); toArray; sleepSort.
console readChar.
].

View file

@ -1,12 +1,14 @@
input = [3,2,4,7,3,6,9,1]
output = Int[]
@sync for i in input
@async begin
sleep(i)
push!(output, i)
function sleepsort(arr::Vector{<:Real})
out = Vector{eltype(arr)}(0)
sizehint!(out, length(arr))
@sync for x in arr
@async begin
sleep(x)
push!(out, x)
end
end
return out
end
@assert output == sort(input)
println(output)
v = rand(-10:10, 10)
println("# unordered: $v\n -> ordered: ", sleepsort(v))

View file

@ -0,0 +1,23 @@
// version 1.1.51
import kotlin.concurrent.thread
fun sleepSort(list: List<Int>, interval: Long) {
print("Sorted : ")
for (i in list) {
thread {
Thread.sleep(i * interval)
print("$i ")
}
}
thread { // print a new line after displaying sorted list
Thread.sleep ((1 + list.max()!!) * interval)
println()
}
}
fun main(args: Array<String>) {
val list = args.map { it.toInt() }.filter { it >= 0 } // ignore negative integers
println("Unsorted: ${list.joinToString(" ")}")
sleepSort(list, 50)
}