In another thread, CrashTech posted a link to a programming interview problem that exposes the incompetence of many "professional" programmers. This thread posts a slight modification of that problem statement, and will hopefully show how competent all of us can be...

Problem: Interestingly enough, most multiples of 15 (at least for those < 1000) when displayed in binary contain four values of 1. For example, the number 15 expressed in binary is 1111. Here is a table with the first 8 multiples of 15, and as you can see, all of them contain 4 1's.

Now clearly, there are a few multiples of 15 that do not contain 4 1's in them. For example, 495 is 111101111 in binary.

Question #1 (EASY): What is the largest multiple of 15 that you can find that does not contain 4 1's in binary? This will be an ongoing search like the search for the largest prime number.

Question #2 (HARD): Can you prove that either (a) there an infinite number of multiples of 15 that do not contain 4 1's or (b) there are a finite number. Major kudos to anyone who can express this as a proof.

Question #3 (????): Are there any multiple of 15 with fewer than 4 1s in them?

Question #1 (EASY): What is the largest multiple of 15 that you can find that does not contain 4 1's in binary? This will be an ongoing search like the search for the largest prime number.

Question #2 (HARD): Can you prove that either (a) there an infinite number of multiples of 15 that do not contain 4 1's or (b) there are a finite number. Major kudos to anyone who can express this as a proof.

Question #3 (????): Are there any multiple of 15 with fewer than 4 1s in them?

To save us some pain, please use something like the following syntax:

#1 -- 495 111101111

#1 -- 4,294,967,280 11111111 11111111 11111111 11110000 (28 bits set)
With good ol' Turbo C, the largest integer I can find with more than 4 bits set

#2 -- No!

#3 -- There are no multiples of 15 less than 4 billion, that have less than four 1 bits in them.

I wrote this C program in Turbo C, but have little experience with bit operations.

Any number x expressed in binary may be doubled by adding a zero to the end of its bit string.

Code:

x = 2, x(bin) = 102x = 4, 2x(bin) = 100

For any number which contains 15 as a factor and is doubled, the resulting product will also have 15 as a factor by the associative property of multiplication.

Code:

15 = 15 * 1 30 = 15 * 2X = 15 * y2X = 15 * 2y

Therefore, given any number X which is a multiple of 15 and does not have 4 ones in its bit string, that number can be doubled an infinite number of times to produce an infinite series of multiples of 15 which do not have 4 1s in their bit string.

Or, For any x such that x is a multiple of 15 and does not have 4 ones in its bit string, 2^n * X also does not have 4 ones in its bit string for all n > 0, n = integer.

Since we know that at least one number exists that satisfies x, there are an infinite number of multiples of 15 whose bit string do not contain 4 1s.

Adak! It has been a LONG time. WTH, you're programming in Turbo-C now?! BTW, your submission to problem #1 is valid.

Adak wrote:

#2 -- No!

LMAO... you wimp! =)

Adak wrote:

#3 -- There are no multiples of 15 less than 4 billion, that have less than four 1 bits in them.

I didn't come up with any three 1 bits multiples of 15 either. I had previously ran the code below overnight and it didn't pop out anything, but I didn't have it printing out where it had left off either.

Here is the code that I'm using for the <4 1-bits problem... It appears to be a bit shorter than yours! =P

#2: For any x such that x is a multiple of 15 and does not have 4 ones in its bit string, 2^n * x also does not have 4 ones in its bit string for all n > 0, n = integer.

Not only does it have not have 4 ones, but it is the same bit string with an additional 0 on the right.

If we define a proper bit-string as a bit-string with any 0's to the right of the right-most 1 removed, we create a mapping from the smallest multiple of 15 with this proper bit-string to all of the other bit-strings that are some multiple of 2 larger.

5) Are there an infinite or finite number of proper bit-strings that are a multiple of 15 with four 1 bits set? (proof)

6) What is the largest proper bit-string someone can come up with? (similar to the largest prime)

Y'all have a lot more education than I do. What I do have, is decidedly rusty with a capital 'R'. Especially math!

For smaller programs, I prefer Turbo C to Visual C. Turbo C has special extensions to facilitate bit handling, but I didn't use them. I wanted a more "standard" program.

WHAT is that language you're programming in Gadget? I know you prefer some of the less popular languages.

For a laugh, if you haven't done so already, check out the language "Brainphuck" (with an 'f'), on Wikipedia. It's hard not to roll on the floor in fits of laughter, just looking it over.

"Overnight" runs?

I know C has been described as having the language elegance of two tin cans and a piece of string, but it does romp. My code runs are done in 1/2 -5 minutes, depending on how much output I have it set for. Have to comment out the getchar()'s of course.

And my code isn't efficient - it always continues to the end of the a[] array values, even though it can't use them any more. I left it like this because it makes looking at the code, easier.

I wrote a new version looking for the first multiple of 15 with three 1 bits set. Instead of searching multiples of 15, I decided to do something a bit more intelligent. A "proper" bit-string will have both the first and last bits set to 1, therefore you only need to set one more bit to 1 within the bit-string and check to see if the value is a multiple of 15. There is an example in the code below that makes everything very clear.

So far, I've check all bit-strings up to 500 bits in length and didn't find a single match. I'll check through 1000 before stopping the search.

WHAT is that language you're programming in Gadget? I know you prefer some of the less popular languages.

That is Common Lisp. IIRC, wasn't an older version of BASIC your language of choice a few years back?

Adak wrote:

For a laugh, if you haven't done so already, check out the language "Brainphuck" (with an 'f'), on Wikipedia. It's hard not to roll on the floor in fits of laughter, just looking it over.

