numbers

Hint for lookup table set bit count algorithm

末鹿安然 提交于 2019-12-07 14:42:13
问题 I am looking at solution for the set bit count problem (given a binary number, how to efficiently count how many bits are set). Here, http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetNaive, I have found some methods. What about the lookup table method? I dont understand what properties of binary representation / number make it work. static const unsigned char BitsSetTable256[256] = { # define B2(n) n, n+1, n+1, n+2 # define B4(n) B2(n), B2(n+1), B2(n+1), B2(n+2) # define B6(n)

Is there a function which does grouping numbers (thousand)?

我的梦境 提交于 2019-12-07 13:18:54
问题 Is there somewhere hidden in a (small) module a function, which does this for me: my $var = 23654325432; $var = reverse $var; $var =~ s/\d{3}\K(?=\d+)/_/g; $var = reverse $var; I like Number::Format but it didn't pass all tests on windows. use Number::Format; my $nf = new Number::Format( -thousands_sep => ',', -decimal_point => '.', ); my $formatted = $nf->format_number( 23142153 ); 回答1: Look at perl5i. It has commify and group_digits methods. 回答2: The fastest method is in the perlfaq (

Print largest number out of given digits - Java

梦想与她 提交于 2019-12-07 13:13:13
问题 First I would apologize if my question seems not clear. I want output to be the largest possible number from user input. Example: input: x = 0; y = 9; z = 5; output: 950 I tried something like the below code. import java.util.Scanner; class LargestOfThreeNumbers{ public static void main(String args[]){ int x, y, z; System.out.println("Enter three integers "); Scanner in = new Scanner(System.in); x = in.nextInt(); y = in.nextInt(); z = in.nextInt(); if ( x > y && x > z ) System.out.println(

How to avoid writing repetitive code for different numeric types in .NET

假装没事ソ 提交于 2019-12-07 12:04:07
问题 I am trying to write generic Vector2 type which would suite float, double, etc. types and use arithmetical operations. Is there any chance to do it in C#, F#, Nemerle or any other more or less mature .NET language? I need a solution with (1)good performance (same as I would have writing separate Vector2Float, Vector2Double, etc. classes), (2)which would allow code to look nice (I do not want to emit code for each class in run-time) (3)and which would do as much compile time checking as

How would I find the answer to X% of X in PHP?

我只是一个虾纸丫 提交于 2019-12-07 11:40:31
I have two variables: $percent = '3.5'; //this is the percentage $order = 400; //so how would i get $percent of $order? Now in PHP how would I find out what 3.5% of 400 is (I know its 14) - but would like to know how to calculate it directly in PHP using those two variables above. Appreciate your response. "Percent" just means "per 100" or "over 100" or "/ 100" $percentOfOrder = $order * ($percent / 100); You could make a percentOf function: function percentOf($number, $percent){ return $number * ($percent / 100); } //then: echo percentOf($order, $percent); Demo: http://codepad.org/a6BgEEs2 来源

How to save a number as a String in Excel?

你。 提交于 2019-12-07 11:37:09
问题 How to save a number as a String in Excel? When I try to enter a number, 00112233, Excel automatically formats it as 112233 and saving it as number. But I want the preceeding 0's not to be truncated and save the number as string. As a workaround I'm using quotes ("") to save the actual string. Any suggestion...?? 回答1: If you put a single quote in front of the number, it will be stored as text. 回答2: If you pre-format the input cells with TEXT format you can just enter 00112233 or whatever and

Localization of numeric number in Rails

蹲街弑〆低调 提交于 2019-12-07 10:42:08
问题 [Sorry for the new post, but my first one was focusing to arabic/persian numbers but it seems the issue is larger.] I wonder if someone had done a gem to handle the localization of numeric number in ruby/rails. I18n official locales (https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale) seems not to take care of that. It's kind of complex to do by helpers. Arabic is simple: ٠ ١ ٢ ٣ ٤ ٥ ٦ ٧ ٨ ٩ Persian too: ۰ ١ ۲ ۳ ۴ ۵ ۶ ۷ ۸ ۹ ۱۰ But all languages don't match 1-1 conversion with

How can I use numbers with angular.js without comma and dot?

倾然丶 夕夏残阳落幕 提交于 2019-12-07 09:51:38
问题 I m new at angular.js I have a ID column in my grid so I dont want to use formatted numbers with comma or dot. Should I use replace method or related regex expression? I used like: {{value | number: 0}} For example(10000 is 10,000 in my application I want to use like 10000) 回答1: Then don't use the number filter? Else, if you want it to be a number type create a custom filter: app.filter('customNumber', function() { return function(value) { return parseInt(value, 10) //convert to int } })

Scheme language: merge two numbers

99封情书 提交于 2019-12-07 09:44:23
问题 How can I merge two integers from a list into one? (in Scheme) Example: '(11 223) -> 11223 回答1: Assuming that the list has exactly two elements, and that both are numbers: (define (merge-numbers lst) (let ((1st (number->string (first lst))) (2nd (number->string (second lst)))) (string->number (string-append 1st 2nd)))) It works as expected: (merge-numbers '(11 223)) > 11223 Alternatively, without using a let : (define (merge-numbers lst) (string->number (string-append (number->string (first

Why isn't this int incrementing?

牧云@^-^@ 提交于 2019-12-07 08:36:25
I am stuck on probably an easy problem, but I really can't find why it isn't working. I am trying to increase mijnScore with 1 each time the method gets called. But somehow mijnScore goes back to 0 after the method is done. int mijnScore = 0; ... public void updateUI() { System.out.println("updateUI"); SwingUtilities.invokeLater(new Runnable() { public void run() { ikWin = true; while(ikWin) { mijnScore++; System.out.println("mijnScore" + mijnScore); Scoresp1.setText(mijnScore + ""); ikWin = false; positie = 0; } } }); } Solved Making the variable static solved my problem. static int mijnScore