Followers 0

# Unknown string of numbers..

## 15 posts in this topic

(retracted, was slightly wrong)

Edited by Nypyren
2

##### Share on other sites
Your method would produce 877, but that wasn't in the list.
All numbers should again not have two times the same number except for the nine.
Edited by ProtectedMode
0

##### Share on other sites

Alvaro, I still can't really code a program to generate this numbers in c++. Why your method produce 9988?

0

##### Share on other sites

Alvaro, I still can't really code a program to generate this numbers in c++.

Here it is in C++:

#include <iostream>

bool check_histogram_of_digits_is_weakly_increasing(unsigned long x) {
int histogram[10] = {0};

do {
histogram[x % 10]++;
x /= 10;
} while (x > 0);

for (int i=0; i<9; ++i) {
if (histogram[i] > histogram[i+1])
return false;
}

return true;
}

int main() {
for (int i=1; i<10000; ++i) {
if (check_histogram_of_digits_is_weakly_increasing(i))
std::cout << i << '\n';
}
}


Because its histogram of digits is (0,0,0,0,0,0,0,0,2,2), which is weakly increasing. Edited by Álvaro
2

##### Share on other sites

Thank you very much Alvaro. I don't really understand what " histogram of digits is weakly increasing" means but I found an article about histograms on wikipedia. I will read it and hopefully understand it. Thank you.

Edited by Bratie Fanut
0

##### Share on other sites

Thank you very much Alvaro. I don't really understand what " histogram of digits is weakly increasing" means but I found an article about histograms on wikipedia. I will read it and hopefully understand it. Thank you.

"Histogram" is just a fancy name for "one counter for each possible value". I think my C++ code should be fairly easy to read, but I'll give you a couple of examples in English.

Let's see why the number 799 is not in the list. Let's count how many times each digit appear in 799: "0" appears 0 times, "1" appears 0 times, ..., "7" appears 1 time, "8" appears 0 times and "9" appears 2 times. Putting all ten counters in a row, it's (0,0,0,0,0,0,0,1,0,2), and this is what I am calling the "histogram". As you see there are more "7"s than "8"s, so this sequence is not weakly increasing.

Let's now see why the number 989 is in the list. The histogram is (0,0,0,0,0,0,0,0,1,2). This is weakly increasing (i.e., every number is either the same as the one before it or larger).

Oohh.. I understand now :) And understand why on wikipedia on histogram article was a lot of graphics and statistics  Thank you very much.

0

## Create an account

Register a new account