Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,58 @@
' version 21-10-2016
' compile with: fbc -s console
' compile with: fbc -s console -exx (for bondry check on the array's)
' not very well suited for large numbers and large array's
' positive numbers only
Sub sandman(sleepy() As ULong)
Dim As Long lb = LBound(sleepy)
Dim As Long ub = UBound(sleepy)
Dim As Long i, count = ub
Dim As Double wakeup(lb To ub)
Dim As Double t = Timer
For i = lb To ub
wakeup(i) = sleepy(i) +1 + t
Next
Do
t = Timer
For i = lb To ub
If wakeup(i) <= t Then
Print Using "####";sleepy(i);
wakeup(i) = 1e9 ' mark it as used
count = count -1
End If
Next
Sleep (1 - (Timer - t)) * 300, 1 ' reduce CPU load
Loop Until count < lb
End Sub
' ------=< MAIN >=------
Dim As ULong i, arr(10)
Dim As ULong lb = LBound(arr)
Dim As ULong ub = UBound(arr)
Randomize Timer
For i = lb To ub -1 ' leave last one zero
arr(i) = Int(Rnd * 10) +1
Next
Print "unsorted ";
For i = lb To ub
Print Using "####";arr(i);
Next
Print : Print
Print " sorted ";
sandman(arr())
Print : Print
' empty keyboard buffer
While InKey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End

View file

@ -0,0 +1,13 @@
import os, strutils
proc single(n: int) =
sleep n
echo n
proc main =
var thr = newSeq[TThread[int]](paramCount())
for i,c in commandLineParams():
thr[i].createThread(single, c.parseInt)
thr.joinThreads
main()

View file

@ -0,0 +1,7 @@
import: parallel
: sleepSort(l)
| ch n |
Channel new ->ch
l forEach: n [ #[ n dup 20 * sleep ch send drop ] & ]
ListBuffer newSize(l size) #[ ch receive over add ] times(l size) ;

View file

@ -0,0 +1,29 @@
integer count
procedure sleeper(integer key)
? key
count -= 1
end procedure
sequence s, val
atom task
s = command_line()
s = s[3..$]
if length(s)=0 then
puts(1,"Nothing to sort.\n")
else
count = 0
for i = 1 to length(s) do
val = value(s[i])
if val[1] = GET_SUCCESS then
task = task_create(routine_id("sleeper"),{val[2]})
task_schedule(task,{val[2],val[2]}/10)
count += 1
end if
end for
while count do
task_yield()
end while
end if

View file

@ -0,0 +1,3 @@
ARGV.map{.to_i}.map{ |i|
{Sys.sleep(i); say i}.fork;
}.each{.wait};

View file

@ -0,0 +1,12 @@
import Foundation
for i in [5, 2, 4, 6, 1, 7, 20, 14] {
let time = dispatch_time(DISPATCH_TIME_NOW,
Int64(i * Int(NSEC_PER_SEC)))
dispatch_after(time, dispatch_get_main_queue()) {
print(i)
}
}
CFRunLoopRun()

View file

@ -0,0 +1,11 @@
echo '[5, 1, 3, 2, 11, 6, 4]' | jq '
def f:
if .unsorted == [] then
.sorted
else
{ unsorted: [.unsorted[] | .t = .t - 1 | select(.t != 0)]
, sorted: (.sorted + [.unsorted[] | .t = .t - 1 | select(.t == 0) | .v]) }
| f
end;
{unsorted: [.[] | {v: ., t: .}], sorted: []} | f | .[]
'