# Don't give me five!

In this kata you get the start number and the end number of a region and should return the count of all numbers except numbers with a 5 in it. The start and the end number are both inclusive!

Examples:

```
1,9 -> 1,2,3,4,6,7,8,9 -> Result 8
4,17 -> 4,6,7,8,9,10,11,12,13,14,16,17 -> Result 12
```

The result may contain fives. ;-)
The start number will always be smaller than the end number. Both numbers can be also negative!

I'm very curious for your solutions and the way you solve it. Maybe someone of you will find an easy pure mathematics solution.

Have fun coding it and please don't forget to vote and rank this kata! :-) 

I have also created other katas. Take a look if you enjoyed this kata!

Source: codewars | Difficulty: EASY
Tags: Data structures

Mathematics

Starter code: def dont_give_me_five(start,end):
	

Solutions:
def dont_give_me_five(start, end):
	return sum(('5' not in str(i) for i in range(start, end + 1)))


def dont_give_me_five(start, end):
	return len([num for num in range(start, end + 1) if '5' not in str(num)])


def dont_give_me_five(start, end):
	tick = 0
	for x in range(start, end + 1):
		if '5' not in str(x):
			tick += 1
	return tick


def dont_give_me_five(start, end):

	def goo(n):
		result = 0
		pos9 = 1
		while n > 0:
			digit = n % 10
			effective_digit = digit
			if digit > 5:
				effective_digit -= 1
			to_add = effective_digit * pos9
			if digit == 5:
				result = -1
			result += to_add
			n //= 10
			pos9 *= 9
		return result
	if end >= 0 and start >= 0 or (end < 0 and start < 0):
		return goo(max(abs(end), abs(start))) - goo(min(abs(start), abs(end)) - 1)
	else:
		return goo(abs(end)) + goo(abs(start)) + 1


def dont_give_me_five(start, end):
	return len(tuple((n for n in range(start, end + 1) if '5' not in str(n))))


dont_give_me_five = lambda s, e: sum(('5' not in str(e) for e in range(s, e + 1)))


def dont_give_me_five(start, end):
	n = []
	i = start
	while i <= end:
		m = str(i)
		if '5' in m:
			i += 1
		if '5' not in m:
			n.append(m)
			i += 1
	x = len(n)
	return x


def dont_give_me_five(start, end):
	count = 0
	for i in range(start, end + 1):
		if '5' not in str(i):
			count += 1
	return count


def dont_give_me_five(start, end):
	return sum((1 for n in range(start, end + 1) if '5' not in str(n)))


def dont_give_me_five(start, end):
	n = 0
	for j in range(start, end + 1):
		i = abs(j)
		n += 1
		while i // 5 > 0:
			if i % 5 == 0 and i % 10 != 0:
				n -= 1
				break
			i = i // 10
	return n


def dont_give_me_five(start, end):
	n = end - start + 1
	for i in range(start, end + 1):
		if '5' in str(i):
			n -= 1
	return n


dont_give_me_five = lambda s, e: len([i for i in range(s, e + 1) if '5' not in str(i)])


def dont_give_me_five(start, end):
	return sum([(1, 0)['5' in str(x)] for x in range(start, end + 1)])


def dont_give_me_five(start, end):
	return len([i for i in list(map(str, range(start, end + 1))) if '5' not in i])


def dont_give_me_five(start, end):
	n_list = [i for i in range(start, end + 1)]
	n = 0
	for i in n_list:
		if '5' in str(i):
			continue
		n += 1
	return n


def dont_give_me_five(start, end):
	rez = []
	for i in list(range(start, end + 1)):
		if '5' in list(str(i)):
			print(i)
		else:
			rez.append(i)
	return len(rez)


def dont_give_me_five(start, end):
	return len(list(filter(lambda i: not '5' in str(i), range(start, end + 1))))


def dont_give_me_five(start, end):
	array = list(range(start, end + 1))
	out = [num for num in array if not '5' in str(num)]
	return len(out)


def dont_give_me_five(start, end):
	arr = []
	for x in range(start, end + 1):
		if '5' not in str(x):
			arr.append(x)
	return len(arr)


def dont_give_me_five(start, end):
	z = 0
	for i in range(start, end + 1):
		if str(i).find('5') == -1:
			z += 1
	return z


def dont_give_me_five(start, end):
	k = [str(i) for i in range(start, end + 1)]
	return len([i for i in k if '5' not in i])


def dont_give_me_five(start: int, end: int) -> int:
	count = 0
	for item in range(start, end + 1):
		if '5' not in str(item):
			count += 1
	return count


def dont_give_me_five(start, end):
	nums = [str(number) for number in range(start, end + 1) if '5' not in str(number)]
	return len(nums)


def dont_give_me_five(start, end):
	n = 0
	for x in range(start, end + 1):
		if '5' in str(x):
			continue
		n = n + 1
	return n


def dont_give_me_five(start, end):
	arr = []
	for i in range(start, end + 1):
		arr.append(i)
	count = 0
	for i in arr:
		if '5' in str(i):
			count += 1
	return len(arr) - count


def dont_give_me_five(start, end):
	position = start
	count = []
	while position <= end:
		if '5' in str(position):
			position += 1
		else:
			count.append(position)
			position += 1
	return len(count)


def dont_give_me_five(start, end):
	l = list(range(start, end + 1))
	new_l = []
	for i in l:
		if not '5' in str(i):
			new_l.append(i)
	return len(new_l)


def dont_give_me_five(start, end):
	count = 0
	for i in range(start, end + 1):
		valid = True
		for j in str(i):
			if j == '5':
				valid = False
		if valid:
			count += 1
	return count


def dont_give_me_five(start, end):
	answer = 0
	for i in range(start, end + 1):
		if '5' in str(i):
			pass
		else:
			answer += 1
	return answer


def dont_give_me_five(start, end):

	def has_five(n):
		x = False
		for i in str(n):
			if i == '5':
				x = True
		return x
	y = 0
	for i in range(start, end + 1):
		if not has_five(i):
			y = y + 1
	return y


def dont_give_me_five(start, end):
	array = list(range(start, end + 1))
	array_str = [str(num) for num in array]
	array_with_5 = [num for num in array_str if '5' in num]
	count_withno5 = len(array_str) - len(array_with_5)
	return count_withno5


def dont_give_me_five(start, end):
	return len([n for n in range(start, end + 1) if not (n % 5 == 0) & (n % 2 != 0) | (n in range(50, 60)) | (n in range(150, 160))])


def dont_give_me_five(start, end):
	print(start, end)
	l = []
	for x in range(start, end + 1):
		if str(5) not in str(x):
			l.append(x)
	return len(l)


def dont_give_me_five(start, end):
	countnotfive = 0
	for scanner in range(start, end + 1):
		if '5' not in str(scanner):
			countnotfive += 1
	return countnotfive
print(dont_give_me_five(52, 106))


def dont_give_me_five(start, end):
	startlist = list(range(start, end + 1))
	newlist = []
	for item in startlist:
		if '5' not in str(item):
			newlist.append(item)
	return len(newlist)


def dont_give_me_five(start, end):
	count = 0
	for i in range(start, end + 1):
		if str(i).__contains__('5'):
			continue
		else:
			count += 1
	return count


def dont_give_me_five(start, end):
	n = []
	for i in range(start, end + 1):
		if i % 5 != 0 or i % 10 == 0:
			if not 50 <= i <= 59:
				if not 150 <= i <= 159:
					n.append(i)
	return len(n)


def dont_give_me_five(start: int, end: int):
	list_of_numbers = range(start, end + 1)
	range_without_fives = []
	for number in list_of_numbers:
		digits_list = list(str(number))
		if '5' not in digits_list:
			range_without_fives.append(int(''.join((str(digit) for digit in digits_list))))
	return len(range_without_fives)


def dont_give_me_five(start, end):
	numbers = list(range(start, end + 1))
	n = 0
	for i in numbers:
		s = str(i)
		if '5' not in s:
			n += 1
	return n


def dont_give_me_five(start, end):
	counts = 0
	for num in range(start, end + 1):
		if '5' not in str(num):
			counts = counts + 1
		else:
			continue
	return counts


def dont_give_me_five(start, end):
	rc = 0
	for ing in range(start, end + 1):
		if '5' in list(str(ing)):
			pass
		else:
			rc += 1
	return rc


def dont_give_me_five(start, end):
	arr = list(range(start, end + 1))
	filter = []
	for el in arr:
		if str(el).find('5') == -1:
			filter.append(el)
	print(filter)
	return len(filter)


def dont_give_me_five(start, end):
	c = list(range(start, end + 1))
	v = []
	for t in c:
		if '5' not in str(t):
			v.append(t)
	n = len(v)
	return n


def dont_give_me_five(start, end):
	return sum([1 for i in range(min(start, end), max(start, end) + 1) if testFive(i)])

def testFive(num):
	if num < 0:
		num = abs(num)
	while num > 0:
		if num % 10 == 5:
			return False
		num //= 10
	return True


