A Selfish Number

General — Alex @ 8:35 pm

Here’s what I call the `selfish’ number problem:

Find a ten digit number a_0a_1a_2a_3a_4a_5a_6a_7a_8a_9 which satisfies the condition that there are a_k occurences of the digit k in the number.

This was a fun problem, although I had trouble getting what it was asking for at first— for some reason, I imagined the digits weren’t repeatable, but that makes the problem obviously impossible. Then I tried constructing a list of how many times each digit could possibly occur (e.g. no digit can occur 9 times), and cross referencing the lists to form a number that works.

Ironically, I didn’t get the problem until after I had wrote a code to exhaustively test all ten digit numbers, using brute force (yep, searching 10^9 numbers). I said, yeah that’s a lot of numbers, but still, this can be done in a reasonable amount of time… ha ha. When I realized not, I ended up trying basically the same list construction that I mention before, to optimize the number space being searched (e.g. the for loop that determined a_0 doesn’t have to go all the way from 0 to 9). In doing this, I found the answer.

I didn’t realize it at the time, but the answer is obviously unique. I think I was doing this around 1 in the morning, and was already dead exhausted before starting, so I forgive myself.

Possibly relevant posts:

0 Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2008 ChapterZero | powered by WordPress with Barecity