Risokaoni

Challenge #42

Aug 16th, 2020
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.26 KB | None | 0 0
  1. /* Script by u/Risoka
  2. You use it with any arg you want. Yes, any. (but no big numbers) */
  3.  
  4. import java.util.*;
  5.  
  6. public class Main
  7. {
  8. /* variable to see if its star trek mode */ public static int ISSTARTREKMODE = 0;
  9.  
  10. public static void main(String[] args) throws InterruptedException {
  11. /* I'll use double to make sure we can calculate any number */ double L[] = new double[args.length];
  12. /* Here too */ double P = 0;
  13. for (int INT = 0; INT < args.length; INT++) {
  14. if (!ISNOTINT(GETARGVALUE(args, INT))) {
  15. /* use byte to be more resource friendly */ L[INT] = GETARGVALUEASBYTE(args,INT);}}
  16. for (int INT = 0; INT < args.length; INT++) {
  17. if (L[INT] != 0)
  18. P = P + L[INT];}
  19.  
  20. System.out.print("Working on number: " + P);
  21. System.out.print("\nDo you want to continue? [YES]/[no]");
  22. Scanner A = new Scanner(System.in);
  23. String B = A.nextLine();
  24. //double V = Integer.parseInt(getargvalue(args,0))*1.0; //old dont use
  25. double V = P;
  26. P = 0;
  27.  
  28. int interation = 1;
  29. for (interation = 1;interation<10E6;interation++){
  30. P = V + (Math.pow(-1,(interation+1))/(2*interation-1)) + P;
  31. //advanced math
  32. }
  33. /* User don't want to know the answer. We need to close the request ***TODO*** */if (B.equals("no")) { Thread.sleep(4000); System.out.print("Ok, bye."); return;}
  34. if (args.length > 1) {
  35. for (int INT = 0; INT < args.length; INT++) {
  36. if (GETARGVALUE(args,INT).equals("star_trek")){
  37. ISSTARTREKMODE = ISSTARTREKMODE + 1;}}}
  38. if (ISSTARTREKMODE == 0){
  39. P = P - (interation-1) * V;
  40. P = 4 * P;
  41. P = P * 3;
  42. P = P * 2;
  43. P = P * 7;
  44. P = P/Math.PI;
  45. P = (int)P;
  46. }
  47. if (ISSTARTREKMODE != 0){
  48. //star trek mode, works for any number or star_trek flags to fix bug
  49. P = P - (interation - 1) * V;
  50. P = 4 * P;
  51. P = P * 3;
  52. P = 2 * P;
  53. P = P * 7;
  54. P = P/Math.PI;
  55. P = Math.round(P + (int)(2*Math.PI) - Math.pow(Math.PI, 0));
  56. }
  57. Thread.currentThread().sleep(2000);
  58. System.out.print("Calculating.");
  59. Thread.currentThread().sleep(500);
  60. System.out.print(" .");
  61. Thread.currentThread().sleep(500);
  62. System.out.print(" .\n");
  63. Thread.currentThread().sleep(1000);
  64. System.out.print("Waiting for approval.");
  65. Thread.currentThread().sleep(500);
  66. System.out.print(" .");
  67. Thread.currentThread().sleep(500);
  68. System.out.print(" .\n");
  69. Thread.currentThread().sleep(1000);
  70. System.out.print("Matrix aproval granted.");
  71. Thread.currentThread().sleep(500);
  72. System.out.print(" .");
  73. Thread.currentThread().sleep(500);
  74. System.out.print(" .\n");
  75. Thread.currentThread().sleep(1000);
  76. System.out.print("The final result is:\n");
  77. Thread.currentThread().sleep(1000);
  78. System.out.print(P);
  79.  
  80. }
  81.  
  82. public static byte GETARGVALUEASBYTE(String[] a, int i){
  83. try{
  84. Byte.parseByte(GETARGVALUE(a, i));
  85. }
  86. catch(NumberFormatException e) {
  87.  
  88. if (Integer.parseInt(GETARGVALUE(a, i))>126){
  89. System.out.println("values in the arg > 126 will be interpreted as 126, sorry");
  90. return (byte)126;
  91. }
  92.  
  93. if (Integer.parseInt(GETARGVALUE(a, i))<-126){
  94. System.out.println("values in the arg < -126 will be interpreted as -126, sorry");
  95. return (byte)-126;
  96. }
  97. return 0;
  98. }
  99. return Byte.parseByte(GETARGVALUE(a, i));    }
  100. public static String GETARGVALUE(String[] a, int i) {
  101. String r = new String(a[i]);
  102. return r;   }
  103. public static boolean ISNOTINT(String s) {
  104. try {
  105. Integer.parseInt(s);
  106. } catch(NumberFormatException e) {
  107. return true;} return false;
  108. }
  109. }
  110.  
Advertisement
Add Comment
Please, Sign In to add comment