Jump to content

Hi all,

 

I wanted to code something so i challenged myself to writing a program in C# based on the Countdown Program Math 

however coding with Flu is not the best idea! :(

 

1. Creating random numbers based on user input in done [user chooses Highest Number any number can be] & user chooses how many numbers their will be]

2. What i'm struggling with is the best way to Create As random as possible equation for the user to work out. i created a quick mock-up to test a theory which did not work

3. i want to pick a random number from the array + random operator then put the formula & Answer into different strings to hide from user.

 

 

For anyone that has not seen Countdown

Only Rule i believe is:

1. Only each number once

namespace Math_Trainner
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        List<int> Number_list = new List<int>();
        List<string> MathOperation = new List<string>(new string[] { "+", "/", "-","*" });
        List<string> Answer = new List<string>();
        int loop = 0;
        int HighestNumber = 0;
        int NumberAmount = 0;
        string MathAnswer;
            
        private void RandomNumber()
        {
            int HighestNumber = Int32.Parse(Max_Number.Text);
            int NumberAmount = Int32.Parse(Max_Ints.Text);
            Random rnd = new Random();

            while (loop < NumberAmount)
            {  
                int Number = rnd.Next(0, HighestNumber);
                Number_list.Add(Number);
                Listbox.Items.Add(Number);
                loop++;
            }

        }

        private void CreateMaths()
        {
            


        }

        private void Start_Click(object sender, EventArgs e)
        {
            RandomNumber();
            CreateMaths();
        }
    }
}

 

Link to comment
https://linustechtips.com/topic/785690-c-challenge-help/
Share on other sites

Link to post
Share on other sites

3 hours ago, smogsy said:

Hi all,

 

I wanted to code something so i challenged myself to writing a program in C# based on the Countdown Program Math 

however coding with Flu is not the best idea! :(

 

1. Creating random numbers based on user input in done [user chooses Highest Number any number can be] & user chooses how many numbers their will be]

2. What i'm struggling with is the best way to Create As random as possible equation for the user to work out. i created a quick mock-up to test a theory which did not work

3. i want to pick a random number from the array + random operator then put the formula & Answer into different strings to hide from user.

 

 

For anyone that has not seen Countdown

Only Rule i believe is:

1. Only each number once


namespace Math_Trainner
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        List<int> Number_list = new List<int>();
        List<string> MathOperation = new List<string>(new string[] { "+", "/", "-","*" });
        List<string> Answer = new List<string>();
        int loop = 0;
        int HighestNumber = 0;
        int NumberAmount = 0;
        string MathAnswer;
            
        private void RandomNumber()
        {
            int HighestNumber = Int32.Parse(Max_Number.Text);
            int NumberAmount = Int32.Parse(Max_Ints.Text);
            Random rnd = new Random();

            while (loop < NumberAmount)
            {  
                int Number = rnd.Next(0, HighestNumber);
                Number_list.Add(Number);
                Listbox.Items.Add(Number);
                loop++;
            }

        }

        private void CreateMaths()
        {
            


        }

        private void Start_Click(object sender, EventArgs e)
        {
            RandomNumber();
            CreateMaths();
        }
    }
}

 

Ooooookey dokey, you got my attention. 


It is an interesting idea, a difficult one, but quite cool.

 

The way I could see the algorithm work is:

 

1. Choose random number of brackets (0-3)

2. For each bracket choose number of elements that it has to contain (if 3 brackets chosen then each of them must contain 2 elements, if 2 chosen then it can be 2-2, 2-3, 2-4 or 3-3 and if one chosen then it could be 2, 3, 4 or 5)

3. Choose elements for each bracket

4. Choose positions of elements in the brackets

5. Choose placement of elements in the equation (brackets and numbers)

6. Choose operators between elements (This is where it looses its shit kind of)

 

So:

 

Random numbers:
25 50 75 100 3 6

Step 1:

Number of brackets: 1
Step 2:

Number of elements in the bracket: 2
Step 3:

Numbers in the bracket: 100, 6
Step 4:

Position of elements in the bracket (either 100, 6 or 6, 100): 100, 6
Step 5:
Positions of all elements:

0|	(100 ? 6) 
 ?
1|	3 
 ?
2|	75 
 ?
3|	50 
 ? 
4|	25
Step 6:

Operations between numbers:

(100 + 6) * 3 * 75 - 50 / 25

