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 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 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 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
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
import Foundation | |
func max(a: Int, b: Int) -> Int { | |
return a > b ? a : b | |
} | |
func necklace(pearls: [[Int]]) -> [[Int]] { | |
var res = Array.init(repeating: Array.init(repeating: 0, count: 151), count: pearls.count) | |
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
import Foundation | |
func min(array: [Int]) -> Int { | |
var ret = Int.max; | |
for i in 0...array.count - 1 { | |
if array[i] < ret { | |
ret = array[i] | |
} | |
} |
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 calcNoise(standingOn: Character) -> Int { | |
switch standingOn { | |
case "A": | |
return 1 | |
case "S": | |
return 3 | |
case "H": | |
return 5 |
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 max(a: Int, b: Int) -> Int { | |
return a > b ? a : b | |
} | |
// Assume this one works just fine, since I copied it | |
func pedritoBt(markers: Int, floors: Int) -> Int { | |
if floors <= 1 { | |
return floors |
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 | |
// Returns true iif a in contained by b :) | |
// This is a modification of the longest common subsequence problem | |
func contains(a: [String], b: [String]) -> Bool { | |
var res: [[Int]] = Array.init(repeating: Array.init(repeating: 0, count: b.count), count: a.count) | |
for i in 0...a.count - 1 { | |
for j in 0...b.count - 1 { | |
if a[i] == b[j] { |