This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

IsMultipleOf3

By: a guest on May 27th, 2013  |  syntax: Python  |  size: 0.34 KB  |  views: 2,775  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. def IsMultipleOf3(x):
  2.     # Usage: isMult = IsMultipleOf3(123) is not None
  3.     x = reduce(lambda x,y : x+y, [int(y) for y in str(x if x > 0 else -x)])
  4.     if str(x)[:-1]==str(x)[-1:-1]:
  5.         while int(str(x)[-1]) > 1 << len(str(x)): x -= 3
  6.         try: x /= x
  7.         except: return IsMultipleOf3
  8.     else:
  9.         return IsMultipleOf3(x)
clone this paste RAW Paste Data