MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Coloring a Sum

  • To: mathgroup at smc.vnet.net
  • Subject: [mg107001] Coloring a Sum
  • From: "Bruce Colletti" <bwcolletti at verizon.net>
  • Date: Sun, 31 Jan 2010 05:57:15 -0500 (EST)

Re 7.0.1 under WinXP.

Is there simpler code (than that below) for this task: 

- For numeric list X = {x1,...,xN}, color and display the form x1 + ... + xN

- To color, first split X into m-element sublists

- Color red (blue) the elements in odd (even) numbered sublists

Thanks.

Bruce


f[X_List, m_Integer] := Module[{Y},
   Y = Partition[X, m];
   Z = MapThread[(c = If[OddQ@#2, Red, Blue]; 
       Style[#, c, Bold, 18] & /@ #1) &, {Y, Range@Length@Y}];
   Infix[Flatten@Z, Style["+", 18]]];

f[Table[1,{15}],3]




  • Prev by Date: Re: position of sequence of numbers in list
  • Next by Date: Re: position of sequence of numbers in list
  • Previous by thread: Band too slow when constructing a SparseArray
  • Next by thread: Phase reversal at fixed boundary