Check if a given 8-bit Number is sparse

0

The task is the following:

Program the shortest fully functional program that checks, if an 8-bit value contains a consecutive sequence of 2 or more ones in its binary form.

If it does contain such a sequence, the output shall be 0. If not: 1.

Examples:

Input: 1 Output: 1

Input: 3 Output: 0

Input: 72 Output: 1

Input: 75 Output: 0


The shortest solution wins!

DPF

Posted 2015-10-19T13:40:18.233

Reputation: 101

Question was closed 2015-10-19T14:32:07.503

2Welcome to PPCG! I'm a little confused though, so may I ask a few questions? 1) "If this is the case, the output shall be 1, if not: 1." Should one of these be a 0? and 2) Does a sequence mean a consecutive sequence like 11? If so, how do the last two cases work? (72 = 1001000, 73 = 1001001) – Sp3000 – 2015-10-19T13:47:18.820

Closely related. – Martin Ender – 2015-10-19T13:53:29.930

you're completely right. It was a typo and I mean indeed consecutive series of ones :) – DPF – 2015-10-19T13:53:55.023

1

I fixed one more place where the typo was, and added the "code-golf" tag. I strongly suggest that you read the tag wiki to get a general idea of what the tag is about. There are some folks checking for duplicates of your question. If they find none, I'm sure they will vote to reopen your question. Welcome to PPCG!

– Rainbolt – 2015-10-19T13:56:16.690

I do think this is a duplicate of the challenge I linked. The only real golfing trick that can be applied here is x&2*x which almost all of the answers on the other challenge already use. All answers to this challenge would do is taken an answer from there and remove the loop. – Martin Ender – 2015-10-19T14:32:53.327

I think, you're right. Didn't see it. – DPF – 2015-10-19T15:20:30.220

No answers