daily pastebin goal
22%
SHARE
TWEET

Untitled

a guest Mar 20th, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. type State [10]int
  6.  
  7. func (s *State) isPrime() bool {
  8.     for i := range s {
  9.         if i > 0 && s[i] > 0 {
  10.             return false
  11.         }
  12.     }
  13.     return true
  14. }
  15.  
  16. func (s *State) isBlank() int {
  17.     t := s[0]
  18.     s[0] = 0
  19.     s[2] += t + 1
  20.     u := s[3]
  21.     s[3] = t - 1
  22.     return u + 1 + 3*t + 2
  23. }
  24.  
  25. func (s *State) iteration() int {
  26.     if s[6] == 0 {
  27.         s[6] = 1
  28.         return s.isBlank()
  29.     }
  30.     if s[2] > 0 && s[3] > 0 {
  31.         t := s[3] + 1
  32.         q := s[2] / t
  33.         u := s[0] + s[2]
  34.         s[0] += q * t
  35.         s[2] -= q * t
  36.         if s[2] == 0 {
  37.             return q*(4*t+2) + s.isBlank() + 1
  38.         }
  39.         v := s[2]
  40.         s[0] = 0
  41.         s[2] = u
  42.         s[3]--
  43.         return q*(4*t+2) + 4*v + 2*u + 2
  44.     }
  45.     t := s[2]
  46.     s[0] += t
  47.     s[2] = 0
  48.     s[6] = 0
  49.     return 6*t + 1
  50. }
  51.  
  52. func fun(n int) string {
  53.     if n == 0 {
  54.         return "⚪"
  55.     } else if n == 1 {
  56.         return "⚫"
  57.     }
  58.     panic(n)
  59. }
  60.  
  61. func main() {
  62.     var s State = [10]int{1, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  63.     index := 0
  64.     for iter := 0; iter < 100000; {
  65.         iter += s.iteration()
  66.         fmt.Printf("%4d: %3d, %3d, %3d, %3d   %s%s%s%s%s%s\n", iter, s[0], s[1], s[2], s[3], fun(s[4]), fun(s[5]), fun(s[6]), fun(s[7]), fun(s[8]), fun(s[9]))
  67.         if s.isPrime() {
  68.             index++
  69.         }
  70.     }
  71. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top