Instantly share code, notes, and snippets.

# Atlas7/bitwise.mdSecret Last active Jul 14, 2017

bitwise.md

I've recently bumped into this pretty interesting mini Intel Developer Zone challenge on Facebook:

How can you use eight 8s to get the number 1000?

So I decided to give it a go - and (I think) I successfully solved it. Took me 5 minutes experimenting.

The first thing I see when I see the number `8` is `2**3` (two to the power of 3). This implies it could be something to do with binary system.

Then I see the number `1000` - could this be binary `1000` (i.e. representing decimal number `8`)?

I ended up writing a one line Python 3.6 code:

``````print(bin(8 >> (8//8//8//8//8//8//8)))
``````

Evaluating the floor division `//`, the code effectively is the same as:

``````print(bin(8 >> 0))
``````

i.e. right shift the binary `1000` by 0 bit to `1000` (i.e. no change!). And of course this prints out:

``````0b1000
``````

Lesson learnt of the day!

``````888 + 88 + 8 + 8 + 8 = 1000
``````8888 / 8.888 = 1000