help solving a puzzle

This is the place for queries that don't fit in any of the other categories.

help solving a puzzle

Postby weee » Wed Dec 25, 2013 7:56 am

ABCD * 9 = DCBA
whats ABCD

here's the ugly code
Code: Select all
x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
y = [1, 2, 3, 4, 5, 6, 7, 8, 9]

for a in y:
   for b in x:
      for c in x:
         for d in x:
            if (a*1000 + b*100 + c*10 + d)*9 == (d*1000 + c*100 + b*10 +a):
               print (a, b, c, d)


can anyone code in a much more decent version?
Last edited by metulburr on Wed Dec 25, 2013 11:34 am, edited 2 times in total.
Reason: locked post, added code tags
weee
 
Posts: 1
Joined: Wed Dec 25, 2013 7:53 am

Re: help solving a puzzle

Postby metulburr » Wed Dec 25, 2013 11:34 am

read this first
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1315
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: help solving a puzzle

Postby stranac » Wed Dec 25, 2013 3:26 pm

You can try rewriting those loops using itertools.product().
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1093
Joined: Thu Feb 07, 2013 3:42 pm


Return to General Coding Help

Who is online

Users browsing this forum: kiranv5 and 2 guests