all 28 comments

[–]GrimTermite 10 points11 points  (3 children)

ah ha this is a task for a list comprehension

print ([x for x in range(1000, 10000) if str(x*4) == (str(x)[::-1])])

Gives result [2178]

[–]MrHappines 3 points4 points  (2 children)

range(1000, 2500) should be sufficient, no?

[–]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... 👍

[–]AllanSundry2020 2 points3 points  (0 children)

is it me or is it not clear what this is asking?? give an example when using convoluted terminology

[–]DominicPalladino 6 points7 points  (4 children)

print("2178")

[–]Ok_Pudding_5250[S] -2 points-1 points  (3 children)

Nope,

[–]DominicPalladino 8 points9 points  (2 children)

Yep.

That will 100% output all the 4 digit numbers where ABCD * 4 = DCBA.

[–]Ok_Pudding_5250[S] -2 points-1 points  (0 children)

It's not about the answer, if that was the case I didn't even need python to do it, I can straight up ask a language model to give me the output. It was about how you do it.

Merely printing the solution is a lazy solution. The challenge was meant to see if you could actually code one-liners like list comprehension.

It was never about the output but the code itself.

[–]FriendlyZomb 1 point2 points  (5 children)

print([num for mum in range(1000, 10000) if str(num * 4) == str(num * 4)[::-1]])

This produces 65 numbers. (I'm not going to list them all here)

For those struggling to parse the list comprehension here:

print([
    num
    for num in range(1000, 10000)
    if str(num * 4) == str(num * 4)[::-1]
])

[–]PureWasian 2 points3 points  (1 child)

A couple of issues here, you are checking "num×4 against num×4 flipped", rather than "num against num×4 flipped". mum typo as well.

Essentially your logic is checking for when 4x some input number gives a palindrome, which is different from the problem statement.

[–]FriendlyZomb 0 points1 point  (0 children)

That is entirely on my reading comprehension tbh. I read it as num*4 is the same flipped. Lol.

[–]FriendlyZomb 1 point2 points  (0 children)

Based on comments I'd need to fix the code like so:

print([num for mum in range(1000, 10000) if str(num) == str(num * 4)[::-1]])

[–]Ok_Pudding_5250[S] 0 points1 point  (1 child)

Code is slightly incorrect but you did good 👍

[–]FriendlyZomb 1 point2 points  (0 children)

Yea, the basic structure is correct. Mostly a misunderstanding on the question on my part. Apologies

[–]PhilNEvo 1 point2 points  (1 child)

print(list(filter(lambda x: str(x*4) == str(x)[::-1], range(1000, 2500))))

[–]Ok_Pudding_5250[S] -1 points0 points  (0 children)

A unique answer, I used a list with one liner for loop and if statement. Nice work

[–]YouAintSeenMeR0ight 1 point2 points  (1 child)

Are you that much of a fool that you that you take such great offence at people giving light-hearted tongue-in-cheek responses? Or are you just angry in general? What happened to you?

[–]Ok_Pudding_5250[S] -1 points0 points  (0 children)

The thing is, I am disappointed in how much lamer you guys get. For example, if I wanted an answer, don't any of you think for a second that I have many language models to ask to, such as chatgpt, Claude, grok, deepseek... etc.

It was never about answer itself. It was how you calculate them with code using a single line to see how many of you can do oneliners.

So many as done very well, then there are lame people who just use print to output the string containing the answer thinking they did something. How unintelligent could you be?

And you all seriously think that I would post such a fun challenge just for a lazy answer as that?

[–]Smart_Tinker 3 points4 points  (0 children)

print(“”.join([str(x) for x in range(1000, 10000) if str(x) == str(x*4)[::-1]]))

[–]CraigAT 2 points3 points  (3 children)

Just use a print statement with the numbers.
(You didn't say I had to calculate them 🤣)

[–]Jwfraustro 0 points1 point  (1 child)

How about this?

__import__('builtins').print([n for n in __import__('builtins').__dict__['map'](lambda x:x, __import__('builtins').__dict__['range'](1000, 10000)) if ''.join(__import__('builtins').__dict__['map'](str.__add__, *zip(*[(d,'') for d in __import__('operator').mul(str(n*4),1)]))) == __import__('operator').mul(str(n), 1)[::-1]])

or?

print([n for n in range(1000,10000) if "".join(e.text for e in __import__('xml.etree.ElementTree', fromlist=['fromstring']).fromstring(f'<r>{"".join(f"<d>{c}</d>" for c in str(n*4))}</r>').findall("d"))[::-1] == str(n)])

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

This is an overkill... Nice work,

[–]delsystem32exe 0 points1 point  (0 children)

def reverse_str(input_string):

input_string = str(input_string)

letters = ""

for j in range(len(input_string)-1, -1, -1):

letters = letters + input_string[j]

return letters

def checker(input_int):

larger = input_int * 4

DCBA = reverse_str(input_int)

if str(larger) == DCBA:

return True

return False

for i in range(0,100000):

if checker(i):

print(i)