The Mormons are trying to find new followers and in order to do that they embark on missions.

Each time they go on a mission, every Mormons converts a fixed number of people (reach) into followers. This continues and every freshly converted Mormon as well as every original Mormon go on another mission and convert the same fixed number of people each. The process continues until they reach a predefined target number of followers (input into the model).

Converted Mormons are unique so that there's no duplication amongst them.

Create a function Mormons(startingNumber, reach, target) that calculates how many missions Mormons need to embark on, in order to reach their target. While each correct solution will pass, for more fun try to make a recursive function.

All model inputs are valid positive integers.

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Mathematics

Complete search

Starter code: def mormons(starting_number, reach, target):
	

Solutions:
def mormons(starting_number, reach, target):
	missions = 0
	while starting_number < target:
		starting_number += starting_number * reach
		missions += 1
	return missions


def mormons(start, fac, target):
	return 0 if start >= target else 1 + mormons(start * (fac + 1), fac, target)


from math import log, ceil

def mormons(starting_number, reach, target):
	return ceil(log(target / starting_number) / log(1 + reach))


def mormons(starting_number, reach, target):
	return 0 if starting_number >= target else 1 + mormons(starting_number * (1 + reach), reach, target)


from math import ceil, log

def mormons(n, r, target):
	return ceil(log(target / n, r + 1))


def mormons(followers, reach, target):
	mission = 0
	while followers < target:
		followers *= reach + 1
		mission += 1
	return mission


mormons = lambda a, r, t, m=0: m if a >= t else mormons(a * (r + 1), r, t, m + 1)


def mormons(n, r, target):
	c = 0
	while n < target:
		n *= r + 1
		c += 1
	return c


def mormons(number, reach, target):
	c = 0
	while number < target:
		number += reach * number
		c += 1
	return c