Fri, 28 Mar 2008

« Something like Subsets | MAIN | Howard Dean endorses John McCain »

Fun with Mathematica

Once you get used to writing things in the Mathematica language, all sorts of fun things become possible. This morning I printed a set of small two-sided Mexican flags that we'll wrap around toothpicks, glue together and stick into Krispy Kreme doughnuts tonight:

TableForm[
  Partition[
    Table[
      Framed[
        CountryData["Mexico", "Flag"]
      ],
      {24}
    ],
    2
  ],
  TableSpacing -> {Automatic, 2}
]

and I just solved a little regular expression problem posed by my boss:

> What's the regex for matching a three digit version number?
>
> Valid examples (where 'x' is an integer > 0)
> x
> x.
> x.x
> x.x.
> x.x.x

Howzabout -

In[19]:= strings = {"6", "6.", "6.0", "6.0.", "6.0.1"}
Out[19]= {"6", "6.", "6.0", "6.0.", "6.0.1"}

In[30]:= StringMatchQ[#, RegularExpression["[0-9](\.([0-9](\.([0-9])?)?)?)?"]] & /@ strings
Out[30]= {True, True, True, True, True}

A facility for quotation covers the absence of original thought.—Lord Peter Wimsey

Left column Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.