# Understanding Maps and slot

Going through some old code I found this line:

SampleSierpinskiCarpet[n_] :=
Module[{digitpairs = {{0, 0}, {0, 1}, {0, 2}, {1, 0}, {1, 2}, {2,
0}, {2, 1}, {2, 2}}},
Map[N[#.(1/3^Range[26])] &,
Transpose[RandomChoice[digitpairs, {n, 26}], {1, 3, 2}], {2}]]


Could someone explain exactly whats going on here? There is a lot of syntax to unpack, and no extra comments to go along with it.

When plotted it produces a Sierpiński Carpet:

S = SampleSierpinskiCarpet[100000];
V = SimilarFunction[100000];
Row[ListPlot[#, PlotStyle -> PointSize[Tiny], AspectRatio -> 1,
ImageSize -> 400] & /@ {S, V}]


Yields:

edit: Thanks for the help everyone: The similar function looks like this

SampleViksecFractal[n_] :=
Module[{digitpairs = {{0, 0}, {0, 2}, {2, 0}, {2, 2}, {1, 1}}},
Map[N[#.(1/3^Range[26])] &,
Transpose[RandomChoice[digitpairs, {n, 26}], {1, 3, 2}], {2}]]

• Here's the rough idea: Essentially, each point of the carpet is described by a list of offsets (an element of digitcharacters). You choose 26 offsets, each for a subsequent level of the fractal, which are then multiplied by 1/3^n, where n is the level. For the rest, try to evaluate parts of the expression one by one to see how the output changes as include more and more of the original code – Lukas Lang Jul 2 '18 at 18:39
• Do you have the definition of SimilarFunction as well? – MarcoB Jul 2 '18 at 19:45
• When looking at code like this, I find it's easier to see what it does if I enforce formatting on the code. Try evaluating Needs[ "GeneralUtilities"]; HoldPrettyForm[ SampleSierpinskiCarpet[n_] := <rest of definition> ]` and you might find it easier to understand what it's doing. – Jason B. Jul 2 '18 at 19:46