I found this interesting interview question just today:

> *8 coins are given where all the coins have equal weight, except one. The odd one weights less than the others, not being of pure gold. In the worst case, how many iterations are actually needed to find the odd one out on a two plates scale*.

I am asking you then to tell me what is the *minimum* amount of weighings it will take to measure `n` coins in every possible occurrence (including worst case scenario, ie: without relying on luck at all).

`n` is guaranteed to be a positive integer.

***Tip:*** being able to think *recursively* might help here :p

***Note:*** albeit this is more clearly a logical than a coding problem, do not underestimate (or under-rank) the kata for requiring not necessarily wizard-class coding skills: a good coder is a master of pattern recognition and subsequent optimization ;)

Difficulty: introductory

Starter code:

def how_many_measurements(n):
	

Solutions:
from math import ceil, log

def how_many_measurements(n):
    return ceil(log(n, 3))

def how_many_measurements(n):
  if n>1: 
      return 1 + how_many_measurements(n/3) 
  return 0

import math

def how_many_measurements(n):
    return math.ceil(math.log(n, 3))

from math import log, ceil

def how_many_measurements(n):
    return ceil(log(n, 3))


def how_many_measurements(n):
    # Split coins in three equal sized groups,
    # one measurement will tell which of the groups contains
    # the fake coin, when less than 3 coins is in a group, one
    # measurement is required to determine which coin is fake
    if n == 1:
        return 0
    elif n <= 3:
        return 1 
    n_coins_in_sub_group = n / 3
    return how_many_measurements(n_coins_in_sub_group) + 1

def how_many_measurements(n):
    x = 0
    while n > 1:    
        if n % 2 == 0:
            n = n / 3
            first = round(n)
            if n > first:
                n = first + 1
            x += 1
        else:
            n = n / 3
            x += 1
    return x

import math

def how_many_measurements(n):
    count = 0
    while n > 1:
        n = math.ceil(n/3)
        count += 1
    return count

def how_many_measurements(n):
    exp = 0
    while 3**exp < n:
        exp += 1
    return exp

def how_many_measurements(n):
  if n>1:
      return 1 + how_many_measurements( n//3 + int(0.5 + (n%3)/2) ) 
  return 0

def how_many_measurements(n, c=0): return how_many_measurements(n-2*n//3, c+1) if n > 1 else c