CSnathan

Skyscraper close

Apr 6th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.32 KB | None | 0 0
  1. //*****************************************************
  2. // Nathan Schnitzer
  3. // Skyscraper.java
  4. // 4/6/17
  5. // Contest #4
  6. //******************************************************
  7.  
  8. import java.util.Scanner;
  9. import java.util.Arrays;
  10. import java.util.ArrayList;
  11. public class Skyscraper {
  12.  
  13.     public static void main(String[] args) {
  14.         //Create Scanner Object
  15.         Scanner scan = new Scanner(System.in);
  16.        
  17.         //Create array of all possible combinations (a,b,c,d,e)
  18.         int[] combos = {12345, 12354, 12435, 12453, 12534, 12543, 13245, 13254, 13425, 13452, 13524, 13542, 14235, 14253, 14325, 14352, 14523, 14532, 15234, 15243, 15324, 15342, 15423, 15432, 21345, 21354, 21435, 21453, 21534, 21543, 23145, 23154, 23415, 23451, 23514, 23541, 24135, 24153, 24315, 24351, 24513, 24531, 25134, 25143, 25314, 25341, 25413, 25431, 31245, 31254, 31425, 31452, 31524, 31542, 32145, 32154, 32415, 32451, 32514, 32541, 34125, 34152, 34215, 34251, 34512, 34521, 35124, 35142, 35214, 35241, 35412, 35421, 41235, 41253, 41325, 41352, 41523, 41532, 42135, 42153, 42315, 42351, 42513, 42531, 43125, 43152, 43215, 43251, 43512, 43521, 45123, 45132, 45213, 45231, 45312, 45321, 51234, 51243, 51324, 51342, 51423, 51432, 52134, 52143, 52314, 52341, 52413, 52431, 53124, 53142, 53214, 53241, 53412, 53421, 54123, 54132, 54213, 54231, 54312, 54321};
  19.        
  20.         //Prompt for the left clue
  21.         System.out.println("Please enter left clue");
  22.         int leftClue = scan.nextInt();
  23.        
  24.         //Prompt for the right clue
  25.         System.out.println("Please enter right clue");
  26.         int rightClue = scan.nextInt();
  27.        
  28.         //Create ArrayList object
  29.         ArrayList<Integer> goodcombos = new ArrayList<Integer>();
  30.        
  31.         //Create a for loop to test combos
  32.         for (int k = 0; k < 120; k++)
  33.         {
  34.             int rightViewCount = 1, leftViewCount = 1;
  35.             boolean testRight = false;
  36.             String strValue = Integer.toString(combos[k]);
  37.            
  38.                 int place1, place2, place3, place4, place5;
  39.                 place1 = Character.getNumericValue(strValue.charAt(0));
  40.                 place2 = Character.getNumericValue(strValue.charAt(1));
  41.                 place3 = Character.getNumericValue(strValue.charAt(2));
  42.                 place4 = Character.getNumericValue(strValue.charAt(3));
  43.                 place5 = Character.getNumericValue(strValue.charAt(4));
  44.                
  45.                 //5 is tallest building while 1 is smallest //place shows position
  46.                 if (place1 == 5)
  47.                     leftViewCount = 1; //Can only see tallest building in front
  48.                 else if (place2 == 5)
  49.                     leftViewCount = 2;
  50.                 else
  51.                 {
  52.                     if (place2 > place1) //Can see building #2 and #1
  53.                     {
  54.                         leftViewCount++;
  55.                         if (place3 > place2) //Can see buildings #1,2,3
  56.                         {
  57.                             leftViewCount++;
  58.                             if(place4 > place3) //Can see #1,2,3,4
  59.                             {
  60.                                 leftViewCount++;
  61.                                 if (place5 > place4) //Can see #1,2,3,4,5
  62.                                 {
  63.                                     leftViewCount = 5;
  64.                                     rightViewCount = 1;
  65.                                     testRight = true;
  66.                                 }
  67.                             }
  68.                             else
  69.                             {
  70.                                 if (place5 > place3) //Can see #1,2,3,5
  71.                                 {
  72.                                     leftViewCount++;
  73.                                 }
  74.                             }
  75.                         }
  76.                         else
  77.                         {
  78.                             if (place4 > place2) //Can see buildings #1,2,4
  79.                             {
  80.                                 leftViewCount++;
  81.                                 if (place5 > place4) //Can see #1,2,4,5
  82.                                 {
  83.                                     leftViewCount++;
  84.                                 }
  85.                             }
  86.                             else
  87.                             {
  88.                                 if (place5 > place2) //Can see buildings #1,2,5
  89.                                 {
  90.                                     leftViewCount = 5;
  91.                                     rightViewCount = 1;
  92.                                 }
  93.                             }
  94.                         }
  95.                     }
  96.                     else
  97.                     {
  98.                         if (place3 > place1) //Can see#1,3
  99.                         {
  100.                             leftViewCount++;
  101.                             if (place4 > place3) //Can see #1,3,4
  102.                             {
  103.                                 leftViewCount++;
  104.                                 if (place5 > place4) //Can see #1,3,4,5
  105.                                 {
  106.                                     leftViewCount++;
  107.                                 }
  108.                             }
  109.                             else
  110.                             {
  111.                                 if (place5 > place3) //Can see #1,3,5
  112.                                 {
  113.                                     leftViewCount++;
  114.                                 }
  115.                             }
  116.                         }
  117.                         else
  118.                         {
  119.                             if (place4 > place1) //Can see #1,4
  120.                             {
  121.                                 leftViewCount++;
  122.                                 if (place5 > place4) //Can see #1,4,5
  123.                                     leftViewCount++;
  124.                             }
  125.                             else
  126.                                 leftViewCount = 2; //Can see #1,5
  127.                         }
  128.                     }
  129.                 }
  130.                
  131.                 //Test right view
  132.                 if (testRight == false)
  133.                 {
  134.                     //5 is tallest building while 1 is smallest //place shows position from right
  135.                     if (place5 ==5)
  136.                         rightViewCount = 1; //Can only see tallest building on right
  137.                     else if (place4 == 5)
  138.                         rightViewCount = 2;
  139.                     else
  140.                     {
  141.                         if (place4 > place5) //Can see building #2 and #1
  142.                         {
  143.                             rightViewCount++;
  144.                             if (place3 > place4) //Can see buildings #1,2,3
  145.                             {
  146.                                 rightViewCount++;
  147.                                 if(place2 > place3) //Can see #1,2,3,4
  148.                                 {
  149.                                     rightViewCount++;
  150.                                     if (place1 > place2) //Can see #1,2,3,4,5
  151.                                     {
  152.                                         rightViewCount = 5;
  153.                                         leftViewCount = 1;
  154.                                        
  155.                                     }
  156.                                 }
  157.                                 else
  158.                                 {
  159.                                     if (place1 > place3) //Can see #1,2,3,5
  160.                                     {
  161.                                         rightViewCount++;
  162.                                     }
  163.                                 }
  164.                             }
  165.                             else
  166.                             {
  167.                                 if (place2 > place4) //Can see buildings #1,2,4
  168.                                 {
  169.                                     rightViewCount++;
  170.                                     if (place1 > place2) //Can see #1,2,4,5
  171.                                     {
  172.                                         rightViewCount++;
  173.                                     }
  174.                                 }
  175.                                 else
  176.                                 {
  177.                                     if (place1 > place4) //Can see buildings #1,2,5
  178.                                     {
  179.                                         rightViewCount = 5;
  180.                                         leftViewCount = 1;
  181.                                     }
  182.                                 }
  183.                             }
  184.                         }
  185.                         else
  186.                         {
  187.                             if (place3 > place5) //Can see#1,3
  188.                             {
  189.                                 rightViewCount++;
  190.                                 if (place2 > place3) //Can see #1,3,4
  191.                                 {
  192.                                     rightViewCount++;
  193.                                     if (place1 > place2) //Can see #1,3,4,5
  194.                                     {
  195.                                         rightViewCount++;
  196.                                     }
  197.                                 }
  198.                                 else
  199.                                 {
  200.                                     if (place1 > place3) //Can see #1,3,5
  201.                                     {
  202.                                         rightViewCount++;
  203.                                     }
  204.                                 }
  205.                             }
  206.                             else
  207.                             {
  208.                                 if (place2 > place5) //Can see #1,4
  209.                                 {
  210.                                     rightViewCount++;
  211.                                     if (place1 > place2) //Can see #1,4,5
  212.                                         rightViewCount++;
  213.                                 }
  214.                                 else
  215.                                     rightViewCount = 2; //Can see #1,5
  216.                             }
  217.                         }
  218.                     }
  219.                 }
  220.                 if (rightViewCount == rightClue && leftViewCount == leftClue)
  221.                 {
  222.                     goodcombos.add(combos[k]);
  223.                     System.out.println(leftViewCount + "   " + rightViewCount);
  224.                 }
  225.                
  226.         }
  227.         System.out.println(goodcombos);
  228.         System.out.println(goodcombos.size());
  229.  
  230.     }
  231.  
  232. }
Advertisement
Add Comment
Please, Sign In to add comment