我认为,我经常需要以特别的方式处理顺序的最后部分。 例如,采用<代码>interpose:
> (interpose ", " (range 4))
(0 ", " 1 ", " 2 ", " 3)
一种思维方式是:
- Take the first element, add ", "
- Take the second element, add ", "
- Take the third element, add ", "
- ...
- Take the second to last element, add ", "
- Take the last element and do nothing
我还发现,在利用种子建造米格布局时,我需要做一些特殊的工作。 例如,我要说的是:
+---+---+---+
| 1 | 2 | 3 |
+---+---+---+
| 4 | 5 | 6 |
+---+---+---+
| 7 | 8 | 9 |
+---+---+---+
每一数字都是部分(如纽伦)。 我可以这样做,对整个小组的“流量”作出“临时”限制,然后对每个构成部分增加以下限制:
- "grow" - components 1, 2, 4, 5, 7, 8, 9
- "grow, wrap" - components 3, 6
Note that the above can be said like this:
- "grow" for each component except the last component in the row
- "grow, wrap" for all other components except the last component in the last row
同一“特殊最后要素”主题再次出现。
因此有两个问题:
- Does the above reasoning make sense? I.e. should I change the design fundamentally and think about this in a different way given the above sample problems and the general theme?
- If not, is there an idiomatic and short way to do this?
是的,你可以发挥帮助作用和采取宏观措施,但我发现,这往往足以使我倾向于认为它应当是上述之一。 换言之,你是否属于同样类型的“问题”,以及你如何解决这些问题?