36 => 1.25
34 => 1.3245
24 => 1.88679
22 => 2.06186
I'm stuck with these numbers. Who can see a pattern ? The first one is supposed to be exact, and the other are derivates, so they could be rounded (but I don't think so). I suspect there may be variations on the one, so instead of 36:34 there may be a correlation between 35:33 or 37:35 and their associates.
The numbers come from a sass mixin that got lost - the first column was the number of columns in a grid, and the second column the gutter width related to that.
This seems to match, if $X is the left column and $Y is the right column and numbers are rounded to a few digits.
$innernumcols=36/$X;
$innernummargins=$innernumcols - 1;
$innerwidth=(100-($innernummargins*1.25)/$innernumcols;
$Y=1.25*100/$innerwidth;
which basicly says .. $Y is a reverse percentage of 1.25 depending on $X and related to 36, but indeed with an offset of 1. As a formula, it looks pretty gross.
Related
There is a particular method of converting a decimal (with a decimal point, like xx.xx) to a binary number. It is detailed here: https://www.geeksforgeeks.org/convert-decimal-fraction-binary-number/
I can apply this process but am having trouble understanding WHY it works.
Basically, it calculates the left side of the decimal point separately from the right side - this part I have no issue with.
For example, if we have 6.9, it will start by calculating the left side: 6.
6 divided by 2 gives us 3, with a remainder of 0.
3 divided by 2 gives us 1, with a remainder of 1.
1 divided by 2 gives us 0, with a remainder of 1.
For some reason, it now takes the REVERSE of this, which is 110, and this magically becomes 6.
I don't understand why the remainder of the least significant division (1 divided by 2) is now used in the most significant bit of the answer, and this somehow works.
Similarly confused about why the method for the right hand side works.
Does anyone have some intuition they can share about this particular process of converting decimals to binaries? Again, I have no problem performing the calculation as the computation is quite easy. I simply don't understand why this works.
Think of it like this :
A binary representation b_n, b_(n-1), .., b_0 (least significant bit on the right) represents the number
k = b_n*2^n + b_(n-1)*2^(n-1) + ... + b_0*2^0 (remember that 2^0 is just 1).
To get the least significant bit, you want to know whether this number divides evenly into 2's, because if it doesn't then you know that b_0 == 1 because all the other terms surely divide evenly, as they all have some positive power of 2 in front. Thus the remainder from the division by two is b_0. Don't divide just yet, only get the remainder and write it down.
Now we would like to get rid of that last bit and start over again to get the next one. How can we do that? Simply divide k by two. Because then you get:
k/2 = b_n*2^(n-1) + b_(n-1)*2^(n-2) + ... + b_1*2^0 (Divide each term in the sum by 2, thus decreasing the power. The last term disappears because it was either 0 or 1, which both give 0 when divided by 2)
Or written in binary (without the powers of two) : b_n, b_(n-1), .., b_1.
Now we get a new number which is simply the same as before where the least significant bit has been thrown away and everything shifted to the right. So we can start this whole process again with k/2 to get b_1. And then b_2. And so on.
Here I separated getting the remainder and dividing to make it clearer, but you can do them at the same time if you want to, it's the same thing.
I hope you see how, during this process, we get the bits from right to left, which is why you want to flip the whole thing in the end if you have been writing them down from left to right.
I have scanned a large number of questions and answers around math.round /.floor/.truncate/.ceiling but couldn't find a clear answer to my problem of rounding (with currency values).
I understand math.round / toeven / awayfromzero but that doesn't seem to do it.
( in the following examples 1.88 is just any number an can be replaced with any other n.mm value)
If the result of a calculation of "decimal / decimal" is 1.88499 I need 1.88 as the rounded result. If the calculation gives 1.885499 I want 1.89 as the result of rounding (always rounding to two decimal digits).
Now, math.round(1.88499999,2) Returns 1.89 though 0.00499999 is certainly BELOW the middle between 8 and 9.
I understand that if the number is rounded from the last decimal digit up to the first, the result is understandable:
1.88499999 -> 1.8849999 -> 1.884999 -> 1.88499 -> 1.8849 -> 1.885 -> 1.89
However, from a fiscal Point of view, like for VAT calculations, that doesn't help at all.
The only way i can think of is to cut the number first behind the third decimal digit to round it then to 2 required digits. But isn't there a more elegant way?
you can use Decimal.ToString() ,
try,
decimal dec = 1.88499999m;
dec = Convert.ToDecimal(dec.ToString("#.00"));
I have solved the issue by avoiding the float datatypes in the case.
I did use integer variables and multiplied all currency values by 100. This way the calculations are not dependend on rounding or rather are rounded correctly when the result of a calculation is set into an integer.
When I assign a system array of doubles to an ilnumerics double array, the values are rounded off to nearest integer. This happens particularly for only large arrays.
Is there any way in ILnumerics to specify up to how many decimals the rounding should occur?
The following screenshot shows the problem . Sample_pulsedata is double array of length 1860 which I am assigning to sample_ydata.
The elements are not really rounded. The effect rather comes from the way the elements are displayed in Visual Studios data tips. ILNumerics tries to find a common scale factor which allows to display all elements in an array aligned.
In your example - presumably - there exist large values at higher indices, which are not shown currently (scroll down in order to find them). These elements cause the scale factor to be 1/10^4. This is indicated in the first line, index [0]: '(:;:) 1e+004'. The 32.57 therefore must get rounded to 33 in order to fit into the 4 digits after the decimal point. '4' is a fixed value in ILNumerics and cannot easily get changed.
The actual values of the array elements are not affected, of course. You can use the Watch window to show only the interesting part of the array, without the rounding effect:
sample_ydata["0:13"]
Or, even better, use the ILNumerics Array Visualizer in order to visualize your data graphically. This not only gives a nice overview of the whole array but also prevents from such artefacts as you encountered.
On my Windows desktop I multiply two numbers:
var a:Number = 31.05263157894737;
trace(a * 19) // will print '590'
It's obvious that dividing 590 by a leaves a remainder of 0, right? Well for some reason I get a differend result:
trace(590 % a) // will print '31.05263'
My question is How does this happen? Why does 1 % 0.5 give a correct remainder of 0?
31.05263157894737 * 19 is not exactly 590, it's 590.00000000000003
In other words, 590.00000000000003 % 31.05263157894737 = 0, but since 590 is slightly smaller, it will be just slightly less than required to reach/wrap around to 0.
Either way, even if you used what would in source code look as exact numbers will seldom give you exact results in floating point math, since not all numbers can be represented exactly by single/double types, and even tiny rounding errors can (as in this case) give fairly non obvious results.
I have this massive array of ints from 0-4 in this triangle. I am trying to learn dynamic programming with Ruby and would like some assistance in calculating the number of paths in the triangle that meet three criterion:
You must start at one of the zero points in the row with 70 elements.
Your path can be directly above you one row (if there is a number directly above) or one row up heading diagonal to the left. One of these options is always available
The sum of the path you take to get to the zero on the first row must add up to 140.
Example, start at the second zero in the bottom row. You can move directly up to the one or diagonal left to the 4. In either case, the number you arrive at must be added to the running count of all the numbers you have visited. From the 1 you can travel to a 2 (running sum = 3) directly above or to the 0 (running sum = 1) diagonal to the left.
0
41
302
2413
13024
024130
4130241
30241302
241302413
1302413024
02413024130
413024130241
3024130241302
24130241302413
130241302413024
0241302413024130
41302413024130241
302413024130241302
2413024130241302413
13024130241302413024
024130241302413024130
4130241302413024130241
30241302413024130241302
241302413024130241302413
1302413024130241302413024
02413024130241302413024130
413024130241302413024130241
3024130241302413024130241302
24130241302413024130241302413
130241302413024130241302413024
0241302413024130241302413024130
41302413024130241302413024130241
302413024130241302413024130241302
2413024130241302413024130241302413
13024130241302413024130241302413024
024130241302413024130241302413024130
4130241302413024130241302413024130241
30241302413024130241302413024130241302
241302413024130241302413024130241302413
1302413024130241302413024130241302413024
02413024130241302413024130241302413024130
413024130241302413024130241302413024130241
3024130241302413024130241302413024130241302
24130241302413024130241302413024130241302413
130241302413024130241302413024130241302413024
0241302413024130241302413024130241302413024130
41302413024130241302413024130241302413024130241
302413024130241302413024130241302413024130241302
2413024130241302413024130241302413024130241302413
13024130241302413024130241302413024130241302413024
024130241302413024130241302413024130241302413024130
4130241302413024130241302413024130241302413024130241
30241302413024130241302413024130241302413024130241302
241302413024130241302413024130241302413024130241302413
1302413024130241302413024130241302413024130241302413024
02413024130241302413024130241302413024130241302413024130
413024130241302413024130241302413024130241302413024130241
3024130241302413024130241302413024130241302413024130241302
24130241302413024130241302413024130241302413024130241302413
130241302413024130241302413024130241302413024130241302413024
0241302413024130241302413024130241302413024130241302413024130
41302413024130241302413024130241302413024130241302413024130241
302413024130241302413024130241302413024130241302413024130241302
2413024130241302413024130241302413024130241302413024130241302413
13024130241302413024130241302413024130241302413024130241302413024
024130241302413024130241302413024130241302413024130241302413024130
4130241302413024130241302413024130241302413024130241302413024130241
30241302413024130241302413024130241302413024130241302413024130241302
241302413024130241302413024130241302413024130241302413024130241302413
1302413024130241302413024130241302413024130241302413024130241302413024
02413024130241302413024130241302413024130241302413024130241302413024130
But I like homework :)
I find it easier to reason about the 'paths' problem when starting from the top, and following the rules the other way around.
This means:
a partial path can be the top zero, or an extended partial path
the extensions of a partial path Pr,c are, unless r is the last row, in which they're complete, the union of
the extensions of Pr,c + P(r+1),c
the extensions of Pr,c + P(r+1),c+1
The 'sum' rule just selects certain of all complete paths.