Skip to content

Files

Latest commit

author
juanantonioledesma
Aug 22, 2023
f6b5494 · Aug 22, 2023

History

History
31 lines (21 loc) · 1 KB

handshake-problem.md

File metadata and controls

31 lines (21 loc) · 1 KB

Handshake problem 6 Kyu

LINK TO THE KATA - ALGORITHMS

Description

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).

Solution

const getParticipants = handshakes => {
  let participants = 0

  while (handshakes > (participants * (participants - 1)) / 2) {
    participants++
  }

  return participants
}