I'm somewhat familiar with the language due to stories from other people, but I haven't tried to do anything with it. Someday I'll do a small program in it. I hear that even a simple program is a very sobering experience.

Adak wrote:

I know C has been described as having the language elegance of two tin cans and a piece of string, but it does romp. My code runs are done in 1/2 -5 minutes, depending on how much output I have it set for. Have to comment out the getchar()'s of course.

I was just letting it run in the interpreter without having compiled the code. See if you can beat this one...

Here, I check all of the candidate 3 1-bit set bit-strings up to 100 bits in length in a tenth of a second.

...A "proper" bit-string will have both the first and last bits set to 1, therefore you only need to set one more bit to 1 within the bit-string and check to see if the value is a multiple of 15.

So far, I've check all bit-strings up to 500 bits in length and didn't find a single match. I'll check through 1000 before stopping the search.

That is Common Lisp. IIRC, wasn't an older version of BASIC your language of choice a few years back?

QuickBasic (which has both an interpreter and a compiler), was my programming "refuge" for a long time. I took a one semester course in C, but then didn't use it for much, and forgot a lot. Thanks to a couple good C books, and some C forums, I've learned quite a bit. C is my language of choice for everything, now.

I have never heard of "proper" bit strings having two bits already set to 1. I was using unsigned long's with 4 bytes each. None of the bits are already set to 1, in my program. "They get their 1 the hard way -- they earn it."

Unclear about the rightmost bit being set to 1 all the time, in your program. Think of 30, etc. The right hand bit is zero in these cases.

Your program romps, but it's doing a different job. Common Lisp is obviously a very expressive language.

If I understand Jipstyle's post, we won't be finding any multiples of 15 with less than 4 bits set, no matter how far out we search. No instance being found in the first 4 billion numbers, we won't find any multiplies of that number which have less than 4 bits set, either.

Update:I've check all of the "proper", or perhaps reduced is a better term, bit-strings up to 10,000 bits in length. That is probably sufficient evidence for someone to begin a proof of why there are no three 1-bits set bit-strings that are a multiple of 15. If I have time, I'll start on it later today.

Also, there appear to be an infinite number of multiples of 15 that are a "proper or reduced bit-string". Another proof!

Adak wrote:

If I understand Jipstyle's post, we won't be finding any multiples of 15 with less than 4 bits set, no matter how far out we search. No instance being found in the first 4 billion numbers, we won't find any multiplies of that number which have less than 4 bits set, either.

No... darn old guys... I swear! =)I'll explain the proof that he provided below.

Adak wrote:

I have never heard of "proper" bit strings having two bits already set to 1.<snip>Unclear about the rightmost bit being set to 1 all the time, in your program. Think of 30, etc. The right hand bit is zero in these cases.

I created the ad hoc definition of a "proper bit-string" a couple of posts back after thinking about the proof that Jipstyle provided. He showed that if a number is a multiple of 15, lets start with 15 (1111) or 3*5 factored, then we can simply multiple by 2, and so will 30, 60, 120, 240... to infinity, and beyond!

Each is clearly a multiple of 15 due to the prime factors 3 and 5 never being disturbed (multiplying by 2 simply adds a 0 to the right). The notion of a "proper" bit-string came from thinking about this in reverse. If I give you any binary number that is a multiple of 15 and the right-most bit is a 0, we can immediately remove the 0 from the right (ie divide by 2), and we will now have a smaller multiple of 15 (as the prime factors of 3 and 5 are unchanged). Do this until the right-most bit is a 1, and we have what I have been calling a "proper" bit-string (again, perhaps reduced is a better term).

Instead of searching through all multiples of 15 for a number with only three 1-bits set, I've reduced the search space enormously by only searching for a "proper" bit-string. Of course, if I were to find one, then we know that there are an infinite number of multiples of 15 by the proof that Jipstyle provided.

Before I begin, I will say there is one assumption I've made: that since 3 and 5 both have two bits, then 3*5 will result in 15 with four bits. Therefore, any modification to 15 that would result in 15 with fewer than four 1s, would result in 3 and/or 5 having one 1. So, in order to prove all multiples of 15 have at least four 1s, I prove that all multiples of 3 and 5 have at least two 1s.

All multiples of 15 can be expressed as 15*x. It can further be broken down as even multiples (where x = 2n) and odd multiples (where x = 2n+1).even:2n15 = 2*3*5*nfor an even multiple of 15 to not have four bits, one of the following must be true:5n=2^x or 3n=2^x, because one of the factors of 15 must have only one bit.

5n=2^x:For 5 to be a factor of 2^x, 2^x must have a 0 or 5 in the ones column (decimal)

Looking at the 3 right furthest bits, a pattern emerges: 011, 110, 001, 100, 111, 010, 101, and 000. The only time that a multiple of 3 can have only one 1, is every 8th multiple. So we need to prove 3*8n will always have two or more 1s.3*8n = 3*4*2n = 12*2n:

Again, looking at the 3 right furthest bits, a pattern emerges: 100 and 000. For every multiple that has a 000 as its three right most bits, it is two times a previous multiple; since the previous multiple has at least two 1s, the current multiple also has two 1s.

Therefore, 3n != 2^x. Since 3n != 2^x and 5n != 2^x, even multiples of 15 will have at least four 1s.

odd:(2n+1)15 = (2n+1)3*5, (2n+1)3 = n_1, (2n+1)5 = n_2For an odd multiple of 15 to not have four bits one of the following must be true:5n_1=2^x or 3n_2=2^x, because one of the factors of 15 must have only one bit.

Since 5n_1 != 2^x and 3n_2 != 2^x has already been proven above, odd multiples of 15 will have at least four 1s.

Since odd and even multiples of 15 have at least four 1s, all multiples of 15 have at least four 1s.

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum