add new solutions

This commit is contained in:
kanna5 2026-01-27 18:38:43 +09:00
parent 67cad91898
commit eb6ffe8114
No known key found for this signature in database
24 changed files with 933 additions and 14 deletions

View file

@ -0,0 +1,36 @@
package q1115
type FooBar struct {
n int
foo, bar chan struct{}
}
func NewFooBar(n int) *FooBar {
ret := &FooBar{
n: n,
foo: make(chan struct{}, 1),
bar: make(chan struct{}, 1),
}
ret.bar <- struct{}{}
return ret
}
func (fb *FooBar) Foo(printFoo func()) {
for i := 0; i < fb.n; i++ {
<-fb.bar
// printFoo() outputs "foo". Do not change or remove this line.
printFoo()
fb.foo <- struct{}{}
}
}
func (fb *FooBar) Bar(printBar func()) {
for i := 0; i < fb.n; i++ {
<-fb.foo
// printBar() outputs "bar". Do not change or remove this line.
printBar()
fb.bar <- struct{}{}
}
}