Example #1
0
 async def addcan(self, ctx):
     self.can += 1
     self.changed = True
     modifiers = ""
     factorization = list(factorize(self.can))
     if len(factorization) > 1:
         greatest_common_exponent = reduce(gcd,
                                           [n for _, n in factorization])
     else:
         greatest_common_exponent = 1
     if greatest_common_exponent % 2 == 0:
         modifiers += " These cans make a square."
     if greatest_common_exponent % 3 == 0:
         modifiers += " These cans make a cube!"
     if is_square(8 * self.can + 1):
         if floor(sqrt(8 * self.can + 1)) % 4 == 3:
             modifiers += " These cans make a triangle and a hexagon!!"
         else:
             modifiers += " These cans make a triangle!"
     if greatest_common_exponent > 3:
         modifiers += f" These cans are a {greatest_common_exponent}th power, hope you know how to stack cans in {greatest_common_exponent}D."
     if len(factorization) == 1:
         if factorization[0][1] == 1:
             modifiers += " These cans are a prime number!!!"
         else:
             modifiers += " These cans are a power of a prime number!!!"
     if self.can % 100 == 69:
         modifiers += " nice."
     if self.can % 1000 == 413:
         modifiers += " Lets me tell you about homestuck."
     await ctx.send(
         f"You added a can, there are now {self.can} cans.{modifiers}")
Example #2
0
import itertools
import util

def prod(nn):
  r = 1
  for n in nn:
    r *= n
  return r

def select_some(aa):
  for i in range(len(aa)):
    for sub_aa in itertools.combinations(aa, i):
      yield sub_aa

ii = []
for i in range(2, 30000):
  if i % 1000 == 0:
    print i
  nn = util.factorize(i)
  for selected_nn in select_some(nn):
    a = prod(selected_nn)
    b = i / a
    s = ''.join(sorted(str(a) + str(b) + str(i)))
    if s == '123456789':
      print '%d * %d = %d' % (a, b, i)
      ii.append(i)
      break
print sum(ii)
Example #3
0
def num_distinct_prime_factors(n):
    nn = util.factorize(n)
    return len(set(nn))
Example #4
0
def is_abundant(n):
    return sum(factorize(n)) > n
Example #5
0
 def getObjectsFromNumber(self, n):
     indices = factorize(self, n)
     allItems = ['avatar'] + sorted(self._obstypes.keys())[::-1]
     return [allItems[i] for i in indices]