k.go 325 B

12345678910111213141516171819202122
  1. package kata
  2. /*
  3. Paperfold implements the general paperfold generation (OEIS A0014577) based
  4. on the algorithm given by Joerg Arndt, Apr 15 2010.
  5. See https://oeis.org/A014577
  6. */
  7. func PaperFold(ch chan<- int) {
  8. i := 1
  9. for {
  10. k := i
  11. h := k & -k
  12. k &= h << 1
  13. if k == 0 {
  14. ch <- 1
  15. } else {
  16. ch <- 0
  17. }
  18. i++
  19. }
  20. }