All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 A Bit of a Problem (Posted on 2004-12-07)
Find the pattern of the following sequence and determine the next few terms:
`2, 10, 12, 38, 42, 52, 56, 142, 150, 170`

 See The Solution Submitted by DJ Rating: 4.0000 (2 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
 re: Solution (spoiler) -- different solution | Comment 3 of 17 |
(In reply to Solution (spoiler) by Larry)

I looked at the process differently, and get 212 and 232 as the next two terms in the sequence.

At each step, if one or more pairs of bits within the binary representation are "01" then change them to "10".  The result is the next number.  If, however, no "01" pairs occur in the binary representation, reverse all the bits, preface the reversed set with a "1" bit and tack a "0" bit at the end, and that's the next number.

The binary representation makes a nice diamond pattern when continued:

`2            1010           101012           110038           10011042           10101052           11010056           111000142          10001110150          10010110170          10101010212          11010100232          11101000240          11110000542          1000011110558          1000101110598          1001010110682          1010101010852          1101010100936          1110101000976          1111010000992          11111000002110         1000001111102142         1000010111102222         1000101011102390         1001010101102730         1010101010103412         1101010101003752         1110101010003920         1111010100004000         1111101000004032         1111110000008318         100000011111108382         100000101111108542         100001010111108878         100010101011109558         1001010101011010922        1010101010101013652        1101010101010015016        1110101010100015696        1111010101000016032        1111101010000016192        1111110100000016256        1111111000000033022        100000001111111033150        100000010111111033470        100000101011111034142        100001010101111035502        1000101010101110`

The program:

b\$ = "10"
FOR ct = 1 TO 48
n = 0
FOR i = 1 TO LEN(b\$)
n = n * 2 + VAL(MID\$(b\$, i, 1))
NEXT
PRINT n, b\$
b2\$ = b\$
FOR i = 2 TO LEN(b\$)
IF MID\$(b\$, i - 1, 2) = "01" THEN
MID\$(b2\$, i - 1, 2) = "10"
END IF
NEXT
IF b2\$ = b\$ THEN
b2\$ = "1"
FOR i = LEN(b\$) TO 1 STEP -1
b2\$ = b2\$ + MID\$(b\$, i, 1)
NEXT
b2\$ = b2\$ + "0"
END IF
b\$ = b2\$
NEXT

 Posted by Charlie on 2004-12-07 15:47:48

 Search: Search body:
Forums (0)