This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func min(a: Int, b: Int) -> Int { | |
return a < b ? a : b | |
} | |
func adjacentSpots(board: [[Int]], start: [Int]) -> [[Int]] { | |
let i = start[0] | |
let j = start[1] | |
var ret: [[Int]] = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task type Semaphore is | |
entry Init (Initial_Capacity: in Int); | |
entry Wait; | |
entry Signal; | |
end | |
task body Semaphore is | |
Remaining_Capacity: Int; | |
begin | |
accept Init (Initial_Capacity: in Int) do | |
Remaining_Capacity := Initial_Capacity; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task Readers_Writers is | |
procedure Reader (Read: out Int); | |
entry Writer (Written: in Int); | |
entry Begin_Reading; | |
entry Finish_Reading; | |
end | |
procedure Reader (Read: out Int) is | |
begin | |
Begin_Reading; | |
Read := Shared; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task Readers_Writers is | |
procedure Reader (Read: out Int); | |
entry Writer (Written: in Int); | |
entry Begin_Reading; | |
entry Finish_Reading; | |
end; | |
procedure Reader (Read: out Int) is | |
begin | |
Begin_Reading; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task Buffer is | |
entry Insert (In_Val: in T); | |
entry Extract (Out_Val: out T); | |
end | |
task body Buffer is | |
Data: Array 0..N-1 of Int; | |
Top: Int; | |
Bottom: Int; | |
Length: Int; | |
x: T; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task Alice is | |
end | |
task body Alice is | |
begin | |
loop | |
Yard.Request; | |
Walk_Dog; | |
Yard.Release; | |
end loop | |
end Alice; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Philosophers: Array 0..4 of Philosopher; | |
task type Philosopher is | |
end | |
task body Philosopher is | |
begin | |
loop | |
Table.Enter | |
Chopsticks.Request | |
Chopsticks.Request |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Chopsticks: Array 0..4 of Chopstick; | |
Philosophers: Array 0..4 of Philosopher; | |
task type Philosopher is | |
end | |
task body Philosopher is | |
Left: Int; | |
Enumerator.Gimme_My_Number(Left); | |
Right: Int := (Left + 1) mod 5; | |
begin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class Condition { | |
var waiting: Bool | |
init() { | |
waiting = false | |
} | |
func wait() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class Semaphore { | |
var n: Int | |
init(n: Int) { | |
self.n = n | |
} | |
func P() { |