Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.math.*;
- public class GridCell{
- //V for variable so it doesn't interfere with simple getter names
- private int iV;
- private int jV;
- private int aV;
- private int bV;
- private int cV;
- private int dV;
- private int eV;
- private int fV;
- private int nV;
- private int xV;
- private int tV;
- private int xplusnV;
- private int dplusnV;
- private int xplusnsquaredV;
- private int dplusnsquaredV;
- private int uV;
- private int bignV;
- private int naV;
- private boolean oddxplusnsquaredV;
- private BigInteger iVB;
- private BigInteger jVB;
- private BigInteger aVB;
- private BigInteger bVB;
- private BigInteger cVB;
- private BigInteger dVB;
- private BigInteger eVB;
- private BigInteger fVB;
- private BigInteger nVB;
- private BigInteger xVB;
- private BigInteger tVB;
- private BigInteger xplusnVB;
- private BigInteger dplusnVB;
- private BigInteger xplusnsquaredVB;
- private BigInteger dplusnsquaredVB;
- private BigInteger uVB;
- private BigInteger bignVB;
- private boolean oddxplusnsquaredVB;
- private String descriptionV;
- public GridCell(int aSend, int bSend){
- aV = aSend;
- bV = bSend;
- cV = aV*bV;
- dV = (int)Math.floor((int)Math.sqrt(cV));
- eV = cV-(dV*dV);
- fV = eV-((2*dV)+1);
- nV = ((aV+bV)/2)-dV;
- xV = dV-aV;
- tV = 0;
- if(eV%2==0){
- tV = (xV+2)/2;
- } else {
- tV = (xV+1)/2;
- }
- iV = nV+dV;
- jV = bV-iV;
- xplusnV = xV+nV;
- dplusnV = dV+nV;
- xplusnsquaredV = xplusnV*xplusnV;
- dplusnsquaredV = dplusnV*dplusnV;
- uV = 0;
- naV = nV*aV;
- oddxplusnsquaredV = true;
- if(xplusnsquaredV%2==0){
- oddxplusnsquaredV = false;
- uV = xplusnV/2;
- } else {
- uV = (xplusnV-1)/2;
- }
- bignV = ((cV+1)/2)-dV;
- descriptionV = "("+eV+","+nV+","+tV+") = {"+eV+":"+nV+":"+dV+":"+xV+":"+aV+":"+bV+"}, f="+fV+", c="+cV+", u="+uV+", i="+iV+", j="+jV;
- }
- public GridCell(int aSend, int bSend, int fSend){
- aV = aSend;
- bV = bSend;
- cV = aV*bV;
- dV = ((int)Math.floor((int)Math.sqrt(cV)))+1;
- eV = fSend;
- fV = eV+((2*dV)-1);
- nV = ((aV+bV)/2)-dV;
- xV = dV-aV;
- tV = 0;
- if(eV%2==0){
- tV = (xV+2)/2;
- } else {
- tV = (xV+1)/2;
- }
- iV = nV+dV;
- jV = bV-iV;
- xplusnV = xV+nV;
- dplusnV = dV+nV;
- xplusnsquaredV = xplusnV*xplusnV;
- dplusnsquaredV = dplusnV*dplusnV;
- uV = 0;
- naV = aV*nV;
- oddxplusnsquaredV = true;
- if(xplusnsquaredV%2==0){
- oddxplusnsquaredV = false;
- uV = xplusnV/2;
- } else {
- uV = (xplusnV-1)/2;
- }
- bignV = ((cV+1)/2)-dV;
- descriptionV = "("+eV+","+nV+","+tV+") = {"+eV+":"+nV+":"+dV+":"+xV+":"+aV+":"+bV+"}, e="+fV+", c="+cV+", u="+uV+", i="+iV+", j="+jV;
- }
- /*public GridCell(BigInteger aSend, BigInteger bSend){
- aVB = aSend;
- bVB = bSend;
- cVB = aVB.multiply(bVB);
- dVB =
- dVB = (int)Math.floor((int)Math.sqrt(cV));
- eVB = cV-(dV*dV);
- fVB = eV-((2*dV)+1);
- nVB = ((aV+bV)/2)-dV;
- xVB = dV-aV;
- tVB = 0;
- if(eV%2==0){
- tV = (xV+2)/2;
- } else {
- tV = (xV+1)/2;
- }
- iV = nV+dV;
- jV = bV-iV;
- xplusnV = xV+nV;
- dplusnV = dV+nV;
- xplusnsquaredV = xplusnV*xplusnV;
- dplusnsquaredV = dplusnV*dplusnV;
- uV = 0;
- oddxplusnsquaredV = true;
- if(xplusnsquaredV%2==0){
- oddxplusnsquaredV = false;
- uV = xplusnV/2;
- } else {
- uV = (xplusnV-1)/2;
- }
- bignV = ((cV+1)/2)-dV;
- descriptionV = "("+eV+","+nV+","+tV+") = {"+eV+":"+nV+":"+dV+":"+xV+":"+aV+":"+bV+"}, f="+fV+", c="+cV+", u="+uV+", i="+iV+", j="+jV;
- }*/
- public int a(){
- return aV;
- }
- public int b(){
- return bV;
- }
- public int c(){
- return cV;
- }
- public int d(){
- return dV;
- }
- public int e(){
- return eV;
- }
- public int f(){
- return fV;
- }
- public int n(){
- return nV;
- }
- public int x(){
- return xV;
- }
- public int t(){
- return tV;
- }
- public int i(){
- return iV;
- }
- public int j(){
- return jV;
- }
- public int xplusn(){
- return xplusnV;
- }
- public int dplusn(){
- return dplusnV;
- }
- public int xplusnsquared(){
- return xplusnsquaredV;
- }
- public int dplusnsquared(){
- return dplusnsquaredV;
- }
- public int u(){
- return uV;
- }
- public int bign(){
- return bignV;
- }
- public int na(){
- return naV;
- }
- public boolean oddxplusnsquared(){
- return oddxplusnsquaredV;
- }
- public BigInteger aB(){
- return aVB;
- }
- public BigInteger bB(){
- return bVB;
- }
- public BigInteger cB(){
- return cVB;
- }
- public BigInteger dB(){
- return dVB;
- }
- public BigInteger eB(){
- return eVB;
- }
- public BigInteger fB(){
- return fVB;
- }
- public BigInteger nB(){
- return nVB;
- }
- public BigInteger xB(){
- return xVB;
- }
- public BigInteger tB(){
- return tVB;
- }
- public BigInteger iB(){
- return iVB;
- }
- public BigInteger jB(){
- return jVB;
- }
- public BigInteger xplusnB(){
- return xplusnVB;
- }
- public BigInteger dplusnB(){
- return dplusnVB;
- }
- public BigInteger xplusnsquaredB(){
- return xplusnsquaredVB;
- }
- public BigInteger dplusnsquaredB(){
- return dplusnsquaredVB;
- }
- public BigInteger uB(){
- return uVB;
- }
- public BigInteger bignB(){
- return bignVB;
- }
- public boolean oddxplusnsquaredB(){
- return oddxplusnsquaredVB;
- }
- public void print(){
- System.out.println(descriptionV);
- }
- public String description(){
- return descriptionV;
- }
- public GridCell keepxplusnup(){
- return new GridCell((this.a()+1), (this.b()+1));
- }
- public GridCell keepxplusndown(){
- if(this.a() == 1){
- return this;
- }
- return new GridCell((this.a()-1), (this.b()-1));
- }
- public boolean isPrime(int n){
- if(n==1 || n==2 || n==4 || n<1){
- return false;
- }
- for(int i=2; i<n; i++){
- if(n%i==0){
- return false;
- }
- }
- return true;
- }
- public GridCell e1cell(){
- int a = aV*nV;
- int n = 1;
- int e = eV;
- int x = (int)Math.sqrt((2*n*a)-e);
- int d = a+x;
- int c = (d*d)+e;
- int b = a+(2*x)+(2*n);
- return new GridCell(a, b);
- }
- public GridCell f1cell(){
- int a = aV*(nV-1);
- int n = 1;
- int f = fV;
- int x = (int)Math.sqrt((2*n*a)-f);
- int b = a+(2*x)+(2*n);
- return new GridCell(a, b, f);
- }
- public GridCell e1cBigN(){
- int a = cV*bignV;
- int e = eV;
- int n = 1;
- int x = (int)Math.sqrt((2*n*a)-e);
- int b = a+(2*x)+(2*n);
- return new GridCell(a, b);
- }
- public GridCell e1toindex(GridCell cell, int index){
- if(cell.n()!=1){
- System.out.println("Error in e1toindex");
- return cell;
- }
- int a = cell.a();
- int n = 1;
- int e = cell.e();
- int x = cell.x();
- int t = cell.t();
- int b = cell.b();
- if(t<index){
- while(t<index){
- t++;
- a = b;
- x+=2;
- b = a+(2*x)+(2*n);
- }
- } else if(t>index){
- while(t>index){
- t--;
- b = a;
- x-=2;
- a = b-(2*x)-(2*n);
- }
- } else {
- return cell;
- }
- return new GridCell(a, b);
- }
- public GridCell f1toindex(GridCell cell, int index){
- if(cell.n()!=1){
- System.out.println("Error in f1toindex");
- return cell;
- }
- int a = cell.a();
- int n = 1;
- int f = cell.e();
- int x = cell.x();
- int t = cell.t();
- int b = cell.b();
- if(t<index){
- while(t<index){
- t++;
- a = b;
- x+=2;
- b = a+(2*x)+(2*n);
- }
- } else if(t>index){
- while(t>index){
- t--;
- b = a;
- x-=2;
- a = b-(2*x)-(2*n);
- }
- } else {
- return cell;
- }
- return new GridCell(a, b, f);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment