作者contagious (布穀飽吃不堡)
看板Ruby
標題Re: [問題] 一個 State transitions for bollean r …
時間Sun Nov 12 10:59:28 2006
※ 引述《fuha (mimi)》之銘言:
: 小弟現在正在看 programming ruby , 看到一章 expressions 的問題
: 如果有書的人,可以看看 p.327頁
: 書上是要解釋 Ranges in Bollean Expression
: 他也有一個狀態圖可以看 如下
: expr1 is true
: ------------>------ if expr2 is false
: | | --------
: start -> unset -- -- set <-------|
: | | | expr2 is true |
: | | ----<---------------
: |<--|
: expr1 is false
把整個流程寫出來就懂了
: 我的問題是,我怎麼也看不懂他舉的例子..如下
: a = (11..20).collect { |i| (i%4 == 0)..(i%3 == 0) ?i : nil}
11 11%4 != 0 => unset
12 12%4 == 0 => set, output 12, 12%3 == 0 => unset
13 13%4 != 0 => unset
14 14%4 != 0 => unset
15 15%4 != 0 => unset
16 16%4 == 0 => set, output 16, 16%3 != 0 => set
17 output 17, 17%3 != 0 => set
18 output 18, 18%3 == 0 => unset
19 19%4 != 0 => unset
20 20%4 == 0 => set, output 20, 20%3 != 0 => unset
: 與
: a = (11..20).collect { |i| (i%4 == 0)...(i%3 == 0) ?i : nil}
11 11%4 != 0 => unset
12 12%4 == 0 => set, output 12
13 output 13, 13%3 != 0 => set
14 output 14, 14%3 != 0 => set
15 output 15, 15%3 == 0 => unset
16 16%4 == 0 => set, output 16,
17 output 17, 17%3 != 0 => set
18 output 18, 18%3 == 0 => unset
19 19%4 != 0 => unset
20 20%4 == 0 => set, output 20
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.115.161.115
1F:推 godfat:不過我倒是想問,這種在哪裡用得到?一時想不太到 11/12 14:52
2F:→ godfat: ^/機制\ 11/12 14:52
3F:推 fuha:很奇怪的應用.....ˋ(′_‵||)ˊ 11/12 15:03
4F:→ fuha: 說錯了...應該是很奇怪的機制 不過我po的文章裡 推文裡的連 11/12 15:09