Facebook
From Brice Brown, 3 Years ago, written in C.
Embed
Download Paste or View Raw
Hits: 120
  1. void pemdasProblem(int difficulty)
  2. {
  3.     Text input = inputObject.GetComponent<Text>();
  4.     switch (difficulty)
  5.     {  
  6.             /*
  7.                 there is unshown code but it follows the same logic
  8.             */
  9.  
  10.             // level III is PEMDAS problems
  11.         case 3:
  12.             // 33% of being (a[]b)²[]c[]d
  13.             if (UnityEngine.Random.Range(0,101) > 67)
  14.             {
  15.                     // 50% chance of being multiplication
  16.                 if (UnityEngine.Random.Range(0,101) > 50)
  17.                 {  
  18.                     a = UnityEngine.Random.Range(0,13);
  19.                     b = UnityEngine.Random.Range(0,13);
  20.                     c = UnityEngine.Random.Range(0,13);
  21.                     d = UnityEngine.Random.Range(0,13);
  22.                         // 50% chance of being (a[]b)²(c)[]d
  23.                     if(UnityEngine.Random.Range(0,101) > 50){
  24.                             // 50% chance of being (a+b)²(c)[]d
  25.                         if(UnityEngine.Random.Range(0,101)>50){
  26.                                 // 50% of being (a+b)²(c)+d
  27.                             if(UnityEngine.Random.Range(0,101)>50){
  28.                                 ans = ((int) Mathf.Pow((float) a+ (float) b, 2))*c+d;
  29.                                 input.text = "("+a+"+"+b+")"+"²"+"("+c+")"+"+"+d+"=";
  30.                                 Debug.Log("Problem ID: 78");
  31.                                 // 50% of being (a+b)²(c)-d
  32.                             } else {
  33.                                 ans = ((int) Mathf.Pow((float) a+ (float) b, 2))*c-d;
  34.                                 input.text = "("+a+"+"+b+")"+"²"+"("+c+")"+"-"+d+"=";
  35.                                 Debug.Log("Problem ID: 79");
  36.                             }
  37.                             // 50% of being (a-b)²(c)[]d
  38.                         } else {
  39.                             // 50% of being (a-b)²(c)+d
  40.                             if(UnityEngine.Random.Range(0,101)>50){
  41.                                 ans = ((int) Mathf.Pow((float) a- (float) b, 2))*c+d;
  42.                                 input.text = "("+a+"-"+b+")"+"²"+"("+c+")"+"+"+d+"=";
  43.                                 Debug.Log("Problem ID: 80");
  44.                                 // 50% of being (a-b)²(c)-d
  45.                             } else {
  46.                                 ans = ((int) Mathf.Pow((float) a- (float) b, 2))*c-d;
  47.                                 input.text = "("+a+"-"+b+")"+"²"+"("+c+")"+"-"+d+"=";
  48.                                 Debug.Log("Problem ID: 81");
  49.                             }
  50.                         }
  51.                         // 50% chance of being (a[]b)²c[]*d
  52.                     } else {
  53.                         // 50% chance of being (a+b)²[]c(d)
  54.                         if(UnityEngine.Random.Range(0,101)>50){
  55.                                 // 50% of being (a+b)²+c(d)
  56.                             if(UnityEngine.Random.Range(0,101)>50){
  57.                                 ans = ((int) Mathf.Pow((float) a+ (float) b, 2))+c*d;
  58.                                 input.text = "("+a+"+"+b+")"+"²"+"+"+c+"("+d+")"+"=";
  59.                                 Debug.Log("Problem ID: 82");
  60.                                 // 50% of being (a+b)²-c(d)
  61.                             } else {
  62.                                 ans = ((int) Mathf.Pow((float) a+ (float) b, 2))-c*d;
  63.                                 input.text = "("+a+"+"+b+")"+"²"+"-"+c+"("+d+")"+"=";
  64.                                 Debug.Log("Problem ID: 83");
  65.                             }
  66.                             // 50% of being (a-b)²[]c(d)
  67.                         } else {
  68.                             // 50% of being (a-b)²+c(d)
  69.                             if(UnityEngine.Random.Range(0,101)>50){
  70.                                 ans = ((int) Mathf.Pow((float) a- (float) b, 2))+c*d;
  71.                                 input.text = "("+a+"-"+b+")"+"²"+"+"+c+"("+d+")"+"=";
  72.                                 Debug.Log("Problem ID: 84");
  73.                                 // 50% of being (a-b)²-c(d)
  74.                             } else {
  75.                                 ans = ((int) Mathf.Pow((float) a- (float) b, 2))-c*d;
  76.                                 input.text = "("+a+"-"+b+")"+"²"+"-"+c+"("+d+")"+"=";
  77.                                 Debug.Log("Problem ID: 85");
  78.                             }
  79.                         }
  80.                     }
  81.                     //50% of being division
  82.                 } else {
  83.                     a = UnityEngine.Random.Range(0,13);
  84.                     b = UnityEngine.Random.Range(0,13);
  85.                     c = UnityEngine.Random.Range(0,13);
  86.                     d = UnityEngine.Random.Range(0,13);
  87.                          // 50% chance of being (a[]b)²/(c)[]d
  88.                     if(UnityEngine.Random.Range(0,101) > 50){
  89.                             // 50% chance of being (a+b)²/(c)[]d
  90.                         if(UnityEngine.Random.Range(0,101)>50){
  91.                                 // 50% of being (a+b)²/(c)+d
  92.                             if(UnityEngine.Random.Range(0,101)>50){
  93.                                 divisionQuickLoop(14);
  94.                                 ans = ((int) Mathf.Pow((float) a+ (float) b, 2))/c+d;
  95.                                 input.text = "("+a+"+"+b+")"+"²"+"/"+"("+c+")"+"+"+d+"=";
  96.                                 Debug.Log("Problem ID: 86");
  97.                                 // 50% of being (a+b)²/(c)-d
  98.                             } else {
  99.                                 divisionQuickLoop(14);
  100.                                 ans = ((int) Mathf.Pow((float) a+ (float) b, 2))*c-d;
  101.                                 input.text = "("+a+"+"+b+")"+"²"+"/"+"("+c+")"+"-"+d+"=";
  102.                                 Debug.Log("Problem ID: 87");
  103.                             }
  104.                             // 50% of being (a-b)²/(c)[]d
  105.                         } else {
  106.                             // 50% of being (a-b)²/(c)+d
  107.                             if(UnityEngine.Random.Range(0,101)>50){
  108.                                 divisionQuickLoop(15);
  109.                                 ans = ((int) Mathf.Pow((float) a- (float) b, 2))/c+d;
  110.                                 input.text = "("+a+"-"+b+")"+"²"+"/"+"("+c+")"+"+"+d+"=";
  111.                                 Debug.Log("Problem ID: 88");
  112.                                 // 50% of being (a-b)²/(c)-d
  113.                             } else {
  114.                                 divisionQuickLoop(15);
  115.                                 ans = ((int) Mathf.Pow((float) a- (float) b, 2))/c-d;
  116.                                 input.text = "("+a+"-"+b+")"+"²"+"/"+"("+c+")"+"-"+d+"=";
  117.                                 Debug.Log("Problem ID: 89");
  118.                             }
  119.                         }
  120.                         // 50% chance of being (a[]b)²[]c/(d)
  121.                     } else {
  122.                         // 50% chance of being (a+b)²[]c/(d)
  123.                         if(UnityEngine.Random.Range(0,101)>50){
  124.                                 // 50% of being (a+b)²+c/(d)
  125.                             if(UnityEngine.Random.Range(0,101)>50){
  126.                                 divisionQuickLoop(3);
  127.                                 ans = ((int) Mathf.Pow((float) a+ (float) b, 2))+c/d;
  128.                                 input.text = "("+a+"+"+b+")"+"²"+"+"+c+"/"+"("+d+")"+"=";
  129.                                 Debug.Log("Problem ID: 90");
  130.                                 // 50% of being (a+b)²-c/(d)
  131.                             } else {
  132.                                 divisionQuickLoop(3);
  133.                                 ans = ((int) Mathf.Pow((float) a+ (float) b, 2))-c/d;
  134.                                 input.text = "("+a+"+"+b+")"+"²"+"-"+c+"/"+"("+d+")"+"=";
  135.                                 Debug.Log("Problem ID: 91");
  136.                             }
  137.                             // 50% of being (a-b)²[]c/(d)
  138.                         } else {
  139.                             // 50% of being (a-b)²+c/(d)
  140.                             if(UnityEngine.Random.Range(0,101)>50){
  141.                                 divisionQuickLoop(3);
  142.                                 ans = ((int) Mathf.Pow((float) a- (float) b, 2))+c/d;
  143.                                 input.text = "("+a+"-"+b+")"+"²"+"+"+c+"/"+"("+d+")"+"=";
  144.                                 Debug.Log("Problem ID: 92");
  145.                                 // 50% of being (a-b)²-c/(d)
  146.                             } else {
  147.                                 divisionQuickLoop(3);
  148.                                 ans = ((int) Mathf.Pow((float) a+ (float) b, 2))-c/d;
  149.                                 input.text = "("+a+"-"+b+")"+"²"+"-"+c+"/"+"("+d+")"+"=";
  150.                                 Debug.Log("Problem ID: 93");
  151.                             }
  152.                         }
  153.                     }
  154.                 }
  155.             }
  156.             // 33% of being a[](b[]c)²[]d
  157.             else if (UnityEngine.Random.Range(0,101) > 33)
  158.             { // code not shown }
  159.             // 33% of being a[]b[](c[]d)²
  160.             else
  161.             { //code not show }
  162.              
  163.             break;
  164.     }
  165. }
captcha