Created
February 24, 2014 07:20
-
-
Save ifnull/9183309 to your computer and use it in GitHub Desktop.
Math: Check divisibility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import math, time | |
# 01. All whole numbers are multiples of 1 | |
# 02. The last digit is 2, 4, 6, 8, 0 | |
# 03. The digits add up to a multiple of 3 | |
# 04. The last 2 digits are a multiple of 4 | |
# 05. Last digit is either 5 or 0 | |
# 06. Divisible by 2 and 3 | |
# 07. It is a bit bizarre. Use google. You may get confused | |
# 08. Last 3 digits are divisible by 8 | |
# 09. The digits add up to a multiple of 9 | |
# 10. So obvious - ends in 0 | |
_num = 2520 | |
_pieces = [int(i) for i in str(_num)] | |
def d2(): | |
global _pieces, num | |
return _pieces[-1] in [0, 2, 4, 6, 8] | |
def d3(): | |
if sum( _pieces ) % 3 == 0: | |
return True | |
else: | |
return False | |
def d4(): | |
if int( ''.join( [str(i) for i in _pieces[-2:]] ) ) % 4 == 0: | |
return True | |
else: | |
return False | |
def d5(): | |
return _pieces[-1] in [0, 5] | |
def d6(): | |
if d2() and d3(): | |
return True | |
else: | |
return False | |
def d7(): | |
s1 = int( ''.join( str(i) for i in _pieces[:-1] ) ) | |
s2 = _pieces[-1] * 2 | |
s3 = s1 - s2 | |
s4 = [int(i) for i in str(s3)] | |
s5 = int( ''.join( str(i) for i in s4[:-1] ) ) | |
s6 = s4[-1] * 2 | |
if ( s5 - s6 ) % 7 == 0: | |
return True | |
else: | |
return False | |
def d8(): | |
if int( ''.join( str(i) for i in _pieces[-3:] ) ) % 8 == 0: | |
return True | |
else: | |
return False | |
def d9(): | |
if sum( _pieces ) % 9 == 0: | |
return True | |
else: | |
return False | |
def d10(): | |
if _pieces[-1:][0] == 0: | |
return True | |
else: | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment