Click here to Skip to main content
15,889,635 members
Home / Discussions / Algorithms
   

Algorithms

 
QuestionHow they got this function? Pin
Member 125085107-May-16 1:51
Member 125085107-May-16 1:51 
AnswerRe: How they got this function? Pin
Chris Losinger12-May-16 6:33
professionalChris Losinger12-May-16 6:33 
QuestionIn Search for a Published Board Game Generating Algorithm Pin
Mark.io5-May-16 2:13
Mark.io5-May-16 2:13 
QuestionAlgorithm Pin
Member 1246448116-Apr-16 5:43
Member 1246448116-Apr-16 5:43 
AnswerRe: Algorithm Pin
Richard Deeming18-Apr-16 2:28
mveRichard Deeming18-Apr-16 2:28 
GeneralRe: Algorithm Pin
honglomong940@gmail.com29-Apr-16 22:50
honglomong940@gmail.com29-Apr-16 22:50 
AnswerRe: Algorithm Pin
Patrice T18-Apr-16 5:46
mvePatrice T18-Apr-16 5:46 
QuestionDealing with arbitrarily large power of 10 numbers Pin
Member 1168325115-Apr-16 3:52
Member 1168325115-Apr-16 3:52 
If you are familiar with idle game or incremental games like Adventure Capitalist or Clicker Heroes you know that after a while you are dealing with very large numbers. If you are not aware basically you earn points in these games which you invest so that you can earn more points even quicker, rinse and repeat.

I wrote a small game of this style myself but didn't leave the range that a double couldn't handle but it did get me thinking on how to deal with extraordinarily large numbers.

Just to play around I figured a quick and easy way was to just keep a list with ints, each index represents a higher power and you can easily go higher if needed. index zero keeps numbers between 0-999 and index 1 then starts at 10^3. So index 5 would be ^7 etc.

Except for numbers 0-999 if you want to increase the number I have a function where you specify what number 1-9 you want to add and to which power. If you add say 9^5 to 3^5 it sorts this out by becoming 2^5 and 1^6.

So far I haven't accounted for subtraction yet in my little project but that should be fairly easy in a similar manner.

I think this shouldn't be too computationally heavy unless if used to run addition between several large lists.

Should I want to use this in a game I think it could also be easily adapted to use some approximation to reduce unnecessary work. For example if you have an entity in the game which adds 10^15 points per second and one that adds 10^3 and you show 5 decimals instead of doing all the background computations of adding those smaller numbers every second you just approximate how many seconds before they add as much so that it shows and then go from there if I made myself clear.

C#
public void AddNumber(int value, int power) // 10^3 = power1, 10^4 = power 2, 10^5 = power 3 etc.
        {
            if (power == 0)
            {
                NumberContainer[0] += value;
                while (NumberContainer[0] >= 1000)
                {
                    NumberContainer[0] -= 1000;
                    AddNumber(1, 1);
                }
            } else if(power < mPower)
            {
                NumberContainer[power] += value;
                while( NumberContainer[power] >= 10)
                {
                    NumberContainer[power] -= 10;
                    AddNumber(1, power + 1);
                }
            }else
            {
                //power too large
            }
        }

        public static NumberControl operator +(NumberControl c1, NumberControl c2)
        {
            //set new maxpower to largest of the two
            int mMaxp = c1.mPower;
            if (c2.mPower > mMaxp) mMaxp = c2.mPower;

            NumberControl nc = new NumberControl(mMaxp);

            for(int i = 0;i < c1.NumberContainer.Count;i++)
            {
                nc.AddNumber(c1.NumberContainer[i], i);
            }

            for (int i = 0; i < c2.NumberContainer.Count; i++)
            {
                nc.AddNumber(c2.NumberContainer[i], i);
            }

            return nc;
        }


Here is how I add numbers. Thinking about this really got me wondering about how others would choose to solve it instead.

Number container is just a list<int>.

I'm planning on profile how well it handles a few different scenarios, for example if you have a list that goes to the power of 100 and have say 80 "generators" which adds a number at different power levels each second how will it will hold out compared to if I approximate those that are smaller than a certain range from the biggest number.

Reading the numbers is done by specifying how many decimals I want shown and then just walk backwards in the list and adding to a string so unless I want full precision it also works fairly well.
SuggestionRe: Dealing with arbitrarily large power of 10 numbers Pin
Richard Deeming15-Apr-16 4:21
mveRichard Deeming15-Apr-16 4:21 
GeneralRe: Dealing with arbitrarily large power of 10 numbers Pin
Member 1168325115-Apr-16 8:45
Member 1168325115-Apr-16 8:45 
AnswerRe: Dealing with arbitrarily large power of 10 numbers Pin
Eddy Vluggen15-Apr-16 5:00
professionalEddy Vluggen15-Apr-16 5:00 
AnswerRe: Dealing with arbitrarily large power of 10 numbers Pin
Kenneth Haugland15-Apr-16 14:43
mvaKenneth Haugland15-Apr-16 14:43 
AnswerRe: Dealing with arbitrarily large power of 10 numbers Pin
Mark.io5-May-16 1:56
Mark.io5-May-16 1:56 
GeneralRe: Dealing with arbitrarily large power of 10 numbers Pin
Member 116832518-May-16 22:15
Member 116832518-May-16 22:15 
AnswerRe: Dealing with arbitrarily large power of 10 numbers Pin
Daniel Pfeffer8-May-16 22:36
professionalDaniel Pfeffer8-May-16 22:36 
Question~difficult~ finding combination from K arrays Pin
Member 1245958914-Apr-16 6:27
Member 1245958914-Apr-16 6:27 
GeneralRe: ~difficult~ finding combination from K arrays Pin
Richard MacCutchan14-Apr-16 20:43
mveRichard MacCutchan14-Apr-16 20:43 
QuestionCompression algorithms Pin
Member 121468278-Apr-16 9:38
Member 121468278-Apr-16 9:38 
AnswerRe: Compression algorithms Pin
Dave Kreskowiak8-Apr-16 10:37
mveDave Kreskowiak8-Apr-16 10:37 
GeneralRe: Compression algorithms Pin
Patrice T9-Apr-16 0:54
mvePatrice T9-Apr-16 0:54 
AnswerRe: Compression algorithms Pin
Patrice T9-Apr-16 0:54
mvePatrice T9-Apr-16 0:54 
AnswerRe: Compression algorithms Pin
Alan Balkany9-May-16 4:46
Alan Balkany9-May-16 4:46 
AnswerRe: Compression algorithms Pin
Rupinder Singh thind27-Jun-16 1:37
Rupinder Singh thind27-Jun-16 1:37 
Questionwhich mathematical subjects I need to know for learning algorithms Pin
Mur25018-Apr-16 6:15
Mur25018-Apr-16 6:15 
AnswerRe: which mathematical subjects I need to know for learning algorithms Pin
Richard MacCutchan8-Apr-16 6:27
mveRichard MacCutchan8-Apr-16 6:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.