numbers

Regex to match a digit two or four times

一曲冷凌霜 提交于 2019-11-28 18:05:19
It's a simple question about regular expressions, but I'm not finding the answer. I want to determine whether a number appears in sequence exactly two or four times. What syntax can I use? \d{what goes here?} I tried \d{2,4} , but this expression accepts three digits as well. There's no specific syntax for that, but there are lots of ways to do it: (?:\d{4}|\d{2}) <-- alternation: four digits or two \d{2}(?:\d{2})? <-- two digits, and optionally two more (?:\d{2}){1,2} <-- two digits, times one or two 来源: https://stackoverflow.com/questions/8177143/regex-to-match-a-digit-two-or-four-times

Count the number of Ks between 0 and N

巧了我就是萌 提交于 2019-11-28 17:39:56
Problem: I have seen questions like: count the number of 0s between 0 and N? count the number of 1s between 0 and N? count the number of 2s between 0 and N? ... ... These kinds of questions are very similar of asking to find the total number that Ks (i.e. K=0,1,2,...,9) are shown in number range [0, N] . Example: Input: K=2, N=35 Output: 14 Detail: list of 2 s between [0,35] : 2, 12, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 32 , note that 22 will be counted as twice (as 22 contains two 2 s) What we have: There are solutions for each of them (available if you search for it). Usually, O(log N)

Obscure / encrypt an order number as another number: symmetrical, “random” appearance?

僤鯓⒐⒋嵵緔 提交于 2019-11-28 17:03:52
Client has an simple increasing order number (1, 2, 3...). He wants end-users to receive an 8- or 9- digit (digits only -- no characters) "random" number. Obviously, this "random" number actually has to be unique and reversible (it's really an encryption of the actualOrderNumber). My first thought was to just shuffle some bits. When I showed the client a sample sequence, he complained that subsequent obfuscOrderNumbers were increasing until they hit a "shuffle" point (point where the lower-order bits came into play). He wants the obfuscOrderNumbers to be as random-seeming as possible. My next

The field must be a number. How to change this message to another language?

依然范特西╮ 提交于 2019-11-28 15:49:44
问题 How can I change that messages for all int fields so that instead of saying: The field must be a number in English, it shows: El campo tiene que ser numerico in Spanish. Is there are a way? 回答1: If you happen to be using ASP.NET MVC 4 onwards, check this post: Localizing Default Error Messages in ASP.NET MVC and WebForms Basically you have to add the following piece of code in your Application_Start() method in Global.asax : ClientDataTypeModelValidatorProvider.ResourceClassKey = "Messages";

Long vs Integer, long vs int, what to use and when?

六眼飞鱼酱① 提交于 2019-11-28 15:36:41
Sometimes I see API's using long or Long or int or Integer , and I can't figure how the decision is made for that? When should I choose what? Borealid Long is the Object form of long , and Integer is the object form of int . The long uses 64 bits . The int uses 32 bits, and so can only hold numbers up to ±2 billion (-2 31 to +2 31 -1). You should use long and int , except where you need to make use of methods inherited from Object , such as hashcode . Java.util.collections methods usually use the boxed ( Object -wrapped) versions, because they need to work for any Object , and a primitive type

Why is it that parseInt(8,3) == NaN and parseInt(16,3) == 1?

青春壹個敷衍的年華 提交于 2019-11-28 15:12:57
I'm reading this but I'm confused by what is written in the parseInt with a radix argument chapter Why is it that parseInt(8, 3) → NaN and parseInt(16, 3) → 1 ? AFAIK 8 and 16 are not base-3 numbers, so parseInt(16, 3) should return NaN too T.J. Crowder This is something people trip over all the time, even when they know about it. :-) You're seeing this for the same reason parseInt("1abc") returns 1: parseInt stops at the first invalid character and returns whatever it has at that point. If there are no valid characters to parse, it returns NaN . parseInt(8, 3) means "parse "8" in base 3"

Using Fractions On Websites

懵懂的女人 提交于 2019-11-28 14:46:33
Is it possible to use any fraction symbol on a website, represented as ¼ rather than 1/4 for example? From what I've gathered, these are the only ones I can use: ½ ⅓ ⅔ ¼ ¾ Is this right and why is that? The reason why I ask this is because I've done a Google web search and can't seem to locate any others ... eg. 2/4 mohammad mohsenipur You can test http://www.mathjax.org/ it is a JavasScript library to make a Math Formula if this is what you want. poitroae The image below displays all unicode-defined fraction symbols. Each of them is treated as one single character. You can use all of them

Hexadecimal to decimal

与世无争的帅哥 提交于 2019-11-28 14:33:03
I have to convert a hexadecimal number to decimal, but don't know how. In the AutoIt documentation (pictured below) some constants (being assigned hexadecimal values) are defined: 0x00200000 hexadecimal (underlined in image) equals 8192 decimal (this is the true conversion). But convertors return 2097152 . I have to convert another hex value ( 0x00000200 ), but convertors get it wrong. How to correctly convert it? When I use the definition $WS_EX_CLIENTEDGE (or a hexadecimal value), it doesn't work. If I use an integer I believe it will work. As per Documentation - Language Reference -

pyramid of numbers in python

。_饼干妹妹 提交于 2019-11-28 14:19:22
Write a program that prompts the user to enter an integer from 1 to 15 and displays a pyramid, as shown in the following sample run: 1 2 1 2 3 2 1 2 3 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5 6 5 4 3 2 1 2 3 4 5 6 7 6 5 4 3 2 1 2 3 4 5 6 7 I have the following: num = eval(raw_input("Enter an integer from 1 to 15: ")) if num < 16: for i in range(1, num + 1): # Print leading space for j in range(num - i, 0, -1): print(" "), # Print numbers for j in range(i, 0, -1): print(j), for j in range(2, i + 1): print(j), print("") else: print("The number you have entered is greater than 15.") This yields a

JavaScript - Preventing octal conversion

眉间皱痕 提交于 2019-11-28 14:18:45
I'm taking a numerical input as an argument and was just trying to account for leading zeroes. But it seems javascript converts the number into octal before I can do anything to the number. The only way to work around it so far is if I pass the number as a string initially but I was hoping there'd be another way to convert it after it is passed? So far tried (using 017 which alerted me to the octal behaviour): 017.toString(10) // 15 parseInt(017,10) // 15 017 + "" //15 new Number(017) //15 new Number('017') //17 parseInt('017', 10) // 17 So given function(numb) { if (typeof numb === number) {