Guest User

GridCell.java

a guest
Dec 7th, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.21 KB | None | 0 0
  1. import java.util.*;
  2. import java.math.*;
  3.  
  4. public class GridCell{
  5. //V for variable so it doesn't interfere with simple getter names
  6. private int iV;
  7. private int jV;
  8. private int aV;
  9. private int bV;
  10. private int cV;
  11. private int dV;
  12. private int eV;
  13. private int fV;
  14. private int nV;
  15. private int xV;
  16. private int tV;
  17. private int xplusnV;
  18. private int dplusnV;
  19. private int xplusnsquaredV;
  20. private int dplusnsquaredV;
  21. private int uV;
  22. private int bignV;
  23. private int naV;
  24. private boolean oddxplusnsquaredV;
  25.  
  26. private BigInteger iVB;
  27. private BigInteger jVB;
  28. private BigInteger aVB;
  29. private BigInteger bVB;
  30. private BigInteger cVB;
  31. private BigInteger dVB;
  32. private BigInteger eVB;
  33. private BigInteger fVB;
  34. private BigInteger nVB;
  35. private BigInteger xVB;
  36. private BigInteger tVB;
  37. private BigInteger xplusnVB;
  38. private BigInteger dplusnVB;
  39. private BigInteger xplusnsquaredVB;
  40. private BigInteger dplusnsquaredVB;
  41. private BigInteger uVB;
  42. private BigInteger bignVB;
  43. private boolean oddxplusnsquaredVB;
  44.  
  45. private String descriptionV;
  46.  
  47. public GridCell(int aSend, int bSend){
  48. aV = aSend;
  49. bV = bSend;
  50. cV = aV*bV;
  51. dV = (int)Math.floor((int)Math.sqrt(cV));
  52. eV = cV-(dV*dV);
  53. fV = eV-((2*dV)+1);
  54. nV = ((aV+bV)/2)-dV;
  55. xV = dV-aV;
  56. tV = 0;
  57. if(eV%2==0){
  58. tV = (xV+2)/2;
  59. } else {
  60. tV = (xV+1)/2;
  61. }
  62. iV = nV+dV;
  63. jV = bV-iV;
  64. xplusnV = xV+nV;
  65. dplusnV = dV+nV;
  66. xplusnsquaredV = xplusnV*xplusnV;
  67. dplusnsquaredV = dplusnV*dplusnV;
  68. uV = 0;
  69. naV = nV*aV;
  70. oddxplusnsquaredV = true;
  71. if(xplusnsquaredV%2==0){
  72. oddxplusnsquaredV = false;
  73. uV = xplusnV/2;
  74. } else {
  75. uV = (xplusnV-1)/2;
  76. }
  77. bignV = ((cV+1)/2)-dV;
  78. descriptionV = "("+eV+","+nV+","+tV+") = {"+eV+":"+nV+":"+dV+":"+xV+":"+aV+":"+bV+"}, f="+fV+", c="+cV+", u="+uV+", i="+iV+", j="+jV;
  79. }
  80.  
  81. public GridCell(int aSend, int bSend, int fSend){
  82. aV = aSend;
  83. bV = bSend;
  84. cV = aV*bV;
  85. dV = ((int)Math.floor((int)Math.sqrt(cV)))+1;
  86. eV = fSend;
  87. fV = eV+((2*dV)-1);
  88. nV = ((aV+bV)/2)-dV;
  89. xV = dV-aV;
  90. tV = 0;
  91. if(eV%2==0){
  92. tV = (xV+2)/2;
  93. } else {
  94. tV = (xV+1)/2;
  95. }
  96. iV = nV+dV;
  97. jV = bV-iV;
  98. xplusnV = xV+nV;
  99. dplusnV = dV+nV;
  100. xplusnsquaredV = xplusnV*xplusnV;
  101. dplusnsquaredV = dplusnV*dplusnV;
  102. uV = 0;
  103. naV = aV*nV;
  104. oddxplusnsquaredV = true;
  105. if(xplusnsquaredV%2==0){
  106. oddxplusnsquaredV = false;
  107. uV = xplusnV/2;
  108. } else {
  109. uV = (xplusnV-1)/2;
  110. }
  111. bignV = ((cV+1)/2)-dV;
  112. descriptionV = "("+eV+","+nV+","+tV+") = {"+eV+":"+nV+":"+dV+":"+xV+":"+aV+":"+bV+"}, e="+fV+", c="+cV+", u="+uV+", i="+iV+", j="+jV;
  113. }
  114.  
  115. /*public GridCell(BigInteger aSend, BigInteger bSend){
  116. aVB = aSend;
  117. bVB = bSend;
  118. cVB = aVB.multiply(bVB);
  119. dVB =
  120.  
  121. dVB = (int)Math.floor((int)Math.sqrt(cV));
  122. eVB = cV-(dV*dV);
  123. fVB = eV-((2*dV)+1);
  124. nVB = ((aV+bV)/2)-dV;
  125. xVB = dV-aV;
  126. tVB = 0;
  127.  
  128. if(eV%2==0){
  129. tV = (xV+2)/2;
  130. } else {
  131. tV = (xV+1)/2;
  132. }
  133. iV = nV+dV;
  134. jV = bV-iV;
  135. xplusnV = xV+nV;
  136. dplusnV = dV+nV;
  137. xplusnsquaredV = xplusnV*xplusnV;
  138. dplusnsquaredV = dplusnV*dplusnV;
  139. uV = 0;
  140. oddxplusnsquaredV = true;
  141. if(xplusnsquaredV%2==0){
  142. oddxplusnsquaredV = false;
  143. uV = xplusnV/2;
  144. } else {
  145. uV = (xplusnV-1)/2;
  146. }
  147. bignV = ((cV+1)/2)-dV;
  148. descriptionV = "("+eV+","+nV+","+tV+") = {"+eV+":"+nV+":"+dV+":"+xV+":"+aV+":"+bV+"}, f="+fV+", c="+cV+", u="+uV+", i="+iV+", j="+jV;
  149. }*/
  150.  
  151. public int a(){
  152. return aV;
  153. }
  154.  
  155. public int b(){
  156. return bV;
  157. }
  158.  
  159. public int c(){
  160. return cV;
  161. }
  162.  
  163. public int d(){
  164. return dV;
  165. }
  166.  
  167. public int e(){
  168. return eV;
  169. }
  170.  
  171. public int f(){
  172. return fV;
  173. }
  174.  
  175. public int n(){
  176. return nV;
  177. }
  178.  
  179. public int x(){
  180. return xV;
  181. }
  182.  
  183. public int t(){
  184. return tV;
  185. }
  186.  
  187. public int i(){
  188. return iV;
  189. }
  190.  
  191. public int j(){
  192. return jV;
  193. }
  194.  
  195. public int xplusn(){
  196. return xplusnV;
  197. }
  198.  
  199. public int dplusn(){
  200. return dplusnV;
  201. }
  202.  
  203. public int xplusnsquared(){
  204. return xplusnsquaredV;
  205. }
  206.  
  207. public int dplusnsquared(){
  208. return dplusnsquaredV;
  209. }
  210.  
  211. public int u(){
  212. return uV;
  213. }
  214.  
  215. public int bign(){
  216. return bignV;
  217. }
  218.  
  219. public int na(){
  220. return naV;
  221. }
  222.  
  223. public boolean oddxplusnsquared(){
  224. return oddxplusnsquaredV;
  225. }
  226.  
  227.  
  228.  
  229. public BigInteger aB(){
  230. return aVB;
  231. }
  232.  
  233. public BigInteger bB(){
  234. return bVB;
  235. }
  236.  
  237. public BigInteger cB(){
  238. return cVB;
  239. }
  240.  
  241. public BigInteger dB(){
  242. return dVB;
  243. }
  244.  
  245. public BigInteger eB(){
  246. return eVB;
  247. }
  248.  
  249. public BigInteger fB(){
  250. return fVB;
  251. }
  252.  
  253. public BigInteger nB(){
  254. return nVB;
  255. }
  256.  
  257. public BigInteger xB(){
  258. return xVB;
  259. }
  260.  
  261. public BigInteger tB(){
  262. return tVB;
  263. }
  264.  
  265. public BigInteger iB(){
  266. return iVB;
  267. }
  268.  
  269. public BigInteger jB(){
  270. return jVB;
  271. }
  272.  
  273. public BigInteger xplusnB(){
  274. return xplusnVB;
  275. }
  276.  
  277. public BigInteger dplusnB(){
  278. return dplusnVB;
  279. }
  280.  
  281. public BigInteger xplusnsquaredB(){
  282. return xplusnsquaredVB;
  283. }
  284.  
  285. public BigInteger dplusnsquaredB(){
  286. return dplusnsquaredVB;
  287. }
  288.  
  289. public BigInteger uB(){
  290. return uVB;
  291. }
  292.  
  293. public BigInteger bignB(){
  294. return bignVB;
  295. }
  296.  
  297. public boolean oddxplusnsquaredB(){
  298. return oddxplusnsquaredVB;
  299. }
  300.  
  301.  
  302.  
  303.  
  304. public void print(){
  305. System.out.println(descriptionV);
  306. }
  307.  
  308. public String description(){
  309. return descriptionV;
  310. }
  311.  
  312. public GridCell keepxplusnup(){
  313. return new GridCell((this.a()+1), (this.b()+1));
  314. }
  315.  
  316. public GridCell keepxplusndown(){
  317. if(this.a() == 1){
  318. return this;
  319. }
  320. return new GridCell((this.a()-1), (this.b()-1));
  321. }
  322.  
  323. public boolean isPrime(int n){
  324. if(n==1 || n==2 || n==4 || n<1){
  325. return false;
  326. }
  327. for(int i=2; i<n; i++){
  328. if(n%i==0){
  329. return false;
  330. }
  331. }
  332. return true;
  333. }
  334.  
  335. public GridCell e1cell(){
  336. int a = aV*nV;
  337. int n = 1;
  338. int e = eV;
  339. int x = (int)Math.sqrt((2*n*a)-e);
  340. int d = a+x;
  341. int c = (d*d)+e;
  342. int b = a+(2*x)+(2*n);
  343. return new GridCell(a, b);
  344. }
  345.  
  346. public GridCell f1cell(){
  347. int a = aV*(nV-1);
  348. int n = 1;
  349. int f = fV;
  350. int x = (int)Math.sqrt((2*n*a)-f);
  351. int b = a+(2*x)+(2*n);
  352. return new GridCell(a, b, f);
  353. }
  354.  
  355. public GridCell e1cBigN(){
  356. int a = cV*bignV;
  357. int e = eV;
  358. int n = 1;
  359. int x = (int)Math.sqrt((2*n*a)-e);
  360. int b = a+(2*x)+(2*n);
  361. return new GridCell(a, b);
  362. }
  363.  
  364.  
  365.  
  366. public GridCell e1toindex(GridCell cell, int index){
  367. if(cell.n()!=1){
  368. System.out.println("Error in e1toindex");
  369. return cell;
  370. }
  371. int a = cell.a();
  372. int n = 1;
  373. int e = cell.e();
  374. int x = cell.x();
  375. int t = cell.t();
  376. int b = cell.b();
  377. if(t<index){
  378. while(t<index){
  379. t++;
  380. a = b;
  381. x+=2;
  382. b = a+(2*x)+(2*n);
  383. }
  384. } else if(t>index){
  385. while(t>index){
  386. t--;
  387. b = a;
  388. x-=2;
  389. a = b-(2*x)-(2*n);
  390. }
  391. } else {
  392. return cell;
  393. }
  394. return new GridCell(a, b);
  395. }
  396.  
  397. public GridCell f1toindex(GridCell cell, int index){
  398. if(cell.n()!=1){
  399. System.out.println("Error in f1toindex");
  400. return cell;
  401. }
  402. int a = cell.a();
  403. int n = 1;
  404. int f = cell.e();
  405. int x = cell.x();
  406. int t = cell.t();
  407. int b = cell.b();
  408. if(t<index){
  409. while(t<index){
  410. t++;
  411. a = b;
  412. x+=2;
  413. b = a+(2*x)+(2*n);
  414. }
  415. } else if(t>index){
  416. while(t>index){
  417. t--;
  418. b = a;
  419. x-=2;
  420. a = b-(2*x)-(2*n);
  421. }
  422. } else {
  423. return cell;
  424. }
  425. return new GridCell(a, b, f);
  426. }
  427. }
Advertisement
Add Comment
Please, Sign In to add comment