Exemplo n.º 1
0
    public bool ProveB()
    {
        string[] lines = File.ReadAllLines(ExampleB, Encoding.UTF8);

        var tests = new Dictionary <IntType, IntType>();

        tests[7] = 999;
        tests[8] = 1000;
        tests[9] = 1001;

        foreach (var line in lines)
        {
            var inputs   = line.Split(" ");
            var input    = IntType.Parse(inputs[0]);
            var expected = IntType.Parse(inputs[1]);
            var program  = Intcode.ParseInput(inputs[2]);
            var output   = RunProgram(ref program, input);
            if (output != expected)
            {
                Console.WriteLine();
                Console.WriteLine($"  Line:       {inputs[2]}");
                Console.WriteLine($"  Input:      {input}");
                Console.WriteLine($"  Expected:   {expected}");
                Console.WriteLine($"  Actual:     {output}");

                return(false);
            }
        }
        return(true);
    }
Exemplo n.º 2
0
        private void findPrimesButton_Click(object sender, EventArgs e)
        {
            Int topBound;

            try
            {
                topBound = Int.Parse(maxNumberInput.Text);
            }
            catch
            {
                MessageBox.Show("Input correct max number!");
                return;
            }

            if (topBound <= 0)
            {
                MessageBox.Show("Max number should be more than 0!");
                return;
            }


            EratostheneSieve primeGetter = new EratostheneSieve();

            List <Int> primes = primeGetter.FindPrimes(topBound);

            // remove bad and old data from output
            primeNumbersOutput.Text = "";
            foreach (var primeNumber in primes)
            {
                primeNumbersOutput.Text += primeNumber.ToString() + " ";
            }
        }
Exemplo n.º 3
0
    public static IntType[] ParseInput(string input)
    {
        var list   = new List <IntType>();
        var inputs = input.Split(",");

        foreach (var i in inputs)
        {
            list.Add(IntType.Parse(i));
        }
        return(list.ToArray());
    }
Exemplo n.º 4
0
 public TokenNumber(TokenType p_Type, int p_line, int p_column, String p_value) : base(p_Type, p_line, p_column)
 {
     try {
         integerValue = Integer.Parse(p_value);
         type         = integerValue.GetType();
     } catch (FormatException) {
         try {
             floatValue = Float.Parse(p_value);
             type       = floatValue.GetType();
         } catch (FormatException) {
             Console.WriteLine("{0}: Bad Format", p_value);
         } catch (OverflowException) {
             Console.WriteLine("{0}: Overflow", p_value);
         }
     } catch (OverflowException) {
         Console.WriteLine("{0}: Overflow", p_value);
     }
 }
Exemplo n.º 5
0
    private bool ProveB()
    {
        string[] lines = File.ReadAllLines(ExampleA, Encoding.UTF8);
        foreach (var line in lines)
        {
            var tokens = line.Split(" ");

            var answer = IntType.Parse(tokens[0]);

            // Array of 5 IntType
            var order = tokens[1].Split(",").Select(t => IntType.Parse(t));

            var power = ComputePowerFeedback(order.ToArray(), tokens[2]);

            if (power != answer)
            {
                Console.WriteLine($"{power} should have been {answer}, {tokens[2]}");
                return(false);
            }
        }

        return(true);
    }
Exemplo n.º 6
0
        public static (INT qty, string name) ParseOneComponent(string inp)
        {
            var s   = inp.Trim().Split(' ');
            var qty = INT.Parse(s[0]);

            return(qty, s[1]);