Skip to content

Latest commit

 

History

History
59 lines (47 loc) · 3.88 KB

shakespearean_tug_of_war.md

File metadata and controls

59 lines (47 loc) · 3.88 KB
“Do you bite your thumb at us, sir?”

Romeo and Juliet Act I: Sc. 1

Prince Escalus and the citizens of Verona have become weary of the ongoing blood-feud between the Montagues and the Capulets. Escalus has decided to settle the feud once and for all with a game of tug of war between the two houses, resulting in the losing family leaving the city.

Objective

This version of tug of war will begin with one member from each house on opposite sides of the center line. Gradually over time, additional members from each house will join their respective side until a winner has been declared or there are no more additional participants.
A house wins if the opposing house touches the center point.

Your goal is to write a function that returns the winner between the two houses and the elapsed time when victory is declared.

Input

The function will accept two arguments:
  • An integer distance n between the two closest members of opposite families (see test example below)
  • An array/list of subarrays. Each subarray will contain three integer values:
    • The pulling force of the participant from House Capulet
    • The pulling force of the participant from House Montague
    • The number of seconds since the last participants had joined the tug of war

Inputs will always be valid.

Output

An array with two elements:
  • The winning house: either Montague or Capulet (string)
  • The elapsed time in seconds (integer)

If the tug of war results in a deadlock, return null or None.

Rope Movement
When the aggregate pulling force on one side is equal to that of the other, there is no rope movement. If this is the state after all house members have joined the tug of war, the result is a deadlock.

If one side has a greater aggregate pulling force, the rope moves at a rate of n * decimeters/second where n is the difference in total pulling force between the Capulets and Montagues currently engaaged in the tug of war.

Test Example

status at 0 seconds
status at 8 seconds

The first image above represents the status at 0 seconds (members[0]).
The image below it represents the status at 8 seconds (members[1]).

  • In the above images, the solid green triangle marks the center point.
  • At 0 seconds, a member from each side joins.
    8 seconds later, the line will have moved 2.4 meters to the left. Another member from each house joins behind their respective preceding member.
let members = [[35,32,0],[38,46,8],[27,24,12],[30,28,22],[39,36,31],[32,40,12],[28,18,6],[47,50,16]];

tugOfWar(20,members); //['Capulet', 154]
members = [[35,32,0],[38,46,8],[27,24,12],[30,28,22],[39,36,31],[32,40,12],[28,18,6],[47,50,16]]

tug_of_war(20,members) #['Capulet', 154]

If you enjoyed this kata, be sure to check out my other katas.