Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def fromDecToBase(a, base):
- s = ''
- a_copy = a
- while(a_copy > 0):
- s += str(a_copy % base)
- a_copy //= base
- s = s[::-1]
- return s
- def fromBaseToDec(a, base):
- result = 0
- a_copy = a[::-1]
- for i in range(len(a_copy)):
- result += int(a_copy[i]) * (base**i)
- return result
- base = 3
- for i in range(100000):
- s = fromDecToBase(i, base)
- s += str(i%base)
- res = fromBaseToDec(s, base)
- if (res >= 1000 and res < 10000):
- print(res)
- break
- # Without functions
- for i in range(100000):
- s = ''
- a_copy = i
- while(a_copy > 0):
- s += str(a_copy % 3)
- a_copy //= 3
- s = s[::-1]
- s += str(i%3)
- result = 0
- s = s[::-1]
- for j in range(len(s)):
- result += int(s[j]) * (3**j)
- if (result >= 1000 and result < 10000):
- print(result)
- break
Add Comment
Please, Sign In to add comment