1

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?

Chen Stats Yu
  • 4,986
  • 2
  • 24
  • 50
  • 2
    You can also make use of some triangle lattice functionality from IGraph/M, even though it's not made for this. http://i.stack.imgur.com/SpEH0.png – Szabolcs Jun 25 '18 at 21:03
  • 1
    @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] – Chen Stats Yu Jun 25 '18 at 21:17
  • https://thinkmeta.wordpress.com/2010/06/28/scala-expressiveness/ – matrix42 Jun 26 '18 at 10:09

1 Answers1

3
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

rhermans
  • 36,518
  • 4
  • 57
  • 149