Inheritance: MonoBehaviour
Exemplo n.º 1
0
        public async Task <bool> QuantumSolve(int[,] puzzle, SimulatorBase sim)
        {
            int size = puzzle.GetLength(0);

            FindEdgesAndInitialNumberConstraints(
                puzzle,
                size,
                out var emptySquareEdges,
                out var startingNumberConstraints,
                out var emptySquares
                );
            var emptySquareEdgesQArray          = new QArray <(long, long)>(emptySquareEdges);
            var startingNumberConstraintsQArray = new QArray <(long, long)>(startingNumberConstraints);

            var(foundSolution, solution) = await SolvePuzzle.Run(sim, emptySquares.Count, size, emptySquareEdgesQArray, startingNumberConstraintsQArray);

            if (foundSolution)
            {
                foreach (var(emptySquare, completion) in Enumerable.Zip(emptySquares, solution))
                {
                    puzzle[emptySquare.Row, emptySquare.Column] = (int)completion + 1;
                }
                Console.WriteLine("Solved puzzle.");
            }
            return(foundSolution);
        }
Exemplo n.º 2
0
        public async Task <bool> QuantumSolve(int[,] puzzle)
        {
            // Parse the puzzle into constraints.
            int size = puzzle.GetLength(0);

            FindEdgesAndInitialNumberConstraints(
                puzzle,
                size,
                out var emptySquareEdges,
                out var startingNumberConstraints,
                out var emptySquares
                );
            var emptySquareEdgesQArray          = new QArray <(long, long)>(emptySquareEdges);
            var startingNumberConstraintsQArray = new QArray <(long, long)>(startingNumberConstraints);

            // Estimate the resources required for the solution.
            var estimator = new ResourcesEstimator();

            SolvePuzzle.Run(estimator, emptySquares.Count, size, emptySquareEdgesQArray, startingNumberConstraintsQArray).Wait();
            Console.WriteLine($"The number of qubits estimated: {estimator.Data.Rows.Find("QubitCount")["Sum"]}");

            // Solve the puzzle!
            var sim = new QuantumSimulator(throwOnReleasingQubitsNotInZeroState: true);

            var(foundSolution, solution) = await SolvePuzzle.Run(sim, emptySquares.Count, size, emptySquareEdgesQArray, startingNumberConstraintsQArray);

            if (foundSolution)
            {
                foreach (var(emptySquare, completion) in Enumerable.Zip(emptySquares, solution))
                {
                    puzzle[emptySquare.Row, emptySquare.Column] = (int)completion + 1;
                }
            }
            return(foundSolution);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Question 1");
            int[] l1 = new int[] { 5, 6, 6, 9, 9, 12 };
            int target = 9;
            int[] r = TargetRange(l1, target);
            // formatting the output array
            string Q1output = "[";
            foreach (int n in r)
            {
                Q1output += n + ",";
            }
            Q1output = (Q1output.Remove(Q1output.Length - 1)) + "]";
            Console.WriteLine(Q1output);

            Console.WriteLine("Question 2");
            string s = "University of South Florida";
            string rs = StringReverse(s);
            Console.WriteLine(rs);

            Console.WriteLine("Question 3");
            int[] l2 = new int[] { 2, 2, 3, 5, 6 };
            int sum = MinimumSum(l2);
            Console.WriteLine(sum);

            Console.WriteLine("Question 4");
            string s2 = "Dell";
            string sortedString = FreqSort(s2);
            Console.WriteLine(sortedString);

            Console.WriteLine("Question 5-Part 1");
            int[] nums1 = { 1, 2, 2, 1 };
            int[] nums2 = { 2, 2 };
            int[] intersect1 = Intersect1(nums1, nums2);
            Console.WriteLine("Part 1- Intersection of two arrays is: ");
            DisplayArray(intersect1);
            Console.WriteLine("\n");

            Console.WriteLine("Question 5-Part 2");
            int[] intersect2 = Intersect2(nums1, nums2);
            Console.WriteLine("Part 2- Intersection of two arrays is: ");
            DisplayArray(intersect2);
            Console.WriteLine("\n");

            Console.WriteLine("Question 6");
            char[] arr = new char[] { 'a', 'g', 'h', 'a' };
            int k = 3;
            Console.WriteLine(ContainsDuplicate(arr, k));

            Console.WriteLine("Question 7");
            int rodLength = 4;
            int priceProduct = GoldRod(rodLength);
            Console.WriteLine(priceProduct);

            Console.WriteLine("Question 8");
            // Create string array and string keyword to hold values for question 8
            string[] userDict = new string[] { "rocky", "usf", "hello", "apple" };
            string keyword = "hhllo";
            // Write results for question 8
            Console.WriteLine(DictSearch(userDict, keyword));
            Console.WriteLine("Question 9");
            // Call method for question 9
            SolvePuzzle value = new SolvePuzzle();
            value.Calculate();

            Console.ReadLine();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Question 1");
            int[] l1     = new int[] { 5, 6, 6, 9, 9, 12 };
            int   target = 9;

            int[] r = TargetRange.TargetRangeSoln(l1, target);
            // Write your code to print range r here
            Console.WriteLine("[" + r[0] + "," + r[1] + "]");

            Console.WriteLine("Question 2");
            String s  = "University of South Florida";
            String rs = StringReverse.StringReverseSoln(s);

            Console.WriteLine(rs);

            Console.WriteLine("Question 3");
            int[] l2  = new int[] { 2, 2, 3, 5, 6 };
            int   sum = MinimumSum.MinimumSumSoln(l2);

            Console.WriteLine(sum);

            Console.WriteLine("Question 4");
            string s2           = "Dell";
            string sortedString = FreqSort.FreqSortSoln(s2);

            Console.WriteLine(sortedString);

            Console.WriteLine("Question 5-Part 1");
            int[] nums1 = { 1, 1, 2, 2, 2 };
            int[] nums2 = { 2, 2 };
            //int[] nums1 = { 3, 6, 6, 3};
            //int[] nums2 = { 6, 3, 6, 7, 3 };
            int[] intersect1 = Intersect.Intersect1(nums1, nums2);
            Console.WriteLine("Part 1- Intersection of two arrays is: ");
            Intersect.DisplayArray(intersect1); Console.WriteLine("\n");
            Console.WriteLine("Question 5-Part 2");
            int[] intersect2 = Intersect.Intersect2(nums1, nums2);
            Console.WriteLine("Part 2- Intersection of two arrays is: ");
            Intersect.DisplayArray(intersect2);
            Console.WriteLine("\n");

            Console.WriteLine("Question 6");
            char[] arr = new char[] { 'a', 'g', 'h', 'a' };
            int    k   = 3; Console.WriteLine(ContainsDuplicate.ContainsDuplicateSoln(arr, k));

            Console.WriteLine("Question 7");
            int rodLength    = 4;
            int priceProduct = GoldRod.GoldRodSoln(rodLength);

            Console.WriteLine(priceProduct);

            Console.WriteLine("Question 8");
            string[] userDict = new string[] { "rocky", "usf", "hello", "apple" };
            string   keyword  = "hhllo";

            Console.WriteLine(DictSearch.DictSearchSoln(userDict, keyword));

            Console.WriteLine("Question 9");
            SolvePuzzle.SolvePuzzleSoln();
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Question 1");
            int[] l1     = new int[] { 5, 6, 6, 9, 9, 12 };
            int   target = 9;

            int[] r = TargetRange.TargetRangeSoln(l1, target);
            // Write your code to print range r here
            Console.WriteLine("[" + r[0] + "," + r[1] + "]");

            Console.WriteLine("Question 2");
            String s  = "University of South Florida";
            String rs = StringReverse.StringReverseSoln(s);

            Console.WriteLine(rs);

            Console.WriteLine("Question 3");
            int[] l2  = new int[] { 2, 2, 2, 4, 5, 7 };
            int   sum = MinimumSum.MinimumSumSoln(l2);

            Console.WriteLine("The Sum is:  " + sum);

            Console.WriteLine("Question 4");
            string s2           = "Dell";
            string sortedString = FreqSort.FreqSortSoln(s2);

            Console.WriteLine(sortedString);

            Console.WriteLine("Question 5-Part 1");
            int[] nums1 = { 1, 1, 2, 2, 2 };
            int[] nums2 = { 2, 2 };
            try
            {
                int[] intersect1 = Intersect.Intersect1(nums1, nums2);
                Console.WriteLine("Part 1- Intersection of two arrays is: ");
                Intersect.DisplayArray(intersect1); Console.WriteLine("\n");
                Console.WriteLine("Question 5-Part 2");
                int[] intersect2 = Intersect.Intersect2(nums1, nums2);
                Console.WriteLine("Part 2- Intersection of two arrays is: ");
                Intersect.DisplayArray(intersect2);
                Console.WriteLine("\n");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("Question 6");
            char[] arr = new char[] { 'a', 'g', 'h', 'a' };
            int    k   = 3; Console.WriteLine(ContainsDuplicate.ContainsDuplicateSoln(arr, k));

            Console.WriteLine("Question 7");
            int rodLength    = 15;
            int priceProduct = GoldRod.GoldRodSoln(rodLength);

            Console.WriteLine(priceProduct);

            Console.WriteLine("Question 8");
            string[] userDict = new string[] { "rocky", "usf", "hello", "apple" };
            string   keyword  = "hhllo";

            try
            {
                if (userDict.Length > 0)
                {
                    Console.WriteLine(DictSearch.DictSearchSoln(userDict, keyword));
                }
                else
                {
                    Console.WriteLine("Enter an array with at least one element.");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("Question 9");
            Console.WriteLine(" ");
            try
            {
                SolvePuzzle.SolvePuzzleSoln();
            }catch (Exception e)
            {
                Debug.WriteLine(e.StackTrace);
                Console.WriteLine("Error computing the solution.");
            }
        }