HabKaffee

Untitled

Dec 5th, 2021 (edited)
316
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def fromDecToBase(a, base):
  2.     s = ''
  3.     a_copy = a
  4.     while(a_copy > 0):
  5.         s += str(a_copy % base)
  6.         a_copy //= base
  7.     s = s[::-1]
  8.     return s
  9.  
  10.  
  11. def fromBaseToDec(a, base):
  12.     result = 0
  13.     a_copy = a[::-1]
  14.     for i in range(len(a_copy)):
  15.         result += int(a_copy[i]) * (base**i)
  16.     return result
  17.  
  18.  
  19. base = 3
  20. for i in range(100000):
  21.     s = fromDecToBase(i, base)
  22.     s += str(i%base)
  23.     res = fromBaseToDec(s, base)
  24.     if (res >= 1000 and res < 10000):
  25.         print(res)
  26.         break
  27. # Without functions
  28. for i in range(100000):
  29.     s = ''
  30.     a_copy = i
  31.     while(a_copy > 0):
  32.         s += str(a_copy % 3)
  33.         a_copy //= 3
  34.     s = s[::-1]
  35.     s += str(i%3)
  36.     result = 0
  37.     s = s[::-1]
  38.     for j in range(len(s)):
  39.         result += int(s[j]) * (3**j)
  40.     if (result >= 1000 and result < 10000):
  41.         print(result)
  42.         break
  43.  
RAW Paste Data