You will require a function f which when given an integer S will return a list of the arrangements of the integers 1 to S such that g1=1 gS=S and generally for n=1 to n=S-1 gn+gn+1 is prime. S=1 is undefined. For S=2 to S=20 print f(S) to form a triangle. Then again for S=2 to S=20 print the number of possible arrangements of 1 to S meeting these requirements.

is_prime=: 1&p:@(+/)
 
is_prime_triangle=: {{
  NB. y is index into L and thus analogous to *a
  p=. is_prime L{~y+0 1
  if. N=y do. p return.end.
  i=. Y=. y+1
  if. p do. if. is_prime_triangle Y do. 1 return.end.end.
  while. M>i=.i+2 do.
    if. is_prime L{~y,i do.
      L=: (L{~Y,i) (i,Y)} L
      if. is_prime_triangle Y do. 1 return.end.
      L=: (L{~Y,i) (i,Y)} L
    end.
  end.
  0
}}
 
prime_triangle_counter=: {{
  NB. y is index into L and thus analogous to *a
  p=. is_prime L{~y+0 1
  if. N=y do.
    count=: count+p return.
  end.
  i=. Y=. y+1
  if. p do. prime_triangle_counter Y end.
  while. M>i=. i+2 do.
    if. is_prime L{~y,i do.
      L=: (L{~Y,i) (i,Y)} L
      prime_triangle_counter Y
      L=: (L{~Y,i) (i,Y)} L
    end.
  end.
  count
}}
 
prime_triangles=: {{
  for_k. i.y-1 do.
    L=: l=. 1+i.1+M=: 1+N=: k
    count=: 0
    prime_triangle_counter 0
    L=: l
    assert is_prime_triangle 0
    echo (8":count),' | ',3":L
  end.
}}