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,30 @@
class PriorityQueue {
has tasks = []
method insert (Number priority { _ >= 0 }, task) {
for n in range(tasks.len, priority) {
tasks[n] = []
}
tasks[priority].append(task)
}
method get { tasks.first { !.is_empty } -> shift }
method is_empty { tasks.all { .is_empty } }
}
var pq = PriorityQueue()
[
[3, 'Clear drains'],
[4, 'Feed cat'],
[5, 'Make tea'],
[9, 'Sleep'],
[3, 'Check email'],
[1, 'Solve RC tasks'],
[9, 'Exercise'],
[2, 'Do taxes'],
].each { |pair|
pq.insert(pair...)
}
say pq.get while !pq.is_empty