Skip to content

Instantly share code, notes, and snippets.

@acchandl
Last active January 24, 2018 14:20
Show Gist options
  • Save acchandl/a3eed905fe172381e7c4802c94057d08 to your computer and use it in GitHub Desktop.
Save acchandl/a3eed905fe172381e7c4802c94057d08 to your computer and use it in GitHub Desktop.

Question One

  
using System;

class Program
{
    static void Main()
    {
      /*** loop through numbers 1-100 and use the modulo operator to find
           mulpitles of any number, in this case, 3 and 5. ***/
           
      for (int i = 1; i <= 100; i++)
      {
           string loop = "";  
           if (i % 3 == 0)  
            {  
              loop += "Explorica";  
            }  
           if (i % 5 == 0)  
            {  
              loop += "Tours";  
            }  
           if (loop.Length == 0)  
            {  
              loop = i.ToString();  
            }  
        
            Console.WriteLine(loop);
      }
 
    }
}


  

Question Two

using System;

namespace WSQuestions
{
    class Triangles
    {

        public void DrawTop()
        {

            int row;
            int column;
            int space;
            
            /*** first 6 lines of diamond-
                 will add a star for every column <= (2 * row) - 1, where row
                 will increment***/
                 
            for (row = 1; row <= 6; row++)
            {
                for (space = 6; space > row; space--)
                    Console.Write(" ");

                for (column = 1; column <= (2 * row) - 1; column++)
                    Console.Write("*");

                Console.WriteLine();
            }
        }

           /*** last 5 lines of diamond-
                 will add a star for every column <= (2 * row) - 1, where row
                 will decrement ***/
                 
           public void DrawBottom()
           {
               int row;
               int column;
               int space;

               for (row = 5; row >= 1; row--)
               {
                   for (space = 6; space > row; space--)
                       Console.Write(" ");

                   for (column = 1; column <= (2 * row) - 1; column++)
                       Console.Write("*");

                   Console.WriteLine();
               }
           }
       }

    class Program
    {
        static void Main()
        {
            Triangles app = new Triangles();
            
            //first pattern
            app.DrawTop();
            
            //second pattern
            app.DrawTop();
            app.DrawBottom();
        }
    }
}

Question Three

Given a File "text.txt":

2
##
######
####
#
######
#######
###

Where N = 2. Find the minimum and maximum lengths of N joined together.

using System;
using System.IO;
using System.Linq;


namespace WSQuestions
{
    class Program
    {   
        static void Main(string[] args)
        {
            // Read in the file input
            string[] textFile = File.ReadAllLines("text.txt");

            // Skip the first line of the input file
            textFile = textFile.Skip(1).ToArray();
          
            //initialize variables
            string firstMinVal = textFile[0];
            string secondMinVal = "";
            string firstMaxVal = textFile[0];
            string secondMaxVal = "";
            

            /***  Iterate over strings in file-
                  first traversal finds minimum, second scan 
                  finds smallest length greater than the minimum ***/

             foreach (string text in textFile)
             {
                Console.WriteLine(text.Length);
                
                 if (text.Length < firstMinVal.Length)
                {
                    secondMinVal = firstMinVal;
                    firstMinVal = text;
                }

               /***  Iterate over strings in file-
                     first traversal finds maximum, second scan
                     finds largest length greater than the maximum***/

                if (text.Length > firstMaxVal.Length)
                {
                    secondMaxVal = firstMaxVal;
                    firstMaxVal = text;
                }
             }

             // Join the minimums and maximums for final calculation
            int finalMinVal = firstMinVal.Length + secondMinVal.Length;
            int finalMaxVal = firstMaxVal.Length + secondMaxVal.Length;

            // Write results
            Console.WriteLine("Result: " + "\r\n" + "Min: " + finalMinVal 
                              + " | Max: " + finalMaxVal);
            
            Console.ReadLine();
           
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment