Questions tagged [digits]

Questions dealing with getting, manipulating, or changing the digits of numbers

Use this tag for questions dealing with getting, manipulating, or changing the digits of numbers. More about digits on wikipedia

1098 questions
3
votes
6 answers

Fastest way to sum digits in a number

Given a large number, e.g. 9223372036854775807 (Int64.MaxValue), what is the quickest way to sum the digits? Currently I am ToStringing and reparsing each char into an int: num.ToString().Sum(c => int.Parse(new String(new char[] { c }))); Which is…
ConfusedNoob
  • 9,826
  • 14
  • 64
  • 85
3
votes
1 answer

Does the julia round function contain an error for large numbers?

The julia round function seems to work OK up to factorial(75), but breaks at factorial 76. Is this a bug in the round function? julia>round(factorial(big(75)), sigdigits=2) 2.5e+109 julia>round(factorial(big(76)),…
Julia Learner
  • 2,754
  • 15
  • 35
3
votes
1 answer

Java regular expression for digits and dashes

I need a regular expression which matches lines with only 4(four) hyphens and 13 digits(0-9). The order is undefined. I have regex like: ^([0-9\u2013-]{17})$ But, when I receive strings as ----123456789---- or 1-2-3-4-5-6-7-8-9 matching is true…
Dron4K
  • 456
  • 2
  • 6
  • 20
3
votes
2 answers

How can I tell R to round correctly?

How can I tell R to round correctly? Decimal Places in R I have encountered a problem that I cannot figure out how to solve I want R to calculate 5/26*100 = 19.230769 x <- 5/26*100 x gives me: [1] 19.23077 Let's try to use round(), first setting…
user9237696
3
votes
5 answers

Regex for a random set of chars and digits

I am looking for a regex that matches only when it sees a string that is randomly filled by digits and chars. For example, adfak332arg3 is allowed but 332352 and fagaaah are not allowed. .*[^\\s] looks fine for strings with only chars but how to…
lonesome
  • 2,503
  • 6
  • 35
  • 61
3
votes
1 answer

How to propose a "Subset operations" algorithm?

I am working on this problem: Given a set (or multiset) of positive numbers, find all the numbers which are combination of some elements from the set. Combination means sum, subtraction or product. For example, if A = {3, 4, 7}, we have to find 3,…
Averke
  • 31
  • 3
3
votes
5 answers

Python: Strategically go through ten digit numbers with 0-9

Recently, I read a math problem inspiring me to write a program. It asked to arrange the digits 0-9 once each so that xx xxx / xx xxx = 9. I wrote a python program to find the solutions and had a bit of trouble making sure the digits were different.…
Tawfeeq
  • 45
  • 8
3
votes
1 answer

split digits and alpha

I need to split a string like this: ID00605button. I want to get out ID00605. my code example: var contentLeftID; var id = "ID00605button" id = id.split(*some regex*); contentLeftID = id[0] + id[1]; Is it somebody how knows to…
HAFL
  • 33
  • 5
3
votes
2 answers

Why is std::numeric_limits::digits10 is one less for int types?

Why std::numeric_limits::digits10 is one less than it can be? For example, std::numeric_limits::digits10 == 2, but 100 consists of three digits. Or, std::numeric_limits::digits10 == 18, but INT64_MAX…
vladon
  • 8,158
  • 2
  • 47
  • 91
3
votes
2 answers

Allow limited keyboard digits in edit text, android?

I want to allow only alphabets, numbers and some of the special characters in Edit text: android:digits="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ()*-_,;':." I also want to allow am-percent(&) and double quote (") When I add…
WISHY
  • 11,067
  • 25
  • 105
  • 197
3
votes
5 answers

How can I safely and quickly extract digits from an int?

We currently have some code to extract digits from an int, but I need to convert this to a platform without snprintf, and I am afraid of a buffer overrun. I have started to write my own portable (and optimized) snprintf but I was told to ask here in…
Ariel Bold
  • 245
  • 2
  • 8
3
votes
3 answers

How to customize the form of rounding

My question may seem simple, but still can not get something that works. I need to customize the Math.round rounding format or something to make it work as follows: If the number is 1.6 he should round to 1, if greater than or equal to 1.7 should…
Raphael MM
  • 103
  • 8
3
votes
0 answers

Solving digit-only captcha

There is a captcha which I'm trying to solve, I know its always digits. When i try the command tesseract cap.png cap it returns empty page !!! When I try command tesseract cap.png cap -psm 6 digits && cat cap.txt it returns: [root@usa1 ~]#…
3
votes
3 answers

How to stop read.table from rounding numbers with different degrees of precision in R?

I am trying to import a text file containing latitudes and longitudes into R, which all have different degrees of precision (i.e. points after the decimal). When I try to use read.table, the data imports but cuts off at 5 decimal places. Is there…
user41569
  • 31
  • 1
  • 3
3
votes
1 answer

How can we efficiently count the digits in an integer in Elixir?

How can we efficiently count the digits in an integer in Elixir? My attempt in Iex iex(1)> a=100_000 100000 iex(2)> Enum.reduce(1..a, &(&1*&2))|> to_string|> String.length 456574 iex(3)> Takes over 15…
Charles Okwuagwu
  • 10,538
  • 16
  • 87
  • 157