2024-10-01 03:50:04 -06:00
|
|
|
// run
|
2024-09-18 09:39:05 -06:00
|
|
|
|
|
|
|
// Copyright 2024 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"iter"
|
|
|
|
)
|
|
|
|
|
2024-09-25 12:37:07 -06:00
|
|
|
func All() iter.Seq[int] {
|
|
|
|
return func(yield func(int) bool) {
|
|
|
|
for i := 0; i < 10; i++ {
|
2024-10-01 03:50:04 -06:00
|
|
|
growStack(512)
|
2024-09-25 12:37:07 -06:00
|
|
|
if !yield(i) {
|
2024-09-18 09:39:05 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-25 12:37:07 -06:00
|
|
|
type S struct {
|
|
|
|
round int
|
2024-09-18 09:39:05 -06:00
|
|
|
}
|
|
|
|
|
2024-09-25 12:37:07 -06:00
|
|
|
func NewS(round int) *S {
|
|
|
|
s := &S{round: round}
|
|
|
|
return s
|
2024-09-18 09:39:05 -06:00
|
|
|
}
|
|
|
|
|
2024-09-25 12:37:07 -06:00
|
|
|
func (s *S) check(round int) {
|
|
|
|
if s.round != round {
|
|
|
|
panic("bad round")
|
2024-09-18 09:39:05 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-25 12:37:07 -06:00
|
|
|
func f() {
|
2024-09-18 09:39:05 -06:00
|
|
|
rounds := 0
|
2024-09-25 12:37:07 -06:00
|
|
|
s := NewS(rounds)
|
|
|
|
s.check(rounds)
|
2024-09-18 09:39:05 -06:00
|
|
|
|
2024-09-25 12:37:07 -06:00
|
|
|
for range All() {
|
|
|
|
s.check(rounds)
|
|
|
|
rounds++
|
|
|
|
s = NewS(rounds)
|
|
|
|
s.check(rounds)
|
2024-09-18 09:39:05 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-01 03:50:04 -06:00
|
|
|
func growStack(i int) {
|
|
|
|
if i == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
growStack(i - 1)
|
|
|
|
}
|
|
|
|
|
2024-09-18 09:39:05 -06:00
|
|
|
func main() {
|
2024-09-25 12:37:07 -06:00
|
|
|
f()
|
2024-09-18 09:39:05 -06:00
|
|
|
}
|