The biggest problem is what to do if some of the numbers are not divisible by each other and how to not get an answer like 943,928837361009 or something like this (unless you are telling the user to round the value in which case it's no longer a problem). What I would also recommend is letting user choose a random seed, so program would generate the same equation every time. 

 

My answer may be total bullshit since I didn't test it or anything like that.


It's a fun project and if you actually do it they definitely post it here, I would love to play it ;)

Try, fail, learn, repeat...

Link to comment
https://linustechtips.com/topic/785690-c-challenge-help/#findComment-9902199
Share on other sites

Link to post
Share on other sites

I started coding my version and quickly realized its not as simple as I thought, it will take me some time... The only hard part (in my eyes) is checking that the numbers can be divided by one another. Give me a couple of hours (I need to eat) and I'll see what I can do :) Awesome challenge though

Quote or tag if you want me to answer! PM me if you are in a real hurry!

Why do Java developers wear glasses? Because they can't C#!

 

My Machines:

The Gaming Rig:

Spoiler

-Processor: i5 6600k @4.6GHz

-Graphics: GTX1060 6GB G1 Gaming

-RAM: 2x8GB HyperX DDR4 2133MHz

-Motherboard: Asus Z170-A

-Cooler: Corsair H100i

-PSU: EVGA 650W 80+bronze

-AOC 1080p ultrawide

My good old laptop:

Spoiler

Lenovo T430

-Processor: i7 3520M

-4GB DDR3 1600MHz

-Graphics: intel iGPU :(

-Not even 1080p

 

Link to comment
https://linustechtips.com/topic/785690-c-challenge-help/#findComment-9902251
Share on other sites

Link to post
Share on other sites

49 minutes ago, dany_boy said:

I started coding my version and quickly realized its not as simple as I thought, it will take me some time... The only hard part (in my eyes) is checking that the numbers can be divided by one another. Give me a couple of hours (I need to eat) and I'll see what I can do :) Awesome challenge though

If (Number1 % Number2 == 0) ?

Link to comment
https://linustechtips.com/topic/785690-c-challenge-help/#findComment-9902414
Share on other sites

Link to post
Share on other sites

1 minute ago, AUniqueName said:

If (Number1 % Number2 == 0) ?

I mean how to store the valid divisions, parse them , and perform the arithmetics following the correct precedence and valid divisions

Quote or tag if you want me to answer! PM me if you are in a real hurry!

Why do Java developers wear glasses? Because they can't C#!

 

My Machines:

The Gaming Rig:

Spoiler

-Processor: i5 6600k @4.6GHz

-Graphics: GTX1060 6GB G1 Gaming

-RAM: 2x8GB HyperX DDR4 2133MHz

-Motherboard: Asus Z170-A

-Cooler: Corsair H100i

-PSU: EVGA 650W 80+bronze

-AOC 1080p ultrawide

My good old laptop:

Spoiler

Lenovo T430

-Processor: i7 3520M

-4GB DDR3 1600MHz

-Graphics: intel iGPU :(

-Not even 1080p

 

Link to comment
https://linustechtips.com/topic/785690-c-challenge-help/#findComment-9902423
Share on other sites

Link to post
Share on other sites

i missed a huge flaw. in coutdown you must select big little or small numbers and how many

 

so an update the GUI

uh29QKA.jpg

 

The code is optimized be aware. Just to show you where i'm at. Probably get the random numbers into one function when i have not got the flu!

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Math_Trainner
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        List<int> Number_list = new List<int>();
        List<string> MathOperation = new List<string>(new string[] { "+", "/", "-","*" });
        List<string> Answer = new List<string>();
        int loop = 0;


        private void RandomNumber_low()
        {
            loop = 0;
            int Low_Num = Int32.Parse(Low_Number.Text);

            Random rnd = new Random();

            while (loop < Low_Num)
            {  
                int Number = rnd.Next(0, 10);
                Number_list.Add(Number);
                Listbox.Items.Add(Number);
                loop++;
            }

        }


        private void RandomNumber_Medium()
        {
            loop = 0;
            int Medium_Num = Int32.Parse(Medium_Number.Text);

            Random rnd = new Random();

            while (loop < Medium_Num)
            {
                int Number = rnd.Next(10, 100);
                Number_list.Add(Number);
                Listbox.Items.Add(Number);
                loop++;
            }

        }

        private void RandomNumber_High()
        {
            loop = 0;
            int High_Num = Int32.Parse(High_Number.Text);

            Random rnd = new Random();

            while (loop < High_Num)
            {
                int Number = rnd.Next(100, 900);
                Number_list.Add(Number);
                Listbox.Items.Add(Number);
                loop++;
            }

        }



        private void Low_number_Button_Click(object sender, EventArgs e)
        {
            RandomNumber_low();
        }

        private void Medium_Number_Button_Click(object sender, EventArgs e)
        {
            RandomNumber_Medium();
        }

        private void High_Number_button_Click(object sender, EventArgs e)
        {
            RandomNumber_High();
        }
    }
}

 

Link to comment
https://linustechtips.com/topic/785690-c-challenge-help/#findComment-9904215
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×