快乐周末:“最二的 Go 语言程序”竞赛
by xslidian
at 2012-06-27 23:16:45
original http://www.guao.hk/posts/the-most-2ed-go-contest.html
Go-Nuts 群组有人发起了“最傻的 Go 语言代码”竞赛。你的程序能比下面的更具魅力吗?
点击标题可查看执行效果和进行在线调试。
1、LOL
func main() { var LOL bool fmt.Println(!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!LOL) }
func мир(ы interface{}){ fmt.Println(ы) } func Ґудзик(){if привет := recover(); привет != nil {мир(привет)}} func main() { defer Ґудзик() こんにちは := make(chan string) 你好 := make(chan string) go func(){ 你好 <- <- こんにちは }() go func(){ こんにちは <- "world" }() go func(){ мир("Hello") }() panic(<- 你好) }
3、求助信
Dear gc,
I hope you are well. I regret that we haven't spoken for a while, but I have been busy preparing for Google I/O.
I am writing to ask a favor. Would you mind emitting the standard "Hello, world" program? It would be a big help.
Keep up the good work.
Your pal, Andrew
func main() { fmt.Println("H!dlrow ,olle") }
package main import ( "fmt" "strings" )
type char string
func main() { print(H,E,L,L,O, SPACE, W, O, R, L, D) }
func print(chars ...char) { // print ascciart character line by line lblChar := make([][]string, len(chars)) maxSplit := 0 for i := 0; i < len(chars); i++ { lblChar[i] = strings.Split(string(chars[i]), "\n") maxSplit = max(maxSplit, len(lblChar[i])) } for line := 0; line < maxSplit; line++ { for i := 0; i < len(lblChar); i++ { if line < len(lblChar[i]) { fmt.Print(lblChar[i][line]) } } fmt.Println() } }
func max(i, j int) int{ if i > j { return i } return j }
const ( H char = ` _ _ | | | | | |_| | | _ | | | | | |_| |_| ` E char = ` ___ | _| | |_ | _| | |_ |___| ` L char = ` _ | | | | | | | |_ |___| `
O char = ` _____ | _ | | | | | | | | | | |_| | |_____| ` SPACE char = `
` R char = ` _____ | _ | | |_| | | _ | | | \ \ |_| \_\ ` W char = ` __ __ \ \ / / \ \ /\ / / \ \/ \/ / \ / \____/ ` D char = ` ____ | _ \ | | | | | | | | | |_| | |____/ `
)
© xslidian 发表于 谷奥——探寻谷歌的奥秘 ( http://www.guao.hk ), 2012. |
1 条评论 |
永久链接 |
关于谷奥 |
投稿/爆料
Post tags: fun, Go