add new solutions
This commit is contained in:
parent
67cad91898
commit
81cc2d3ba6
19 changed files with 693 additions and 14 deletions
38
solutions/11/q1117/solution.go
Normal file
38
solutions/11/q1117/solution.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package q1117
|
||||
|
||||
type void struct{}
|
||||
|
||||
type H2O struct {
|
||||
h, o, hRel chan void
|
||||
}
|
||||
|
||||
func NewH2O() *H2O {
|
||||
h := &H2O{
|
||||
h: make(chan void, 2),
|
||||
o: make(chan void, 2),
|
||||
hRel: make(chan void, 2),
|
||||
}
|
||||
h.o <- void{}
|
||||
return h
|
||||
}
|
||||
|
||||
func (h *H2O) Hydrogen(releaseHydrogen func()) {
|
||||
<-h.h
|
||||
// releaseHydrogen() outputs "H". Do not change or remove this line.
|
||||
releaseHydrogen()
|
||||
|
||||
h.hRel <- void{} // confirmation
|
||||
}
|
||||
|
||||
func (h *H2O) Oxygen(releaseOxygen func()) {
|
||||
<-h.o
|
||||
|
||||
// releaseOxygen() outputs "H". Do not change or remove this line.
|
||||
releaseOxygen()
|
||||
|
||||
h.h <- void{}
|
||||
h.h <- void{}
|
||||
<-h.hRel
|
||||
<-h.hRel
|
||||
h.o <- void{}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue