A trick I learned in elementary school to determine whether or not a number was divisible by three is to add all of the integers in the number together and to divide the resulting sum by three. If there is no remainder from dividing the sum by three, then the original number is divisible by three as well.

Given a series of numbers as a string, determine if the number represented by the string is divisible by three.

You can expect all test case arguments to be strings representing values greater than 0. 

Example:

```
"123"      -> true
"8409"     -> true
"100853"   -> false
"33333333" -> true
"7"        -> false
```

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Data structures

Starter code: def divisible_by_three(st):
	

Solutions:
def divisible_by_three(s):
	return int(s) % 3 == 0


def divisible_by_three(st):
	return sum([int(i) for i in st]) % 3 == 0


def divisible_by_three(st):
	return sum([int(c) for c in st]) % 3 == 0


import re

def divisible_by_three(st):
	return re.match('(((((0|3)|6)|9)|((2|5)|8)((((0|3)|6)|9))*((1|4)|7))|(((1|4)|7)|((2|5)|8)((((0|3)|6)|9))*((2|5)|8))(((((0|3)|6)|9)|((1|4)|7)((((0|3)|6)|9))*((2|5)|8)))*(((2|5)|8)|((1|4)|7)((((0|3)|6)|9))*((1|4)|7)))+$', st) != None


def divisible_by_three(s):
	return not int(s) % 3


def divisible_by_three(st):
	while len(st) > 1:
		st = str(sum(map(int, st)))
	return st in '369'


def divisible_by_three(st):
	num_str = str(st)
	sum = 0
	for i in range(0, len(num_str)):
		sum += int(num_str[i])
	if sum % 3 == 0:
		return True
	else:
		return False
	pass


def divisible_by_three(st):
	sum = 0
	while int(st) > 0:
		digit = int(st) % 10
		sum = sum + digit
		st = int(st) // 10
	if sum % 3 == 0:
		return True
	else:
		return False


def divisible_by_three(string):
	return not sum((int(n) for n in string)) % 3


def divisible_by_three(stg):
	return sum((int(d) for d in stg)) % 3 == 0