Challenge 42
🌌
42
In pop culture, the number 42 is infamous after being popularised by the Hitchhiker's Guide to the Galaxy, in which it's jokingly referred to as the answer to the "ultimate question of life, the universe and everything"
The number 42 also has some interesting mathematical properties:
- It is a binary palindrome (that is it is the same in reverse and forward order), consisting of an alternating series of "01" - "0101010"
- The ASCII value of 42 is the asterix "*"
- Rainbows are formed when the angle between the observer, raindrop and sunlight are 42 degrees
- It was the only number less than 100 until recently that didn't have a solution for the sum of 3 cubes problem
- Is represents as "MB" in Greek numerals
- And has other mathematical properties
For this task, let's focus on binary palindromes - create a function that takes an input denary number and outputs whether its two's complement binary representation is a palindrome
Examples:
isBinaryPalindrome(42) returns true
isBinaryPalindrome(6) returns true
isBinaryPalindrome(-7) returns true
isBinaryPalindrome(-6) returns false
Extension:
Output all the binary palindromes in the range -1024 to 1023