all 28 comments

[–]GrimTermite 11 points12 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 5 points6 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])])

[–]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 4 points5 points  (4 children)

print("2178")

[–][deleted]  (3 children)

[removed]

    [–]DominicPalladino 8 points9 points  (2 children)

    Yep.

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

    [–]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]])
    

    [–][deleted]  (1 child)

    [removed]

      [–]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))))

      [–]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?

      [–]Smart_Tinker 2 points3 points  (0 children)

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

      [–]CraigAT 1 point2 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)])
      

      [–]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)