为程序员的爱情点赞

jopen 10年前

为程序员的爱情点赞

        程序员的爱简单实用,就像他们的代码,过程虽不同,也曾抛出异常,但都是 happy ending。当情人节遇上元宵节,run 爱情密码程序并转发本文至微信朋友圈,就能为你及好友带来爱情蜜运。

        下面的程序代表程序员的爱情密码,不浮夸,简单实用。来吧,进入:http://play.golang.org/p/xl1P6jYtIZ

 package main    import (      "fmt" "math/rand" "time"  )    func main () {      msg := make (chan string)      end := make (chan string)      go girlStory (msg, end)      go boyStory (msg, end)      fmt.Println (<- end)    }    func boyStory (msg, end chan string) {      sendMsg ("boy", "girl", "hi!", "happy", msg)      for {          switch m := <- msg; {          case m == "hi!": sendMsg ("boy", "girl", "hi!", "miss", msg)          case m == "...": sendMsg ("boy", "girl", "hi!", "angry", msg)          case m == "hi~": sendMsg ("boy", "girl", "a u happy?", "exciting", msg)          case m == "yes, i am happy": sendMsg ("boy", "girl", "ok,nice", "so sad", msg)          case m == "i am lonely...": sendMsg ("boy", "girl", "be my love?", "exciting!", msg)          case m == "ok, why not": end <- "---May happy ending of love belong to every developer. ---"          }          time.Sleep (time.Duration (1e9))      }  }    func girlStory (msg, end chan string) {      rand.Seed (time.Now () .UnixNano ())      for {          happy := rand.Intn (5) < 3          alone := rand.Intn (5) == 0 switch m := <- msg; {          case m == "hi!":              if happy {                  sendMsg ("girl", "boy", "hi~", "happy", msg)              } else {                  sendMsg ("girl", "boy", "hi!", "sad", msg)              }          case m == "a u happy?":              if !happy &&  alone {                  sendMsg ("girl", "boy", "i am lonely...", "sad", msg)              } else if !happy {                  sendMsg ("girl", "boy", "...", "sad", msg)              } else {                  sendMsg ("girl", "boy", "yes, i am happy", "happy", msg)              }          case m == "ok,nice":              sendMsg ("girl", "boy", "...", "-_-", msg)          case m == "be my love?":              sendMsg ("girl", "boy", "ok, why not", "happy", msg)          }          time.Sleep (time.Duration (1e9))      }  }    func sendMsg (from, to, body, feeling string, msg chan string) {      fmt.Println (from, "(", feeling, "): ", body)      msg <- body  }

        点击 run 按钮,祝你们爱情甜蜜~~(还有爱情程序文档详细说明哦)

        boy ( happy ):  hi!

        girl ( happy ):  hi~

        boy ( exciting ):  a u happy?

        girl ( happy ):  yes, i am happy

        boy ( so sad ):  ok,nice

        girl ( -_- ):  ...

        boy ( angry ):  hi!

        girl ( sad ):  hi!

        boy ( miss ):  hi!

        girl ( sad ):  hi!

        boy ( miss ):  hi!

        girl ( happy ):  hi~

        boy ( exciting ):  a u happy?

        girl ( sad ):  i am lonely...

        boy ( exciting! ):  be my love?

        girl ( happy ):  ok, why not

        ---May happy ending of love belong to every developer. ---

131320321656074.jpg

为程序员的爱情点赞