addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupsimageimagesinstagramlinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1outlookpersonJoin Group on CardStartprice-ribbonImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruseryahoo

Algorithms Meetup Problem #4

From: Andy P.
Sent on: Saturday, July 31, 2010 11:52 AM

I would like to express my gratitude and thanks to YangXikun,
Deepankar, MichaelMellinger, SamSandberg, fjania, and dawgmatix for
solving and uploading code to our Github repository. We have solutions
in Java, Python, PHP, Lisp, and pseudo code. Great job! We need C,
C++, Scala, Ruby, Ocaml, and Haskell.

Please, follow AlgorithmsNYC on Twitter
(­), so we can follow each other and
expand community.

I would like to encourage everyone to start using our Meetup's email
list and forums to share problems and ask questions.

Here is our next "Problem of the week". Please, upload your solutions
to our Github repository­



Problem Statement

You may remember an old computer game called "The Incredible Machine".
It was a game where you could simulate simple processes like balls
falling, lasers shooting, or cats pursuing mice. Moreover, you were
able to perform these observations with different values for
gravitational acceleration.

Imagine a system with some unknown acceleration of gravity. There are
N balls, each fixed initially at some height above the ground. You are
given a int[] height, where the i-th element is the height of the i-th
ball above the ground. At time 0, the first ball is set loose and it
starts falling. When it reaches the ground, the second ball is
instantly set loose, and so on. This continues until the last ball
reaches the ground at time T.

Return the acceleration of gravity in this system. Neglect air
resistance and any other resisting factors. The distance d travelled
by an object falling for time t with no initial velocity in a system
with gravitational acceleration g and no resisting factors is equal to
d = 0.5 * g * t^2.

Class:	IncredibleMachineEas­y
Method:	gravitationalAcceler­ation
Parameters:	int[], int
Returns:	double
Method signature:	double gravitationalAcceler­ation(int[] height, int T)
(be sure your method is public)

-	The returned value must have an absolute or relative error less than 1e-9.

-	height will contain between 1 and 50 elements, inclusive.
-	Each element of height will be between 1 and 100, inclusive.
-	T will be between 1 and 100, inclusive.






That's an acceleration of gravity that might be somewhere on Earth's surface.





And this is likely on Jupiter.





That's a light one.





You could nearly fly under such conditions.

Our Sponsors

  • Pivotal Labs

    Pivotal Labs

  • Vendavo

    Vendavo is the leader in front-line profit optimization

  • Wolfram Research

    Mathematica is the world's ultimate application for computations.

  • Yodle

    Local online advertising for small businesses.

  • Lyft

    Free ride credit to try the service. Fast and safe way to get around.

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy