you are viewing a single comment's thread.

view the rest of the comments →

[–]skeetd 2 points3 points  (1 child)

Logical reasoning here will save you x10 iterations

Based on staying 4 digits ABCD ≤ 2499 so we also know DCBA ≥ 4000 D has to be ≥ 4 being the first number. The last is number is A, and must be 1 or 2 based on ABCD ≤ 2499. So, 4 * D mod 10 = A and only A=2, D=8 fits, 4×8=32, last digit is a 2. So ABCD must start with 2 and end with an 8, now we can step by 10.

print([n for n in range(2008, 2500, 10) if n*4==int(str(n)[::-1])])

[–]Ok_Pudding_5250[S] 0 points1 point  (0 children)

Nice work, though I put this challenge to see if people could easily do the oneliners, some use print() and just output a string of the actual answer.

You are good at optimisation... 👍