Write a Regular Expression which identifies numbers divisible by 11 [closed] - regex

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
For a study I am doing everyone gets assigned a unique number.
All unique numbers are divisble by 11 (this is done because it makes sequential numbers quite different from each other).
I would ideally like a regex which I can use to check that the number entered in the study_id field is an acceptable value - e.g divisible by 11.
I will have leading zeroes to a maximum of 5 digits
So:
00011 - Acceptable
00012 - Not Acceptable
13211 - Acceptable
13221 - Not Acceptable
Any suggestions gratefully received

This isn't possible because there are no textual similarities between numbers that are divisible by 11. Regex is used for text matching.
For example 000165 is divisible by 11 as is 00011.
The best way to validate the number is to divide it by 11 and see if there is any remainder. So in Excel you'd do this:
=IF(MOD(165, 11) = 0, "VALID", "INVALID")
Or C# you'd do something like this
bool isValid = 165 % 11 == 0;
(Disclaimer I'm not familiar with ODK so I can't provide a suitable sample; I've just guessed on the best language to write in)

Related

Is there a way to enter a number through another number? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm taking a C++ class in school, (No experience with programming) so I realize that this is a very dumb question and also horribly worded but here it is:
Is there any way to enter 6-21 (As in 6 through 21) into a boolean expression? I've tried it like this:
if (regs = 6-21)
But it assumes that I'm trying to subtract. What I'm trying to ask is, is there a way to enter a number through another number? Is it even possible?
Here is how you do it:
if (regs >= 6 && regs <= 21) {
// some code
}
>= means "greater than or equal to".
<= means "less than or equal to".
&& means "and", as in "if this AND this is true".

How do i take fifth power of a number in c [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I am creating a gp calculator in c++ ,But in gp the formulae has common ratio to the power of the term number. in order to get calculate that term i need to know how do i take the number as power for some other number, is there any operator for doing this.
If both arguments are floating point numbers, you have to use formula xᵐ = exp(m log x).
Supposedly std::pow does that for you. If your program requires to match some particular test patterns, further investigation may be required.
Know your <math>
As long as x != 0 to get any power:
exp(log(x)*power)
The interesting tidbit here is that if power is 1.0/y it will extract the y-root of the value.

C++: Decimal to Roman Numeral conversion [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I know how to do this and have made a program that does so in the past, however it never incorporated the special cases of roman numerals (e.g. IV = 4). Integrating that into a functional program in a minimalistic way is my main problem. Is there a good way to do this?
A very simple solution, in pseudo-code, could look something like this:
value = get_the_value_to_convert();
divider = 1000; // Start at 1000 (M)
while (value > 0)
{
count = value / divider;
value = value % divider;
for (i = 0; i < count; ++i)
print(roman_numeral_from_number(divider));
divider /= 10;
}
The roman_numeral_from_numbe function does a one-to-one mapping between a number and a roman numeral.
For e.g. 5432 as input it would print MMMMMCCCCXXXII.
For better results, divide the divider variable with 2 and 5 every second time.
For even better results, add check for certain numbers, like 90 being equal to "XC".
Note that even with the modifications, the above algorithm can't handle very large numbers, but on the other hand Wikipedia states that historically it was only used for small numbers anyway.

C++ prime number logic [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm creating a program that will output whether a number is prime or not. although, I'm trying to make it a little more complicated. I created a vector which I now want to store every prime number up to and including the number input by the user.
And then for the number input by the user (i.e. if the user types 13) will return true for the function hence it is a prime number. Here are some examples:
**U
primechecker() : plist(2) {;}
bool operator()(int);
3 5 7
then 3 5 6 7 7
The reason your vector is starting with two zeros is because you are initializing it with two elements of the default constructor:
primechecker() : plist(2)
Check out the documentation of std::vector (you are using the 'fill constructor')

regular expression for amount enclosed [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
This regular expression
/^\d{1,6}(?:\.\d{0,2})?$/
limits the user to only 6 digits.
How to make this regex work to allow any number of digits(no max limit)
How to make this regex optional
Assuming you just mean any number of digits followed by any single character followed by 2 digits, then use:
/^\d+(?:.\d{0,2})?$/
If 0 is ok, then:
/^\d*(?:.\d{0,2})?$/
I think you actually are trying to find money values (dollar and cents) which would likely be this instead:
/^\d*(?:\.\d{0,2})?$/
Your regex limits it to 1-6 digits, followed by an optional 0-2 decimals.
To remove the limit, remove the {1,6} and replace with + and to make it optional, wrap in (...)?:
/(^\d+(?:\.\d{0,2})?$)?/
This make the input, if provided, still require at least 1 digit before the decimal place.
To make the first part match one or more digits, you can change it to /^\d+(?:.\d{0,2})?$/.
It's a bit confusing what you mean by 'optional', so I'm not sure what to suggest there.