P
P
p4p2013-03-17 20:08:19
C++ / C#
p4p, 2013-03-17 20:08:19

How to find the number of digits between two given ones?

I'm trying to determine the number of months between two dates. The built-in functions are not suitable, because they do not work as I need with incomplete months.
Months 3 and 12 are known, how to find out how many digits are between them? 1 2 3 4 5 6 7 8 9 10 11 12 how can I programmatically catch this interval in c#?

Answer the question

In order to leave comments, you need to log in

10 answer(s)
P
p4p, 2013-03-18
@p4p

I don’t know why I was downvoted, so I wrote a simple function:

public int monthInterval(int fMonth, int sMonth)
        {
            int f = fMonth + 1;
            int s = sMonth - 1;

            int buffer1 = 12 - (f - 1);

            int buffer2 = 12 - s;

            int buffer3 = buffer1 - buffer2;

            int monthInterval = buffer3;

            return monthInterval;
        }

E
egorinsk, 2013-03-17
@egorinsk

I think that serious mathematical analysis is needed here, maybe try to look for a familiar mathematician?

A
Archet, 2013-03-17
@Archet

I saw a library for this somewhere.

D
Dimond17, 2013-03-17
@Dimond17

in this example the correct answer is 10?

B
brevis, 2013-03-17
@brevis

Use the Wolframalpha.com API.

D
Dmitry Timofeev, 2013-03-17
@blackstrip

The built-in subtraction function will do for this =)
N - the first number
M - the second number the
number of digits between them is (MN-1)
check: N = 3, M = 12, then MN-1=12-3-1=8

A
AxisPod, 2013-03-17
@AxisPod

If the number of numbers, then the above has already been said. If it's numbers, then something tells you that it's not very difficult.
We take the number of digits in the boundary numbers.
And here we have 2 options in essence:
- The number of digits is equal.
- The number of digits is not equal, in this case there are necessarily extreme subranges and possibly 1 or more ranges between them. Ranges are a set of numbers with one number of digits.
1st option.
(right value - left value + 1) * number of digits for the range
2nd option for more details.
For the extreme ranges, the number of digits will be something like, for the left: (the maximum number with the current number of digits is the left value + 1) * the number of digits for the range, for the right for the right (the current value is the minimum number with current number of digits + 1) * number of digits for the range.
Well, for the averages in the cycle (the maximum number with the current number of digits - the minimum number with the current number of digits + 1) * number of digits for the range).
The number of digits for the range is the number of digits for the 1st number from the range of numbers with one number of digits.
If you still need to take into account, for example, gaps, then they can be calculated as in the 1st option.
My sick brain tells me something like this without going into mathematical theory at all.
PS I wrote from proson, it may sound clumsy in places.

A
aktuba, 2013-03-17
@aktuba

Maybe not in the topic, but it seems like there are many solutions to this problem in Google: bit.ly/ZKLKIb Why are they not suitable? Here, for example: dkomanov.livejournal.com/37861.html

S
sergeyZ, 2013-03-17
@sergeyZ

Good library for working with time intervals.
http://www.codeproject.com/Articles/168662/Time-Period-Library-for-NET

K
Krypt, 2013-03-18
@Krypt

pastebin.com/ZgAFeL0R
Here is my bike. True, it is written in Obj-C, but I think you can translate it - in general, the frameworks are quite similar.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question