/*
Online Java - IDE, Code Editor, Compiler
Online Java is a quick and easy tool that helps you to build, compile, test your programs
online.
*/

import java.util.*;

public class Permutation
{
    static int k;
    static long result=0;
    static int finalTotal=0;
    
    public static void main(String[] args) 
    {
        
        System.out.println("Welcome to Online IDE!! Happy Coding :)");
        int n=35;
        Map <Long, Long> mp = new HashMap<>();
        int H=0;   //this will be calculated total beads
        int N=4;   //need to figure limit out pripoerly later
        int M;  //length middle dissector
        int R; //number rows above or below to the dissector
        
        
        System.out.println("***CENTERED HEXAGONAL NUMBER***");
        System.out.println("P(n,r) = n! / (n−r)!");
        
        //do
    //    {
            
            //we know n value is too high, but safe measure set above for now
            //since do not know the termination
            
            for (int i=1;i<N;i++)
            {
                M=(i*2)-1;
                
            
                //if (i!=0)
                //{
                    System.out.println("\nMiddle disector: " + M);
                    
                //}
                
                
         R=i-1;
         System.out.println("Number rows above or below: " + R);
                
                
                //go each row above or below disector
                //we expect the value to be
                
                if (k!=1)
                {
                
                for (k=R; k>=1;k--)
                {
                    System.out.println("val R: " + R);
                    System.out.println("1current result: " + result);
                    System.out.println("Total full count: " + Permutations(mp,i,M,k,R,n));
                    
                    System.out.println("value in k: " + k);
                    System.out.println("value in R: " + R);
                    
                    if (k==1)
                    {
                        result=0;
                        System.out.println("TERMINATE");
                    }
                    
                }
                
            }
                
            }
            
       // }while (H<=n);
    }
    
    public static long Permutations (Map factorialResults, int i, int M, int k,int R,int n)
    {
        
        
        if (R==0)
        {
            return result;
        }
        
        if (k>=1)
        {
            System.out.println("BEADS in: " + (k) + " row above disector is: " + (M-k));
            System.out.println("CURRENT RESULT: " + result);
            result=result + (M-k);
            System.out.println("R:" +R);
            if (R!=1)
            {
                System.out.println("HERE");
                System.out.println("HERE RESULTS: " + result);
                result = ((M-k)+(Permutations (factorialResults,i,M,(k-1),R,n)));
                
                System.out.println("number provided: " + n);
                System.out.println("Final Total: " + n);
                
                if (finalTotal>n)
                {
                    System.out.println("NOT A CENTRAL HEXAGON NUMBER");
                    System.exit(0);
                }
                finalTotal=0;
                
                System.out.println("RE ENTER BACK*****");
                
                if (k==0)
                {
                    return result;
                    //System.out.println("TERMINATE!!!!!!");
                }
                
            }
            else
            {
                result = M-k;
            }
            
            
            //System.out.println("nnnRESULT: " + result);
            //System.out.println("test:" +R);
            
           
            
            //factorialResults.put((M+k),result);
            
            
            
            //return result;
        }
        System.out.println("RWAC: " + result);
        System.out.println("LEAVE THE IF LOOP: ");
        
        System.out.println(result*2);
        System.out.println(M);
        System.out.println(k);
        System.out.println(R);
        
        finalTotal  = (int)(result*2)+M;
        System.out.println("******FINAL TOTAL: " + finalTotal);
        return finalTotal;
    }
}