-2

I want to take a string of the form "(ABC)(DEF)" and translate adjacent pairs of letters into numbers, interpreting the letters inside parenthesis as cycles. From my example I would want to generate the table:

{{"AB", 1}, {"BC", 2}, {"CA", 3}, {"DE", 4}, {"EF", 5}, {"FD", 6}}

I could do this with a loop, but my limited knowledge of the 'Mathematica Style' of coding suggests that there is a better way to do this in Mathematica. How do I do this the Mathematica way? In general where can I learn about Mathematica style coding?

Edit: Changed my mind. I want to create a function, f, such that f["AB"] = 1, etc. but I don't think this will change the problem much.

4

1 回答 1

1

1给定输入“ab” ,这是一个返回的函数:

f["ab"] = 1

在哪里可以了解 Mathematica 的编程方式?从文档、许多参考书、Mathematica 堆栈交换站点、Leonid Shifrin对 Mathematica 编程的高级介绍,还有许多其他地方。但最好的地方是你的键盘,你的手指和思想完全投入。

于 2013-02-21T20:58:57.310 回答