def dont_give_me_five(start, end):
	count = 0
	numbers = [str(x) for x in range(start, end + 1)]
	for number in numbers:
		if '5' not in number:
			count += 1
	return count


def dont_give_me_five(start, end):
	x = start
	total = 0
	while x < end + 1:
		if '5' not in str(x):
			total += 1
		x += 1
	return total


def dont_give_me_five(start, end):
	res = 0
	for n in range(start, end + 1):
		if not '5' in str(n):
			res += 1
	return res


def dont_give_me_five(start, end):
	n = [i for i in range(start, end + 1) if str(i).count('5') == 0]
	return len(n)


def dont_give_me_five(s, e):
	return len([x for x in range(s, e + 1) if not str(x).count('5')])


def dont_give_me_five(s, e):
	return len([i for i in range(s, 1 + e) if '5' not in str(i)])


def dont_give_me_five(start, end):
	s = [str(x) for x in range(start, end + 1)]
	d = '-'.join(s).replace('5', '!')
	f = d.split('-')
	result = []
	for x in f:
		if x.isdigit() == True:
			result.append(x)
	return len(result)


def dont_give_me_five(start, end):
	end = end + 1
	nofives = 0
	for i in range(start, end):
		if '5' not in str(i):
			nofives += 1
		else:
			pass
	return nofives


import re

def dont_give_me_five(start, end):
	n = 0
	for i in range(start, end + 1):
		if re.match('(.*)[5](.*)', str(i)):
			continue
		n += 1
	return n


def dont_give_me_five(start, end):
	if start < 0 and end < 0:
		return nums_without_five(-start + 1) - nums_without_five(-end)
	elif start < 0 and end >= 0:
		return nums_without_five(-start + 1) + nums_without_five(end + 1) - 1
	return nums_without_five(end + 1) - nums_without_five(start)

def nums_without_five(n):
	cnt = 0
	fct = 1
	while n:
		dig = n % 10
		if dig == 5:
			cnt = 0
		cnt += (dig - (dig > 5)) * fct
		fct *= 9
		n //= 10
	return cnt


def dont_give_me_five(start, end):
	num = list(range(start, end + 1))
	count = 0
	for i in num:
		if '5' in str(i):
			pass
		else:
			count += 1
	return count


def dont_give_me_five(start, end):
	return sum([1 if '5' not in str(i) else 0 for i in [loop for loop in range(start, end + 1)]])


def dont_give_me_five(start, end):
	c = 0
	for i in range(start, end + 1):
		d = [int(x) for x in str(abs(i))]
		if not 5 in d:
			c += 1
	return c


def dont_give_me_five(start, end):
	l = end + 1 - start - sum([1 for i in range(start, end + 1) if '5' in str(i)])
	return l


def dont_give_me_five(start, end):
	arr = []
	ran = []
	for i in range(start, end + 1):
		ran.append(i)
	for i in ran:
		s = str(i)
		if '5' in s:
			continue
		else:
			arr.append(s)
	n = len(arr)
	return n


def dont_give_me_five(start, end):
	count = 0
	while start <= end:
		if str(start).find('5') == -1:
			count += 1
		start += 1
	return count


def dont_give_me_five(start, end):
	count = 0
	for number in range(start, end + 1):
		number_as_str = str(number)
		if '5' not in number_as_str:
			count += 1
	return count


def dont_give_me_five(start, end):
	return len([t for t in range(start, end + 1) if str(t).find('5') == -1])


def dont_give_me_five(start, end):
	numbers = []
	for i in range(start, end + 1):
		if '5' in str(i):
			continue
		else:
			numbers.append(i)
	return len(numbers)


def dont_give_me_five(x, y):
	return len([i for i in range(x, y + 1) if '5' not in str(i)])


def dont_give_me_five(start, end):
	n = 0
	five = '5'
	for i in range(start, end + 1):
		i = str(i)
		if five in i:
			continue
		else:
			n += 1
	return n


def dont_give_me_five(start, end):
	itr = 0
	while start <= end:
		strNum = str(start)
		if '5' not in strNum:
			itr += 1
		start += 1
	return itr


def dont_give_me_five(s, e):
	cnt = 0
	for i in range(s, e + 1):
		if '5' not in str(i):
			cnt += 1
	return cnt


def dont_give_me_five(start, end):
	l = []
	for i in range(start, end + 1):
		if '5' not in str(i):
			l.append(i)
	for j in l:
		if '5' in str(j):
			l.remove(j)
	print(l)
	return len(l)


def dont_give_me_five(start, end):
	no_fives = [str(x) for x in range(start, end + 1) if '5' not in str(x)]
	return len(no_fives)