<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bouncing Ball Archives - Onestring Lab</title>
	<atom:link href="https://onestringlab.com/tag/bouncing-ball/feed/" rel="self" type="application/rss+xml" />
	<link>https://onestringlab.com/tag/bouncing-ball/</link>
	<description>Kode Kreativitas Kopi</description>
	<lastBuildDate>Mon, 04 May 2026 08:37:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://onestringlab.com/wp-content/uploads/2021/10/cropped-osl-high-res-e1455499003866-32x32.jpg</url>
	<title>Bouncing Ball Archives - Onestring Lab</title>
	<link>https://onestringlab.com/tag/bouncing-ball/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Belajar Bahasa C &#8211; Bouncing Balls</title>
		<link>https://onestringlab.com/bouncing-balls/</link>
		
		<dc:creator><![CDATA[Rajo Intan]]></dc:creator>
		<pubDate>Wed, 07 Dec 2022 02:06:00 +0000</pubDate>
				<category><![CDATA[Codewars]]></category>
		<category><![CDATA[Bouncing Ball]]></category>
		<category><![CDATA[C Language]]></category>
		<guid isPermaLink="false">https://onestringlab.com/?p=847</guid>

					<description><![CDATA[<p>A child is playing with a ball on the nth floor of a tall building. The height of this floor above ground level, h, is &#8230; </p>
<p>The post <a href="https://onestringlab.com/bouncing-balls/">Belajar Bahasa C &#8211; Bouncing Balls</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>A child is playing with a ball on the nth floor of a tall building. The height of this floor above ground level, h, is known.</p>



<p>He drops the ball out of the window. The ball bounces (for example), to two-thirds of its height (a bounce of 0.66).</p>



<p>His mother looks out of a window 1.5 meters from the ground.</p>



<p>How many times will the mother see the ball pass in front of her window (including when it&#8217;s falling and bouncing?</p>



<p>The problem link is <a href="https://www.codewars.com/kata/5544c7a5cb454edb3c000047/train/c" target="_blank" rel="noreferrer noopener">here</a>.</p>



<h2 class="wp-block-heading">Three conditions must be met for a valid experiment:</h2>



<ul class="wp-block-list">
<li>Float parameter &#8220;h&#8221; in meters must be greater than 0</li>



<li>Float parameter &#8220;bounce&#8221; must be greater than 0 and less than 1</li>



<li>Float parameter &#8220;window&#8221; must be less than h.</li>
</ul>



<p>If all three conditions above are fulfilled, return a positive integer, otherwise return -1.</p>



<p><strong>Note</strong>:<br>The ball can only be seen if the height of the rebounding ball is strictly greater than the window parameter.</p>



<h2 class="wp-block-heading">Examples<strong>:</strong></h2>



<pre class="wp-block-code"><code class="">- h = 3, bounce = 0.66, window = 1.5, result is 3

- h = 3, bounce = 1, window = 1.5, result is -1 

(Condition 2) not fulfilled).</code></pre>



<h2 class="wp-block-heading">Sample Test:</h2>



<pre class="wp-block-code"><code lang="csharp" class="language-csharp line-numbers">#include &lt;criterion/criterion.h&gt;

extern int bouncingBall (double h, double bounce, double window);
static void testequal(double h, double bounce, double window, int expected);

Test(bouncingBall, sampleTests) {       
    testequal(2, 0.5, 1.0, 1);
    testequal(3, 0.66, 1.5, 3);
    testequal(30, 0.66, 1.5, 15);
    testequal(30, 0.75, 1.5, 21);
    testequal(30, 0.4, 10, 3);
    testequal(40, 0.4, 10, 3);
    testequal(10, 0.6, 10, -1);
    testequal(40, 1, 10, -1);
    testequal(-5, 0.66, 1.5, -1);
    testequal(5, -1, 1.5, -1);
    testequal(4, 0.25, 1.0, 1);
}

static void testequal(double h, double bounce, double window, int expected) {
    int actual = bouncingBall(h, bounce, window);
    cr_assert_eq(actual, expected,
		"for h = %f, bounce = %f, window = %f\n"
		"expected %d, but got %d",
		h, bounce, window,
		expected, actual
	);
}</code></pre>



<h2 class="wp-block-heading">Solution</h2>



<pre title="Bouncing Balls" class="wp-block-code"><code lang="csharp" class="language-csharp line-numbers">int bouncingBall(double h, double bounce, double window)
{
  // your code;
  int s = 1;
  if (h &lt;= window || h &lt; 0 || bounce &lt; 0 || bounce &gt;= 1)
    s = -1;
  else
  {
    h = h * bounce;
    while (h &gt; window)
    {
      s += 2;
      h = h * bounce;
    }
  }

  return s;
}
</code></pre>
<p>The post <a href="https://onestringlab.com/bouncing-balls/">Belajar Bahasa C &#8211; Bouncing Balls</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
