Intel's Ronler Acres Plant

Silicon Forest
If the type is too small, Ctrl+ is your friend

Friday, May 25, 2018


I've been spending time on Quora recently. Many of the questions posted there are inane, but every once in a while I find something interesting, and I can usually find a simple math or algebra problem that is challenging enough to keep me entertained for a few minutes but not so difficult that it will strain my brain. Today I ran into this one:
How many ways are there to create a six digit number using digits from 0 to 9 without repetition such that the number has the digit 7 and exactly 3 even numbers?
 Usually these kinds of problems can be solved by simply multiplying some numbers together. For instance, the number of 6 digit numbers is 900,000, which is just 9 times 10 to the fifth power. You start with 9 because anything that starts with zero is not going to be a six digit number, so the first 100,000 numbers get lopped off immediately.

After that it gets a little tricky. I thought about it for a minute and then decided that it would be easier to write a simple computer program to count all the possibilities. There might be a way to calculate the answer, but there might not. A computer program can do it for sure and it shouldn't take that long to write. Besides, the program will use recursion and I have another program that uses recursion that has had my stymied for a couple of weeks, so writing this one will be like a tune up for my brain.

The program was easy enough to write, but it didn't work. Took me a couple of hours of mucking about to sort out what all the problems were. Muddy thinking was the big one.

The answer I got was 38,880, which agrees with the only other answer that was posted, and that person got it the same way I did: by writing a computer program. He wrote his using Python, I used C. You can see mine on github.

I am still not totally sold on github, they still insist on displaying everything with tabs set to 8 spaces. I use 4 spaces. I like 4 spaces. Why does github have to be so contrary? To their credit, they do allow you to set the tab spacing in their editor to 4 spaces, though they call it indent, which technically should only apply to the beginning of the line. Whatever. But when you leave edit mode, it goes back to 8 spaces and all your pretty formatting goes to shit.

No comments: