+ 1
* Beginner Project Idea *
Reversible Odd Numbers Take a number, reverse it, add it to itself, and check the sum for only odd numbers. x + reverse(x) = a a can contain no even digits examples 18 + 81 = 99 .. 18 is a reversible odd number. it has 0 even numbers in the sum. 67 + 76 = 143 .. 67 has an even number in its sum, so it is not a reversible odd number. How many Reversible Odd Numbers are there in a million numbers?
6 ответов
+ 1
Hi, I think I made it, check out my new code and tell me if it fails/works
+ 1
total=0
even=0
odd=0
sums=[]
for i in range(100):
sums=[]
n=str(i)
r=n[::-1]
n=int(n)
r=int(r)
c=n+r
c=str(c)
for i in c:
sums.append(int(i))
even=0
odd=0
for i in sums:
if i%2 !=0:
odd=odd+1
else:
even=even+1
if even==0:
print(n, end=' ')
print("+", end=' ')
print(r, end=' ')
print("=", end=' ')
print(c)
total=total+1
print("\nTotal = %d" %total)
Here is mine. yours is probably much more efficient, but I get there lol
0
Hi, I don't fully understand the idea but if you give further explanation I will give it a try
0
start with number 1. 1+1=2 .. 2 is an even number, so it doesn't count. 2+2=4 .. 4 is an even number, it doesn't count.. continue on, adding each number to its reverse self. 12+21 ( reverse the numbers of 12 is 21) .. 12+21=33 .. 33 IS a reversible odd number because 33 doesn't contain any even numbers. after 12 you do 13. so 13+31=44. has even numbers, so it's no good. then 14... 14+41=55. 55 has no even numbers, so it is a reversible odd number.
continue on checking the result of each number checking it for sums containing ONLY odd numbers
0
looks like you got it! .. now, for everytime it finds one, add it to a count.. how many Reversible Odd Numbers are in a 10,000?
0
Hi, count added. Unfortunately, it doesn't run fast enough to get the numbers up to 10000, but if you remove the "print", you might get the number of occurrences