How to see if numbers have same digits in array?
I'm a bit stuck on one of my problems not because I don't know, but because I can't use more complex operations.(functions and multiple arrays)
So I need to make a program in C that ask for an input of an array(max 100 elements) and then program needs to sort that matrix by numbers with same digits.
So I made everything that I know, I tested my program with sorting algorithm from minimum to maximum values and it works, only thing that I can't understand is how should I test if the number have same digits inside the loop? (I can't use functions.)
So I know the method of finding if the number have the same digits but I don't know how to compare them. Here is an example of what I need.
This is what I have for now this sorts numbers from min to max.
#include <stdio.h>
int main()
int matrix[100];
int i,j;
int temp,min;
int elements_number=0;
printf("Enter the values of matrix-max 100 elements-type -1 to end: ");
for(i=0;i<100;i++)
scanf("%d",&matrix[i]);
elements_number++;
if(matrix[i]==-1)
elements_number--;
break;
for (i=0; i<elements_number; i++)
min=i;
for (j=i+1; j<elements_number; j++)
if (matrix[j] < matrix[min])
min = j;
temp = matrix[i];
matrix[i] = matrix[min];
matrix[min] = temp;
for(i=0;i<elements_number;i++)
if(i!=elements_number-1)
printf("%d,",matrix[i]);
else printf("%d.",matrix[i]);
return 0;
I need this output for these numbers:
INPUT :
1 22 43 444 51 16 7 8888 90 11 -1
OUTPUT:
1,22,444,7,8888,11,43,51,16,90.
Integers with 1 digit count as "numbers with same number of digits" like 7 and 1 in this example.
Hope that you can help.
c algorithm
add a comment |
I'm a bit stuck on one of my problems not because I don't know, but because I can't use more complex operations.(functions and multiple arrays)
So I need to make a program in C that ask for an input of an array(max 100 elements) and then program needs to sort that matrix by numbers with same digits.
So I made everything that I know, I tested my program with sorting algorithm from minimum to maximum values and it works, only thing that I can't understand is how should I test if the number have same digits inside the loop? (I can't use functions.)
So I know the method of finding if the number have the same digits but I don't know how to compare them. Here is an example of what I need.
This is what I have for now this sorts numbers from min to max.
#include <stdio.h>
int main()
int matrix[100];
int i,j;
int temp,min;
int elements_number=0;
printf("Enter the values of matrix-max 100 elements-type -1 to end: ");
for(i=0;i<100;i++)
scanf("%d",&matrix[i]);
elements_number++;
if(matrix[i]==-1)
elements_number--;
break;
for (i=0; i<elements_number; i++)
min=i;
for (j=i+1; j<elements_number; j++)
if (matrix[j] < matrix[min])
min = j;
temp = matrix[i];
matrix[i] = matrix[min];
matrix[min] = temp;
for(i=0;i<elements_number;i++)
if(i!=elements_number-1)
printf("%d,",matrix[i]);
else printf("%d.",matrix[i]);
return 0;
I need this output for these numbers:
INPUT :
1 22 43 444 51 16 7 8888 90 11 -1
OUTPUT:
1,22,444,7,8888,11,43,51,16,90.
Integers with 1 digit count as "numbers with same number of digits" like 7 and 1 in this example.
Hope that you can help.
c algorithm
2
If a number is between 10 and 99, it has the same digits if it's a multiple of 11. If it's between 100 and 999 test if it's a multiple of 111. If it's between1000 and 9999, test if it's a multiple of 1111. Do you see a pattern here?
– Barmar
Nov 15 '18 at 19:44
You mean, sorting by the number of unique digits?qsort
could do that easily, but it is not a stable sort (is stability important?) and it needs a function.
– Neil Edelman
Nov 15 '18 at 20:53
add a comment |
I'm a bit stuck on one of my problems not because I don't know, but because I can't use more complex operations.(functions and multiple arrays)
So I need to make a program in C that ask for an input of an array(max 100 elements) and then program needs to sort that matrix by numbers with same digits.
So I made everything that I know, I tested my program with sorting algorithm from minimum to maximum values and it works, only thing that I can't understand is how should I test if the number have same digits inside the loop? (I can't use functions.)
So I know the method of finding if the number have the same digits but I don't know how to compare them. Here is an example of what I need.
This is what I have for now this sorts numbers from min to max.
#include <stdio.h>
int main()
int matrix[100];
int i,j;
int temp,min;
int elements_number=0;
printf("Enter the values of matrix-max 100 elements-type -1 to end: ");
for(i=0;i<100;i++)
scanf("%d",&matrix[i]);
elements_number++;
if(matrix[i]==-1)
elements_number--;
break;
for (i=0; i<elements_number; i++)
min=i;
for (j=i+1; j<elements_number; j++)
if (matrix[j] < matrix[min])
min = j;
temp = matrix[i];
matrix[i] = matrix[min];
matrix[min] = temp;
for(i=0;i<elements_number;i++)
if(i!=elements_number-1)
printf("%d,",matrix[i]);
else printf("%d.",matrix[i]);
return 0;
I need this output for these numbers:
INPUT :
1 22 43 444 51 16 7 8888 90 11 -1
OUTPUT:
1,22,444,7,8888,11,43,51,16,90.
Integers with 1 digit count as "numbers with same number of digits" like 7 and 1 in this example.
Hope that you can help.
c algorithm
I'm a bit stuck on one of my problems not because I don't know, but because I can't use more complex operations.(functions and multiple arrays)
So I need to make a program in C that ask for an input of an array(max 100 elements) and then program needs to sort that matrix by numbers with same digits.
So I made everything that I know, I tested my program with sorting algorithm from minimum to maximum values and it works, only thing that I can't understand is how should I test if the number have same digits inside the loop? (I can't use functions.)
So I know the method of finding if the number have the same digits but I don't know how to compare them. Here is an example of what I need.
This is what I have for now this sorts numbers from min to max.
#include <stdio.h>
int main()
int matrix[100];
int i,j;
int temp,min;
int elements_number=0;
printf("Enter the values of matrix-max 100 elements-type -1 to end: ");
for(i=0;i<100;i++)
scanf("%d",&matrix[i]);
elements_number++;
if(matrix[i]==-1)
elements_number--;
break;
for (i=0; i<elements_number; i++)
min=i;
for (j=i+1; j<elements_number; j++)
if (matrix[j] < matrix[min])
min = j;
temp = matrix[i];
matrix[i] = matrix[min];
matrix[min] = temp;
for(i=0;i<elements_number;i++)
if(i!=elements_number-1)
printf("%d,",matrix[i]);
else printf("%d.",matrix[i]);
return 0;
I need this output for these numbers:
INPUT :
1 22 43 444 51 16 7 8888 90 11 -1
OUTPUT:
1,22,444,7,8888,11,43,51,16,90.
Integers with 1 digit count as "numbers with same number of digits" like 7 and 1 in this example.
Hope that you can help.
c algorithm
c algorithm
edited Nov 15 '18 at 20:57
chux
84.5k874157
84.5k874157
asked Nov 15 '18 at 19:12
stiMULAntstiMULAnt
23
23
2
If a number is between 10 and 99, it has the same digits if it's a multiple of 11. If it's between 100 and 999 test if it's a multiple of 111. If it's between1000 and 9999, test if it's a multiple of 1111. Do you see a pattern here?
– Barmar
Nov 15 '18 at 19:44
You mean, sorting by the number of unique digits?qsort
could do that easily, but it is not a stable sort (is stability important?) and it needs a function.
– Neil Edelman
Nov 15 '18 at 20:53
add a comment |
2
If a number is between 10 and 99, it has the same digits if it's a multiple of 11. If it's between 100 and 999 test if it's a multiple of 111. If it's between1000 and 9999, test if it's a multiple of 1111. Do you see a pattern here?
– Barmar
Nov 15 '18 at 19:44
You mean, sorting by the number of unique digits?qsort
could do that easily, but it is not a stable sort (is stability important?) and it needs a function.
– Neil Edelman
Nov 15 '18 at 20:53
2
2
If a number is between 10 and 99, it has the same digits if it's a multiple of 11. If it's between 100 and 999 test if it's a multiple of 111. If it's between1000 and 9999, test if it's a multiple of 1111. Do you see a pattern here?
– Barmar
Nov 15 '18 at 19:44
If a number is between 10 and 99, it has the same digits if it's a multiple of 11. If it's between 100 and 999 test if it's a multiple of 111. If it's between1000 and 9999, test if it's a multiple of 1111. Do you see a pattern here?
– Barmar
Nov 15 '18 at 19:44
You mean, sorting by the number of unique digits?
qsort
could do that easily, but it is not a stable sort (is stability important?) and it needs a function.– Neil Edelman
Nov 15 '18 at 20:53
You mean, sorting by the number of unique digits?
qsort
could do that easily, but it is not a stable sort (is stability important?) and it needs a function.– Neil Edelman
Nov 15 '18 at 20:53
add a comment |
1 Answer
1
active
oldest
votes
After processing the array, the single-digit numbers should all be in the left part of the array, the other numbers in the right part. Within each part, the original order of the elements should be preserved. This is called a stable partition. It is different from sorting, because the elements are only classified into two groups. Sorting means that there is a clear relationship between any two elements in the array.
This can be done by "filtering" the array for single-digit numbers and storing the other numbers that were filtered out in a temporary second array. Then append the contents of that second array to the (now shorter) first array.
Here's how that could work:
#include <stdlib.h>
#include <stdio.h>
void print(const int *arr, int n)
for (int i = 0; i < 10; i++)
if (i) printf(", ");
printf("%d", arr[i]);
puts(".");
int is_rep_digit(int n)
int q = n % 10;
n /= 10;
while (n)
if (n % 10 != q) return 0;
n /= 10;
return 1;
int main()
int arr[10] = 1, 22, 43, 444, 51, 16, 7, 8888, 90, 11;
int aux[10]; // auxliary array for numbers with several digits
int i, j, k;
print(arr, 10);
j = 0; // number of single-digit numbers
k = 0; // number of other numbers
for (i = 0; i < 10; i++)
if (is_rep_digit(arr[i]))
arr[j++] = arr[i]; // pick single-digit number
else
aux[k++] = arr[i]; // copy other numbers to aux
k = 0;
while (j < 10) // copy aux to end of array
arr[j++] = aux[k++];
print(arr, 10);
return 0;
Edit: I've just seen your requirement that you can't use functions. You could use Barmar's suggestion to test divisibility by 1, 11, 111 and so on. The tricky part is to find the correct divisor, however.
Anyway, the point I wanted to make here is that you don't need a full sorting algorithm here.
Thank you very much for the time and effort you put in writing the whole code, I can use parts of it to combine it with my code because i understand the logic now. I can put your is_rep_digit function inside the loop and use matrix[i] (as parameter n) to test if it is, if it is I would set a condition to 1(cond1==1 for example) if the numbers are same(if cond1==1) then use that index to put the element in first position of matrix and so on for other. Thanks !!
– stiMULAnt
Nov 15 '18 at 21:05
Yes. You could use a variableis_single
and set it to 1. Then, instead of returning 0 in the inner loop, set it to 0. (You can also break out of the loop for a minimal speed-up, but I woudn't worry about that in a smallproblem as yours.) Then you useis_single
to decide where to put your umber.
– M Oehm
Nov 16 '18 at 6:36
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326439%2fhow-to-see-if-numbers-have-same-digits-in-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
After processing the array, the single-digit numbers should all be in the left part of the array, the other numbers in the right part. Within each part, the original order of the elements should be preserved. This is called a stable partition. It is different from sorting, because the elements are only classified into two groups. Sorting means that there is a clear relationship between any two elements in the array.
This can be done by "filtering" the array for single-digit numbers and storing the other numbers that were filtered out in a temporary second array. Then append the contents of that second array to the (now shorter) first array.
Here's how that could work:
#include <stdlib.h>
#include <stdio.h>
void print(const int *arr, int n)
for (int i = 0; i < 10; i++)
if (i) printf(", ");
printf("%d", arr[i]);
puts(".");
int is_rep_digit(int n)
int q = n % 10;
n /= 10;
while (n)
if (n % 10 != q) return 0;
n /= 10;
return 1;
int main()
int arr[10] = 1, 22, 43, 444, 51, 16, 7, 8888, 90, 11;
int aux[10]; // auxliary array for numbers with several digits
int i, j, k;
print(arr, 10);
j = 0; // number of single-digit numbers
k = 0; // number of other numbers
for (i = 0; i < 10; i++)
if (is_rep_digit(arr[i]))
arr[j++] = arr[i]; // pick single-digit number
else
aux[k++] = arr[i]; // copy other numbers to aux
k = 0;
while (j < 10) // copy aux to end of array
arr[j++] = aux[k++];
print(arr, 10);
return 0;
Edit: I've just seen your requirement that you can't use functions. You could use Barmar's suggestion to test divisibility by 1, 11, 111 and so on. The tricky part is to find the correct divisor, however.
Anyway, the point I wanted to make here is that you don't need a full sorting algorithm here.
Thank you very much for the time and effort you put in writing the whole code, I can use parts of it to combine it with my code because i understand the logic now. I can put your is_rep_digit function inside the loop and use matrix[i] (as parameter n) to test if it is, if it is I would set a condition to 1(cond1==1 for example) if the numbers are same(if cond1==1) then use that index to put the element in first position of matrix and so on for other. Thanks !!
– stiMULAnt
Nov 15 '18 at 21:05
Yes. You could use a variableis_single
and set it to 1. Then, instead of returning 0 in the inner loop, set it to 0. (You can also break out of the loop for a minimal speed-up, but I woudn't worry about that in a smallproblem as yours.) Then you useis_single
to decide where to put your umber.
– M Oehm
Nov 16 '18 at 6:36
add a comment |
After processing the array, the single-digit numbers should all be in the left part of the array, the other numbers in the right part. Within each part, the original order of the elements should be preserved. This is called a stable partition. It is different from sorting, because the elements are only classified into two groups. Sorting means that there is a clear relationship between any two elements in the array.
This can be done by "filtering" the array for single-digit numbers and storing the other numbers that were filtered out in a temporary second array. Then append the contents of that second array to the (now shorter) first array.
Here's how that could work:
#include <stdlib.h>
#include <stdio.h>
void print(const int *arr, int n)
for (int i = 0; i < 10; i++)
if (i) printf(", ");
printf("%d", arr[i]);
puts(".");
int is_rep_digit(int n)
int q = n % 10;
n /= 10;
while (n)
if (n % 10 != q) return 0;
n /= 10;
return 1;
int main()
int arr[10] = 1, 22, 43, 444, 51, 16, 7, 8888, 90, 11;
int aux[10]; // auxliary array for numbers with several digits
int i, j, k;
print(arr, 10);
j = 0; // number of single-digit numbers
k = 0; // number of other numbers
for (i = 0; i < 10; i++)
if (is_rep_digit(arr[i]))
arr[j++] = arr[i]; // pick single-digit number
else
aux[k++] = arr[i]; // copy other numbers to aux
k = 0;
while (j < 10) // copy aux to end of array
arr[j++] = aux[k++];
print(arr, 10);
return 0;
Edit: I've just seen your requirement that you can't use functions. You could use Barmar's suggestion to test divisibility by 1, 11, 111 and so on. The tricky part is to find the correct divisor, however.
Anyway, the point I wanted to make here is that you don't need a full sorting algorithm here.
Thank you very much for the time and effort you put in writing the whole code, I can use parts of it to combine it with my code because i understand the logic now. I can put your is_rep_digit function inside the loop and use matrix[i] (as parameter n) to test if it is, if it is I would set a condition to 1(cond1==1 for example) if the numbers are same(if cond1==1) then use that index to put the element in first position of matrix and so on for other. Thanks !!
– stiMULAnt
Nov 15 '18 at 21:05
Yes. You could use a variableis_single
and set it to 1. Then, instead of returning 0 in the inner loop, set it to 0. (You can also break out of the loop for a minimal speed-up, but I woudn't worry about that in a smallproblem as yours.) Then you useis_single
to decide where to put your umber.
– M Oehm
Nov 16 '18 at 6:36
add a comment |
After processing the array, the single-digit numbers should all be in the left part of the array, the other numbers in the right part. Within each part, the original order of the elements should be preserved. This is called a stable partition. It is different from sorting, because the elements are only classified into two groups. Sorting means that there is a clear relationship between any two elements in the array.
This can be done by "filtering" the array for single-digit numbers and storing the other numbers that were filtered out in a temporary second array. Then append the contents of that second array to the (now shorter) first array.
Here's how that could work:
#include <stdlib.h>
#include <stdio.h>
void print(const int *arr, int n)
for (int i = 0; i < 10; i++)
if (i) printf(", ");
printf("%d", arr[i]);
puts(".");
int is_rep_digit(int n)
int q = n % 10;
n /= 10;
while (n)
if (n % 10 != q) return 0;
n /= 10;
return 1;
int main()
int arr[10] = 1, 22, 43, 444, 51, 16, 7, 8888, 90, 11;
int aux[10]; // auxliary array for numbers with several digits
int i, j, k;
print(arr, 10);
j = 0; // number of single-digit numbers
k = 0; // number of other numbers
for (i = 0; i < 10; i++)
if (is_rep_digit(arr[i]))
arr[j++] = arr[i]; // pick single-digit number
else
aux[k++] = arr[i]; // copy other numbers to aux
k = 0;
while (j < 10) // copy aux to end of array
arr[j++] = aux[k++];
print(arr, 10);
return 0;
Edit: I've just seen your requirement that you can't use functions. You could use Barmar's suggestion to test divisibility by 1, 11, 111 and so on. The tricky part is to find the correct divisor, however.
Anyway, the point I wanted to make here is that you don't need a full sorting algorithm here.
After processing the array, the single-digit numbers should all be in the left part of the array, the other numbers in the right part. Within each part, the original order of the elements should be preserved. This is called a stable partition. It is different from sorting, because the elements are only classified into two groups. Sorting means that there is a clear relationship between any two elements in the array.
This can be done by "filtering" the array for single-digit numbers and storing the other numbers that were filtered out in a temporary second array. Then append the contents of that second array to the (now shorter) first array.
Here's how that could work:
#include <stdlib.h>
#include <stdio.h>
void print(const int *arr, int n)
for (int i = 0; i < 10; i++)
if (i) printf(", ");
printf("%d", arr[i]);
puts(".");
int is_rep_digit(int n)
int q = n % 10;
n /= 10;
while (n)
if (n % 10 != q) return 0;
n /= 10;
return 1;
int main()
int arr[10] = 1, 22, 43, 444, 51, 16, 7, 8888, 90, 11;
int aux[10]; // auxliary array for numbers with several digits
int i, j, k;
print(arr, 10);
j = 0; // number of single-digit numbers
k = 0; // number of other numbers
for (i = 0; i < 10; i++)
if (is_rep_digit(arr[i]))
arr[j++] = arr[i]; // pick single-digit number
else
aux[k++] = arr[i]; // copy other numbers to aux
k = 0;
while (j < 10) // copy aux to end of array
arr[j++] = aux[k++];
print(arr, 10);
return 0;
Edit: I've just seen your requirement that you can't use functions. You could use Barmar's suggestion to test divisibility by 1, 11, 111 and so on. The tricky part is to find the correct divisor, however.
Anyway, the point I wanted to make here is that you don't need a full sorting algorithm here.
edited Nov 15 '18 at 20:39
answered Nov 15 '18 at 20:07
M OehmM Oehm
21.6k31832
21.6k31832
Thank you very much for the time and effort you put in writing the whole code, I can use parts of it to combine it with my code because i understand the logic now. I can put your is_rep_digit function inside the loop and use matrix[i] (as parameter n) to test if it is, if it is I would set a condition to 1(cond1==1 for example) if the numbers are same(if cond1==1) then use that index to put the element in first position of matrix and so on for other. Thanks !!
– stiMULAnt
Nov 15 '18 at 21:05
Yes. You could use a variableis_single
and set it to 1. Then, instead of returning 0 in the inner loop, set it to 0. (You can also break out of the loop for a minimal speed-up, but I woudn't worry about that in a smallproblem as yours.) Then you useis_single
to decide where to put your umber.
– M Oehm
Nov 16 '18 at 6:36
add a comment |
Thank you very much for the time and effort you put in writing the whole code, I can use parts of it to combine it with my code because i understand the logic now. I can put your is_rep_digit function inside the loop and use matrix[i] (as parameter n) to test if it is, if it is I would set a condition to 1(cond1==1 for example) if the numbers are same(if cond1==1) then use that index to put the element in first position of matrix and so on for other. Thanks !!
– stiMULAnt
Nov 15 '18 at 21:05
Yes. You could use a variableis_single
and set it to 1. Then, instead of returning 0 in the inner loop, set it to 0. (You can also break out of the loop for a minimal speed-up, but I woudn't worry about that in a smallproblem as yours.) Then you useis_single
to decide where to put your umber.
– M Oehm
Nov 16 '18 at 6:36
Thank you very much for the time and effort you put in writing the whole code, I can use parts of it to combine it with my code because i understand the logic now. I can put your is_rep_digit function inside the loop and use matrix[i] (as parameter n) to test if it is, if it is I would set a condition to 1(cond1==1 for example) if the numbers are same(if cond1==1) then use that index to put the element in first position of matrix and so on for other. Thanks !!
– stiMULAnt
Nov 15 '18 at 21:05
Thank you very much for the time and effort you put in writing the whole code, I can use parts of it to combine it with my code because i understand the logic now. I can put your is_rep_digit function inside the loop and use matrix[i] (as parameter n) to test if it is, if it is I would set a condition to 1(cond1==1 for example) if the numbers are same(if cond1==1) then use that index to put the element in first position of matrix and so on for other. Thanks !!
– stiMULAnt
Nov 15 '18 at 21:05
Yes. You could use a variable
is_single
and set it to 1. Then, instead of returning 0 in the inner loop, set it to 0. (You can also break out of the loop for a minimal speed-up, but I woudn't worry about that in a smallproblem as yours.) Then you use is_single
to decide where to put your umber.– M Oehm
Nov 16 '18 at 6:36
Yes. You could use a variable
is_single
and set it to 1. Then, instead of returning 0 in the inner loop, set it to 0. (You can also break out of the loop for a minimal speed-up, but I woudn't worry about that in a smallproblem as yours.) Then you use is_single
to decide where to put your umber.– M Oehm
Nov 16 '18 at 6:36
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326439%2fhow-to-see-if-numbers-have-same-digits-in-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
If a number is between 10 and 99, it has the same digits if it's a multiple of 11. If it's between 100 and 999 test if it's a multiple of 111. If it's between1000 and 9999, test if it's a multiple of 1111. Do you see a pattern here?
– Barmar
Nov 15 '18 at 19:44
You mean, sorting by the number of unique digits?
qsort
could do that easily, but it is not a stable sort (is stability important?) and it needs a function.– Neil Edelman
Nov 15 '18 at 20:53