numbers

What is the fastest way to check for duplicate digits of a number?

喜欢而已 提交于 2019-12-01 02:56:05
问题 Let's say I want to check if a number n = 123 has duplicate digits. I tried: #include <iostream> using namespace std; int main() { int n = 123; int d1 = n % 10; int d2 = ( n / 10 ) % 10; int d3 = ( n / 100 ) % 10; if( d1 != d2 && d1 != d3 && d2 != d3 ) { cout << n << " does not have duplicate digits.\n"; } } Is there any faster solution to this problem? Update Sorry for being unclear. The code above was written in C++ only for description purpose. I have to solve this problem in TI-89, with a

Generate integer random numbers from range (0:10^12)

大兔子大兔子 提交于 2019-12-01 02:52:36
I want to generate 10000 integer random numbers between 0 and 10^12. Usually, the code would look like this: x <- sample(0:1000000000000,10000,replace=T) But I get following error message: Error in 0:1000000000000 : result would be too long a vector Is there a more memory efficient method that doesn't have to put 10^12 integers in a vector just to get a sample of size 10000? If not, is there a way to increase the max size of the vector? I'm working on a 64bit OS with 12GB of free RAM. PascalVKooten The real problem lies in the fact that you cannot store the sequence of 0:10^12 into memory. By

How to rotate an image by a random amount using CSS?

你说的曾经没有我的故事 提交于 2019-12-01 02:47:06
问题 I have a gallery of 20 images on my web page that I would like to rotate by a random amount (-5 to 5 degrees) upon hover over each image. If possible, I'd like to use just CSS. If not, I would be open to using JavaScript or jQuery. My CSS is as follows: .photo:hover { z-index:1; transform:rotate(6deg) scale(1.25); -webkit-transform:rotate(6deg) scale(1.25); -moz-transform:rotate(6deg) scale(1.25); -ms-transform:rotate(6deg) scale(1.25); } 6deg should be a random number, so every time the user

Round to .5 or 1.0 in SQL

試著忘記壹切 提交于 2019-12-01 02:15:51
I'm looking to round values like 2.3913 -> 2.5 4.6667 -> 4.5 2.11 -> 2 How can I manage this in SQL? Thanks SELECT ROUND(2.2 * 2, 0) / 2 gets you to the nearest .5 来源: https://stackoverflow.com/questions/9873990/round-to-5-or-1-0-in-sql

Is there a way to write a large number in C++ source code with spaces to make it more readable? [duplicate]

微笑、不失礼 提交于 2019-12-01 02:03:13
This question already has an answer here: Representing big numbers in source code for readability? 5 answers Making large constants in C source more readable? 8 answers Imagine I have the code: vector<int> temp = vector<int>(1 000 000 000); The above will not compile as the compiler will complain about the spaces. Is it possible to indicate to C++ to ommit those spaces when compiling, or otherwise make the number easier to read? Try digit separator: int i = 1'000'000'000; This feature is introduced since C++14 . It uses single quote ( ' ) as digit separator. Also see: Why was the space

SQLite issue with Table Names using numbers?

纵然是瞬间 提交于 2019-12-01 01:37:29
问题 I'm developing an app which requires that the user selects a year formatted like this 1992-1993 from a spinner. The tablename is also named 1992-1993 and the idea is that using SQL the values from this table are pulled through with a statement like this select * from 1992-1993 . When I run the emulator however, it throws an error. If I then relabel the Spinner item to NinetyTwo and rename the table to NinetyTwo and run the emulator it runs as expected and the data is pulled through from the

Return highest and lowest number in a string of numbers with spaces

帅比萌擦擦* 提交于 2019-12-01 00:23:30
Let's say I have a string of numbers separated by spaces and I want to return the highest and lowest number. How could that best be done in JS using a function? Example: highestAndLowest("1 2 3 4 5"); // return "5 1" I would like the both numbers to be returned in a string. The lowest number first followed by a space then the highest number. Here is what I have so far: function myFunction(str) { var tst = str.split(" "); return tst.max(); } You can use Math.min and Math.max , and use them in an array to return the result, try: function highestAndLowest(numbers){ numbers = numbers.split(" ");

Java generics and the Number class

妖精的绣舞 提交于 2019-12-01 00:13:43
问题 I want to create a method that compares a number but can have an input that is any of the subclasses of Number. I have looked at doing this in the following manner... public static <T extends Number> void evaluate(T inputNumber) { if (inputNumber >= x) { ... } } I need to get the actual primative before I can perform the comparison, the Number class has methods to retrieve this for each primative but I want a clean way of selecting the correct one. Is this possible? Cheers 回答1: Unfortunately

Why parseFloat in javascript returns string type for me?

社会主义新天地 提交于 2019-11-30 22:44:42
I searched and only found this one related to my question, but not exactly the same, as I'm using toFixed rather than toPrecision. Why does toPrecision return a String? Here is my code var oldv = parseFloat(document.getElementById('total').textContent).toFixed(2); alert(typeof oldv); // returns string var testv = parseInt(document.getElementById('total').textContent); alert(typeof testv); // returns number I need further math steps, so string type messed up... Why? How to solve? TIA As mentioned in docs, toFixed returns A string representing the given number using fixed-point notation In case

Is there a way to write a large number in C++ source code with spaces to make it more readable? [duplicate]

谁都会走 提交于 2019-11-30 22:24:55
问题 This question already has answers here : Representing big numbers in source code for readability? (5 answers) Making large constants in C source more readable? (8 answers) Closed last year . Imagine I have the code: vector<int> temp = vector<int>(1 000 000 000); The above will not compile as the compiler will complain about the spaces. Is it possible to indicate to C++ to ommit those spaces when compiling, or otherwise make the number easier to read? 回答1: Try digit separator: int i = 1'000