Solve Aristotle's Number Problem Aristotle's number puzzle is the challenge of populating each of 19 cells in a hexagonal grid with a unique integer between 1 and 19 such that the total along every axis is 38.

You can picture the game board looking like this:



And the puzzle, in essence, is the solution to the following set of fifteen equations:

((a + b + c) == 38 &amp;&amp; (d + e + f + g) == 38 &amp;&amp; (h + i + j + k + l) == 
   38 &amp;&amp; (m + n + o + p) == 38 &amp;&amp; (q + r + s) == 38 &amp;&amp; (a + d + h) == 
   38 &amp;&amp; (b + e + i + m) == 38 &amp;&amp; (c + f + j + n + q) == 
   38 &amp;&amp; (g + k + o + r) == 38 &amp;&amp; (l + p + s) == 38 &amp;&amp; (c + g + l) == 
   38 &amp;&amp; (b + f + k + p) == 38 &amp;&amp; (a + e + j + o + s) == 
   38 &amp;&amp; (d + i + n + r) == 38 &amp;&amp; (h + m + q) == 38)


Where each variable is a unique number in the set {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}.

There are multiple possible solutions, and are 19! possible combinations of integers, so naive brute force will be impractical.

Rules:


No hardcoding the answer or looking up the answer elsewhere; your code needs to find it on its own
Speed doesn't matter, but you do have to show your results, so code that takes 1000 years to run won't help you
Find all the answers
Treat answers that are identical under rotation as identical
Deduct 5% of your total byte count if you output the results in an attractive honeycomb
Fewest bytes wins
Java (1517 - 75.85) = 1441.15 (1429 - 71.45) = 1357.55 (1325 - 66.25) = 1258.75

This was fun. 

Prints all unique solutions w.r.t. mirroring and rotation, in a pleasant honeycomb (hence 5% reduction)

Runtime: ~0.122s (122 milliseconds) on my 4 year old laptop.

Golfed code (edit realized I was stupidly repeating my printfs, reduced them to a single printf for maximum golf) (new edit Reduced calls to Set functions into clever smaller functions, some other micro-optimizations): 

import java.util.*;class A{boolean c(Set&lt;Integer&gt;u,int z){return!u.contains(z);}Set&lt;Integer&gt;b(Set&lt;Integer&gt;c,int...v){Set&lt;Integer&gt;q=new HashSet&lt;Integer&gt;(c);for(int x:v)q.add(x);return q;}void w(){Set&lt;Integer&gt;U,t,u,v,w,y,z;int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,X,Z;X=20;Z=38;for(a=1;a&lt;X;a++)for(b=1;b&lt;X;b++)if(b!=a)for(c=1;c&lt;X;c++)if(c!=a&amp;&amp;c!=b&amp;&amp;a+b+c==Z){U=b(new HashSet&lt;Integer&gt;(),a,b,c);for(d=1;d&lt;X;d++)if(c(U,d))for(h=1;h&lt;X;h++)if(h!=d&amp;&amp;c(U,h)&amp;&amp;a+d+h==Z){t=b(U,a,b,c,d,h);for(m=1;m&lt;X;m++)if(c(t,m))for(q=1;q&lt;X;q++)if(q!=m&amp;&amp;c(t,q)&amp;&amp;h+m+q==Z){u=b(t,m,q);for(r=1;r&lt;X;r++)if(c(u,r))for(s=1;s&lt;X;s++)if(s!=r&amp;&amp;c(u,s)&amp;&amp;q+r+s==Z){v=b(u,r,s);for(p=1;p&lt;X;p++)if(c(v,p))for(l=1;l&lt;X;l++)if(l!=p&amp;&amp;c(v,l)&amp;&amp;s+p+l==Z){w=b(v,p,l);for(g=1;g&lt;X;g++)if(c(w,g)&amp;&amp;l+g+c==Z)for(e=1;e&lt;X;e++)if(e!=g&amp;&amp;c(w,e))for(f=1;f&lt;X;f++)if(f!=e&amp;&amp;f!=g&amp;&amp;c(w,f)&amp;&amp;d+e+f+g==Z){y=b(w,g,e,f);for(i=1;i&lt;X;i++)if(c(y,i))for(n=1;n&lt;X;n++)if(n!=i&amp;&amp;c(y,n)&amp;&amp;d+i+n+r==Z&amp;&amp;b+e+i+m==Z){z=b(y,i,n);for(o=1;o&lt;X;o++)if(c(z,o))for(k=1;k&lt;X;k++)if(k!=o&amp;&amp;c(z,k)&amp;&amp;m+n+o+p==Z&amp;&amp;r+o+k+g==Z&amp;&amp;b+f+k+p==Z)for(j=1;j&lt;X;j++)if(c(z,j)&amp;&amp;j!=o&amp;&amp;j!=k&amp;&amp;a+e+j+o+s==Z&amp;&amp;c+f+j+n+q==Z&amp;&amp;h+i+j+k+l==Z){System.out.printf("%6d%4d%4d\n\n%4d%4d%4d%4d\n\n%2d%4d%4d%4d%4d\n\n%4d%4d%4d%4d\n\n%6d%4d%4d\n\n",a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s);return;}}}}}}}}}public static void main(String[]a){(new A()).w();}}



   Brute force is passe, but clever use of the fact that only a very small set of solutions exists led me to an iteration based answer, where within each loop of the iteration I only consider integers that have not been "assigned" yet. I make use of Java's HashSet to gain O(1) lookups for numbers that have been used previously. Finally, there are exactly 12 solutions, but when you discount both rotation and mirroring this reduces to just one unique solution, so when the first solution is encountered, I print it out and terminate. Check out my less-golfed code at github for a bit of a clearer view into how I am approaching this solution.


Enjoy!