Euler Project Question 36

I am up to question 36 , and I thought it would be easy. As usual, I'm apparently mistaken. I am trying to do this in Python (because I do not know Python). My code is below. As a conclusion, I get 19, which seems to be wrong. I do not see what I am missing. Any suggestions (without correcting the code) will be appreciated. I don't need the right answer or code (or even the exact location of my error) - just a hint to lead me in the right direction.

 def isPolynomial(number):
    if(str(number) == str(number)[::-1]):
        return True
    else:
        return False
def isBinaryPolynomial(number):
    binNum = bin(number)
    binStr = str(binNum)[2:]
    revbinStr = binStr[::-1]
    if(binStr == revbinStr):
        return True
    else:
        return False
count = 0
for i in range(1, 1000001):
    if isPolynomial(i):
        if isBinaryPolynomial(i):
            count += 1
print count
+3
source share
4 answers

It looks like your code is correct, but you need to carefully read what it asks to provide as an answer. I can’t be more specific without giving it away!

+6
source

The question asks for the sum of the numbers, not the score. Nor does it affect the answer you get, but the word "Palindrome" and not "Polynomial"

+1
source
# - * - coding: utf-8 - * -
"" "
@author: neo
"" "
def bin (x):
    result = ''
    x = int (x)
    while x> 0:
        mod = x% 2
        x / = 2
        result = str (mod) + result
    return result
print sum (i for i in xrange (1,1000001) \
    if str (i) == str (i) [:: - 1] and str (bin (i)) == str (bin (i)) [:: - 1])
-1
source

All Articles