【发布时间】:2012-12-02 11:03:16
【问题描述】:
我想将整数数组与以下伪模式进行匹配:
其中a 表示这些数字等于或 0(即假设任何数字“等于”0)
[| a; a; a; a; a; |] // matches [| 1; 1; 0; 0; 1 |]
[| a; a; a; not a; a; |] // matches [| 3; 3; 0; 2; 3 |]
[| a; a; not a; a; a; |] // matches [| 4; 4; 2; 0; 4 |]
[| a; not a; a; a; not a; |] // matches [| 1; 2; 0; 0; 3 |]
[| a; a; a; not a; a; |] // matches [| 1; 1; 0; 4; 1 |]
[| not a; a; a; a; a; |] // matches [| 5; 1; 0; 1; 1 |]
我该怎么做?
【问题讨论】:
-
我不太明白
a和not a在这里的含义。你能说得更清楚一点吗?a表示“0 或 1”,not a表示“任何其他数字”吗? -
最终链式 if 语句可能是最快的。有没有真正的理由不放弃匹配语句?
标签: f# pattern-matching