本帖最后由 孤星11 于 2022-11-17 15:37 编辑
没有啦,我没有常去的基础代码网站,前天我只是借用你的题目在马来西亚最大英文论坛发问,结果引来两位程序员作答。
从148楼看起吧,Fraus是我的最新用户名之一(我有很多用户名在那里,嘿嘿):
https://forum.lowyat.net/index.p ... indpost&p=105847346
这个代码是那个最后图案的:
Go Playground - The Go Programming Language
- package main
- import (
- "fmt"
- "strings"
- )
- func cell(cells []byte, rule int) {
- t := [8]byte{}
- for i := 0; i < 8; i++ {
- switch rule & 1 {
- case 0:
- t[i] = ' '
- case 1:
- t[i] = 'X'
- }
- rule >>= 1
- }
- for row := 0; row < 100; row++ {
- fmt.Println(string(cells))
- state := 0
- if cells[0] == 'X' {
- state = 1
- }
- for i := 1; i < len(cells); i++ {
- state = (state << 1) & 7
- if cells[i] == 'X' {
- state = state | 1
- }
- cells[i-1] = t[state]
- }
- state = (state << 1) & 7
- cells[len(cells)-1] = t[state]
- }
- }
- func main() {
- buf := []byte(strings.Repeat(" ", 120))
- // single X in the middle
- buf[len(buf)/2] = 'X'
- cell(buf, 18) // 18 = 00010010 binary
- }
复制代码
|