1
$\begingroup$

I'd like to create some pyramid that looks like this,

enter image description here

The numbers/cells are easy to do

Grid[NestWhileList[ Table[#[[i]] + #[[i + 1]], {i, 1, Length[#] - 1}] &, {1, 22, 5, 7}, Length[#] > 1 &] // Reverse, Frame -> All]

Grid[NestWhileList[ Table[#[[i]] + #[[i + 1]], {i, 1, Length[#] - 1}] &, {a, b, c, d},    Length[#] > 1 &] // Reverse, Frame -> All]

enter image description here

But then the output is not quite there yet. Easily achievable?

$\endgroup$
  • 2
    $\begingroup$ You can also make use of some triangle lattice functionality from IGraph/M, even though it's not made for this. i.stack.imgur.com/SpEH0.png $\endgroup$ – Szabolcs Jun 25 '18 at 21:03
  • 1
    $\begingroup$ @Szabolcs It does not seem to be able to do the "triangular" style frame, but that's fine. Thanks. Column[Grid[{#}, ItemSize -> 3] & /@ (NestWhileList[ Table[#[[i]] + #[[i + 1]], {i, 1, Length[#] - 1}] &, {1, 22, 5, 7}, Length[#] > 1 &] // Reverse), Center, Frame -> All] $\endgroup$ – Chen Stats Yu Jun 25 '18 at 21:17
  • $\begingroup$ thinkmeta.wordpress.com/2010/06/28/scala-expressiveness $\endgroup$ – matrix89 Jun 26 '18 at 10:09
3
$\begingroup$
fun[f_, list_] := NestList[
  f @@@ Partition[#, 2, 1] &,
  list
  , Length[list] - 1
  ]

build[list_] := Module[
  {
   coordinates = 
    Flatten[
     MapIndexed[
      {#1, First[#2]} &, 
      fun[(#/2) &@*Plus, Range[Length[list]]],
      {2}
      ],
     1
   ],
   numbers = Flatten[fun[Plus, list]]
   },
  Graphics[
   {LightOrange,
    Disk[#, 0.4] & /@ coordinates,
    Black,
    Thread@Text[numbers, coordinates]
    }
   ]]


build[{2, 1, 4, 6}]

Mathematica graphics

| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.