numbers

Geometrical progression with any number row

I can have any number row which consists from 2 to 10 numbers. And from this row, I have to get geometrical progression. For example: Given number row: 125 5 625 I have to get answer 5. Row: 128 8 512 I have to get answer 4. Can you give me a hand? I don't ask for a program, just a hint, I want to understand it by myself and write a co...

locale-aware number comparison with XSLT

I have a bunch of costs in my XML that I am trying to compare against another cost value, to determine which values to display (only ones higher than the comparator). This works when the numbers use the decimal point as the separator but not with numbers using comma as the decimal separator. I could be getting either, depending on the ...

Random and negative numbers

Hello, I have to generate numbers in range [-100; +2000] in c++. How can I do this with rand if there is only positive numbers available? Are there any fast ways? ...

Spreadsheets: how do I SUM values in a column, only if the text coloum has a 1?

lets say I have this data 4 1 4 0 4 1 3 0 5 1 So, How do I write a function (using SUM or somethnig like that) to add all the values on the left, if the values on the right are 1, or true the total should be 13 ...

How can I get the last two digits of a number, using Perl?

How can I get a value from particular number? Lets say number is 20040819. I want to get last two digit i.e 19 using Perl. ...

Strange calculation

Hello, I can't understand why does my program do such calculations: #define PixelsPerMeter 40.0 // 40 pixels ~ 1 meter #define Meters2Pixels(meters) (float)meters*PixelsPerMeter #define Pixels2Meters(pixels) (float)pixels/PixelsPerMeter // The speed of free falling #define G Meters2Pixels(9.81) // ... float mHeight = 768; float _wind...

How to see if a string has more numbers than other symbols in java

So for an assignment I have to make a programm that asks for a input of a string and then detects palindromes. thing is, also numbers can be put in. When more than half of the input of the string is a number it needs to regard the string as a numeric string and disregard the other symbols. So what i thought is to put the input string ...

Java: Generic methods and numbers.

Hi, I want to make a generic method which makes the total sum of a List of numbers. What I was trying is this: public static <T extends Number> T sumList(List<T> data) { T total = 0; for (T elem : data) { total += elem; } return total; } But the problem is that there is no += operator in T and that total ...

How to convert a negative number to positive?

How can I convert a negative number to positive in Python? (And keep that positive value.) ...

PHP sequential numbering

Someone gave me a -1. Not displaying my source code anymore, this has been resolved. ...

Google Map marker coordinate string to number

I am trying to create a Google Map with a single coordinate as marker. I use ASP MVC, and the coordinates are saved in the database as a string. <%: Model.LatLng %> outputs something like this: 52.425, 4.938 The problem is, Google Maps cannot read this, probably because it is a string. How do I convert the coordinates to something...

String to Number and back algoritm

This is a hard one (for me) I hope people can help me. I have some text and I need to transfer it to a number, but it has to be unique just as the text is unique. For example: The word 'kitty' could produce 12432, but only the word kitty produces that number. The text could be anything and a proper number should be given. One problem t...

Arithmetic operations with Java Generics

I am trying to create a generic class in Java that will perform operations on numbers. In the following example, addition, as follows: public class Example <T extends Number> { public T add(T a, T b){ return a + b; } } Forgive my naivety as I am relatively new to Java Generics. This code fails to compile with the err...

add commas to a number in jQuery

I have these numbers 10999 and 8094 and 456 And all i want to do is add a comma in the right place if it needs it so it looks like this 10,999 and 8,094 and 456 These are all within a p tag like this <p class="points">10999</p> etc. Can it be done? I've attempted it here with the help of other posts http://jsfiddle.net/pdWTU/1/ but...

Minimum values and Double.MIN_VALUE in Java?

Can anyone shed some light on why Double.MIN_VALUE is not actually the minimum value that Doubles can take? I understand why it's a useful number, but it seems a very unintuitive name, especially when compared to Integer.MIN_VALUE. Calling it Double.SMALLEST_POSITIVE or MIN_INCREMENT or similar would have clearer semantics. Also, what ...

Why do we have "is not a Number" (isNan) functions?

Many languages have an isNaN() function. I am asking myself: why check for not being a number? Is the reason purely logical or is it faster to check for not a number instead of is a number? Note that this is a pure question of understanding. I know that I can negate isNaN() to achieve an isNumber() function for example. However I am se...

Cryptographically-secure pseudorandom number generator seed

Do we need to seed a CSPRNG with a truly random number? Examples and documentation use truly random numbers, but no justification is given (that I can find). If we were to seed one with a pseudorandom number, I don't see what the difference would be compared to with a truly random seed. If someone finds either of the seeds, then the e...

Determine the optimal combination of coins for a dollar amount

I need to find the most optimal combination of coins that makes up a certain dollar amount. So essentially, I want to use the least amount of coins to get there. For example: if a currency system has the coins: {13, 8, 1}, the greedy solution would make change for 24 as {13, 8, 1, 1, 1}, but the true optimal solution is {8, 8, 8}. I ...

Query regarding binary numbers in assembly

I am reading the book art of assembly language. There I came across this paragraph. If the H.O. bit is zero, then the number is positive and is stored as a standard binary value. If the H.O. bit is one, then the number is negative and is stored in the two’s comple-ment form. To convert a positive number to its negative, two’s co...

Query regarding binary numbers

I am reading a book on assembly languages. I came across these sentences in that book. Consider the value “-64”. The eight bit two’s complement value for this number is 0C0h. The 16-bit equivalent of this number is 0FFC0h. I can't understand these two sentences. Can anybody show me how -64's eight bit 2's complement is 0c0h? And how ...