add new solutions

This commit is contained in:
Yiyang Kang 2026-02-01 14:56:08 +09:00
parent 67cad91898
commit 51975f3386
Signed by: kkyy
SSH key fingerprint: SHA256:lJSbAzC3MvrSORdvIVK6h/3g+rVKJNzM7zq0MgA9WKY
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{}{}
}
}