Johnny is a farmer and he annually holds a beet farmers convention "Drop the beet".

Every year he takes photos of farmers handshaking. Johnny knows that no two farmers handshake more than once. He also knows that some of the possible handshake combinations may not happen.

However, Johnny would like to know the minimal amount of people that participated this year just by counting all the handshakes.

Help Johnny by writing a function, that takes the amount of handshakes and returns the minimal amount of people needed to perform these handshakes (a pair of farmers handshake only once).

Difficulty: introductory

Starter code:

def get_participants(h):
	

Solutions:
from math import ceil

def get_participants(h):
    return int(ceil(0.5 + (0.25 + 2 * h) ** 0.5))


def get_participants(handshakes, n = 1):
    return get_participants(handshakes, n + 1) if (n * n - n)/2 < handshakes else n

def get_participants(handshakes):
    from math import ceil
    
    """
        Person #1 can shake hands with (n-1) people, person #2
        can shake hands with (n-2) people... etc. Therefore,
        n people can at most shake hands h = n*(n-1)/2 different times.
        
        If we flip this equation we get the amount
        of people necessary:
        n = 1/2 +(-) sqrt((8*h + 1)/4)
        
        The number of handshakes given might be smaller than
        the max amount possible for n people, so we need to round up.
    """
    
    return ceil(0.5 + ((8*handshakes + 1)/4)**0.5)

def get_participants(handshakes):
    return int(1.5 + (2 * handshakes)**0.5)

def get_participants(h):
    n = 0
    counter = 0
    while h > 0:
        h -= counter
        n += 1
        counter += 1
    return n or 1

from bisect import bisect_left

ns = [n*(n+1)//2 for n in range(1000)]

def get_participants(handshakes):
    return bisect_left(ns, handshakes) + 1

def get_participants(h):
  from math import ceil, sqrt
  return ceil(.5 + sqrt(.25 + 2*h))

import math
def get_participants(h):
    return math.ceil((1+math.sqrt(1+8*h))/2)

def get_participants(handshakes):
    farmers = 1
    maxshakes = 0
    while maxshakes < handshakes:
        maxshakes += farmers
        farmers += 1
    return farmers

from math import ceil 

def get_participants(hs):
    return ceil((1+(1+8*(hs))**.5)/2)