digit

De Bruijn algorithm binary digit count 64bits C#

China☆狼群 提交于 2019-12-09 00:34:14
问题 Im using the "De Bruijn" Algorithm to discover the number of digits in binary that a big number (up to 64bits) has. For example: 1022 has 10 digits in binary. 130 has 8 digits in binary. I found that using a table lookup based on De Bruijn give me the power to calculate this x100 times faster than conventional ways (power, square, ...). According to this website, 2^6 has the table to calculate the 64 bits numbers. this would be the table exposed in c# static readonly int[]

Regex Counting By 3s

ぐ巨炮叔叔 提交于 2019-12-07 16:55:47
问题 I'm teaching myself regular expressions, and found a quizzing site that has been helping me find more applications for them and has been helping me expand my knowledge of how they work. I found a question asking me to form a regex to match 10 digit numbers that are multiples of 3s. The only way I can think of doing this is by having the regex recognise numbers' values and be able to manipulate them mathematically. How is this possible? In other words, what regex would match 0003 0006 0351

Regex Counting By 3s

≯℡__Kan透↙ 提交于 2019-12-06 02:54:03
I'm teaching myself regular expressions, and found a quizzing site that has been helping me find more applications for them and has been helping me expand my knowledge of how they work. I found a question asking me to form a regex to match 10 digit numbers that are multiples of 3s. The only way I can think of doing this is by having the regex recognise numbers' values and be able to manipulate them mathematically. How is this possible? In other words, what regex would match 0003 0006 0351 1749 but not match 0005 0011 0361 4372 First you need to start with the rule that a number is divisble by

Limit Numbers after Decimal on Key Press Event

流过昼夜 提交于 2019-12-05 02:17:56
问题 I am using the following code to take only digits from user and only one decimal point , that is working fine for me on KeyPress Event : if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != '.') { e.Handled = true; } if (e.KeyChar == '.' && (sender as TextBox).Text.IndexOf('.') > -1) { e.Handled = true; } Now I want to Limit the numbers/Digits after the decimal/dot i.e 35.25468, means it take only 6 numbers/digits after the dot/decimal. Update me ! 回答1: private void

Fastest method for adding/summing the individual digit components of a number

旧巷老猫 提交于 2019-12-04 08:10:32
问题 I saw a question on a math forum a while back where a person was discussing adding up the digits in a number over and over again until a single digit is achieved. (i.e. "362" would become "3+6+2" which would become "11"... then "11" would become "1+1" would would become "2" therefor "362" would return 2... I wrote some nice code to get an answer to this and posted it only to be outdone by a user who suggested that any number in modulo 9 is equal to this "infinite digit sum", I checked it an

VBA. How to find position of first digit in string

自古美人都是妖i 提交于 2019-12-03 05:43:44
I have string "ololo123". I need get position of first digit - 1. How to set mask of search ? Something like this should do the trick for you: Public Function GetPositionOfFirstNumericCharacter(ByVal s As String) As Integer For i = 1 To Len(s) Dim currentCharacter As String currentCharacter = Mid(s, i, 1) If IsNumeric(currentCharacter) = True Then GetPositionOfFirstNumericCharacter = i Exit Function End If Next i End Function You can then call it like this: Dim iPosition as Integer iPosition = GetPositionOfFirstNumericCharacter("ololo123") Here is a lightweight and fast method that avoids

Fastest method for adding/summing the individual digit components of a number

安稳与你 提交于 2019-12-02 22:31:36
I saw a question on a math forum a while back where a person was discussing adding up the digits in a number over and over again until a single digit is achieved. (i.e. "362" would become "3+6+2" which would become "11"... then "11" would become "1+1" would would become "2" therefor "362" would return 2... I wrote some nice code to get an answer to this and posted it only to be outdone by a user who suggested that any number in modulo 9 is equal to this "infinite digit sum", I checked it an he was right... well almost right, if zero was returned you had to switch it out with a "9" but that was

Algorithm for digit summing?

我是研究僧i 提交于 2019-12-02 22:16:29
I'm searching for an algorithm for Digit summing. Let me outline the basic principle: Say you have a number: 18268 . 1 + 8 + 2 + 6 + 8 = 25 2 + 5 = 7 And 7 is our final number. It's basically adding each number of the whole number until we get down to a single (also known as a 'core') digit. It's often used by numerologists. I'm searching for an algorithm (doesn't have to be language in-specific) for this. I have searched Google for the last hour with terms such as digit sum algorithm and whatnot but got no suitable results. Because 10-1=9, a little number theory will tell you that the final

[leetcode] Palindrome Number

邮差的信 提交于 2019-12-02 19:12:31
Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to string, note the restriction of using extra space. You could also try reversing an integer. However, if you have solved the problem "Reverse Integer", you know that the reversed integer might overflow. How would you handle such case? There is a more generic way of solving this problem. 思路1(不推荐):利用Reverse Integer的方法,求的转换后的数字,然后比较是否相等。提示说这样有溢出的问题,想了想感觉问题不大,leetcode也过了。因为首先输入必须是一个合法的int值,负数直接返回false,对于正数

Force JTextField to string value while DocumentFilter only allows digits

让人想犯罪 __ 提交于 2019-12-02 17:01:14
问题 I'm working on a Java application and ran into a problem that I cannot seem to solve on my own. I've set a DocumentFilter on JTextField to only allow digit entries, however, the default values are text. I have a button that resets JTextField s back to default, and it is not working presumingly because of the DocumentFilter . How can I overcome this problem? Thanks 回答1: A field that the user can only enter numeric data into, but also needs to display non-numeric values is contradictive. Text