title: Using R to solve the Lucky 26 game
body: <p>I am trying to show my son how coding can be used to solve a problem posed by a game as well as seeing how R handles big data. The game in question is called "Lucky 26". In this game numbers (1-12 with no duplicates) are positioned on 12 points on a star of david (6 vertex, 6 intersections) and the 6 lines of 4 numbers must all add to 26. Of the approximately 479 million possibilities (12P12) there are apparently 144 solutions. I tried to code this in R as follows but memory is an issue it seems. I would greatly appreciate any advice to advance the answer if members have time. Thanking members in advance. </p>
  
  <pre><code>library(gtools)
  
  x=c()
  elements &lt;- 12
  for (i in 1:elements)
  { 
      x[i]&lt;-i
  }
  
  soln=c()            
  
  y&lt;-permutations(n=elements,r=elements,v=x)  
  j&lt;-nrow(y)
  for (i in 1:j) 
  {
  L1 &lt;- y[i,1] + y[i,3] + y[i,6] + y[i,8]
  L2 &lt;- y[i,1] + y[i,4] + y[i,7] + y[i,11]
  L3 &lt;- y[i,8] + y[i,9] + y[i,10] + y[i,11]
  L4 &lt;- y[i,2] + y[i,3] + y[i,4] + y[i,5]
  L5 &lt;- y[i,2] + y[i,6] + y[i,9] + y[i,12]
  L6 &lt;- y[i,5] + y[i,7] + y[i,10] + y[i,12]
  soln[i] &lt;- (L1 == 26)&amp;(L2 == 26)&amp;(L3 == 26)&amp;(L4 == 26)&amp;(L5 == 26)&amp;(L6 == 26) 
  }
  
  z&lt;-which(soln)
  z
  </code></pre>