<?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>Codewars Archives - Onestring Lab</title>
	<atom:link href="https://onestringlab.com/category/codewars/feed/" rel="self" type="application/rss+xml" />
	<link>https://onestringlab.com/category/codewars/</link>
	<description>Kode Kreativitas Kopi</description>
	<lastBuildDate>Mon, 04 May 2026 08:38:23 +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>Codewars Archives - Onestring Lab</title>
	<link>https://onestringlab.com/category/codewars/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Belajar Bahasa C &#8211; Sudoku Solution Validator</title>
		<link>https://onestringlab.com/sudoku-solution-validator/</link>
		
		<dc:creator><![CDATA[Rajo Intan]]></dc:creator>
		<pubDate>Wed, 14 Dec 2022 02:02:00 +0000</pubDate>
				<category><![CDATA[Codewars]]></category>
		<category><![CDATA[C Language]]></category>
		<category><![CDATA[Solution Validator]]></category>
		<category><![CDATA[Sudoku]]></category>
		<guid isPermaLink="false">https://onestringlab.com/?p=871</guid>

					<description><![CDATA[<p>Sudoku Background Sudoku is a game played on a 9&#215;9 grid. The goal of the game is to fill all cells of the grid with &#8230; </p>
<p>The post <a href="https://onestringlab.com/sudoku-solution-validator/">Belajar Bahasa C &#8211; Sudoku Solution Validator</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Sudoku Background</h2>



<p>Sudoku is a game played on a 9&#215;9 grid. The goal of the game is to fill all cells of the grid with digits from 1 to 9, so that each column, each row, and each of the nine 3&#215;3 sub-grids (also known as blocks) contain all of the digits from 1 to 9.<br>(More info at: http://en.wikipedia.org/wiki/Sudoku)</p>



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



<p>Write a function validSolution/ValidateSolution/valid_solution() that accepts a 2D array representing a Sudoku board, and returns true if it is a valid solution, or false otherwise. The cells of the sudoku board may also contain 0&#8217;s, which will represent empty cells. Boards containing one or more zeroes are considered to be invalid solutions.</p>



<p>The board is always 9 cells by 9 cells, and every cell only contains integers from 0 to 9.</p>



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



<pre class="wp-block-code"><code lang="csharp" class="language-csharp">validSolution([
  [5, 3, 4, 6, 7, 8, 9, 1, 2],
  [6, 7, 2, 1, 9, 5, 3, 4, 8],
  [1, 9, 8, 3, 4, 2, 5, 6, 7],
  [8, 5, 9, 7, 6, 1, 4, 2, 3],
  [4, 2, 6, 8, 5, 3, 7, 9, 1],
  [7, 1, 3, 9, 2, 4, 8, 5, 6],
  [9, 6, 1, 5, 3, 7, 2, 8, 4],
  [2, 8, 7, 4, 1, 9, 6, 3, 5],
  [3, 4, 5, 2, 8, 6, 1, 7, 9]
]); // =&gt; true

validSolution([
  [5, 3, 4, 6, 7, 8, 9, 1, 2], 
  [6, 7, 2, 1, 9, 0, 3, 4, 8],
  [1, 0, 0, 3, 4, 2, 5, 6, 0],
  [8, 5, 9, 7, 6, 1, 0, 2, 0],
  [4, 2, 6, 8, 5, 3, 7, 9, 1],
  [7, 1, 3, 9, 2, 4, 8, 5, 6],
  [9, 0, 1, 5, 3, 7, 2, 1, 4],
  [2, 8, 7, 4, 1, 9, 6, 3, 5],
  [3, 0, 0, 4, 8, 1, 1, 7, 9]
]); // =&gt; false</code></pre>



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



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

bool validSolution(unsigned int board[9][9])
{
  /* Write your code here */
  int b, k, ko, bb, kk, jum, cek = 1;

  for (b = 0; b &lt; 9; b++)
  {
    jum = 0;
    for (k = 0; k &lt; 9; k++)
    {
      jum = jum + board[b][k];
    }
    if (jum != 45)
    {
      cek = 0;
    }
  }

  for (b = 0; b &lt; 9; b++)
  {
    jum = 0;
    for (k = 0; k &lt; 9; k++)
    {
      jum = jum + board[k][b];
    }
    if (jum != 45)
    {
      cek = 0;
    }
  }

  for (ko = 0; ko &lt; 9; ko++)
  {
    bb = (ko / 3) * 3;
    kk = (ko % 3) * 3;
    jum = 0;
    for (b = bb; b &lt; bb + 3; b++)
    {
      for (k = kk; k &lt; kk + 3; k++)
      {
        jum = jum + board[b][k];
      }
    }
    if (jum != 45)
    {
      cek = 0;
    }
  }
  return cek;
}</code></pre>
<p>The post <a href="https://onestringlab.com/sudoku-solution-validator/">Belajar Bahasa C &#8211; Sudoku Solution Validator</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Belajar Bahasa C &#8211; ROT13</title>
		<link>https://onestringlab.com/rot13/</link>
		
		<dc:creator><![CDATA[Rajo Intan]]></dc:creator>
		<pubDate>Mon, 12 Dec 2022 01:36:00 +0000</pubDate>
				<category><![CDATA[Codewars]]></category>
		<category><![CDATA[C Language]]></category>
		<category><![CDATA[ROT13]]></category>
		<guid isPermaLink="false">https://onestringlab.com/?p=862</guid>

					<description><![CDATA[<p>How can you tell an extrovert from an introvert at NSA? Va gur ryringbef, gur rkgebireg ybbxf ng gur BGURE thl&#8217;f fubrf. I found this &#8230; </p>
<p>The post <a href="https://onestringlab.com/rot13/">Belajar Bahasa C &#8211; ROT13</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>How can you tell an extrovert from an introvert at NSA? Va gur ryringbef, gur rkgebireg ybbxf ng gur BGURE thl&#8217;f fubrf.</p>



<p>I found this joke on USENET, but the punchline is scrambled. Maybe you can decipher it? According to Wikipedia, ROT13 (<a href="http://en.wikipedia.org/wiki/ROT13" target="_blank" rel="noreferrer noopener">http://en.wikipedia.org/wiki/ROT13</a>) is frequently used to obfuscate jokes on USENET.</p>



<p>Hint: For this task you&#8217;re only supposed to substitute characters. Not spaces, punctuation, numbers etc.</p>



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



<pre class="wp-block-code"><code lang="csharp" class="language-csharp">"EBG13 rknzcyr." --&gt;
 "ROT13 example."

"This is my first ROT13 excercise!" --&gt;
 "Guvf vf zl svefg EBG13 rkprepvfr!"</code></pre>



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



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

char *rot13(char *str_out, const char *str_in)
{
  // write to str_out and return it
  *str_out = '\0';

  char b;
  unsigned long i;
  for (i = 0; i &lt; strlen(str_in); i++)
  {
    b = str_in[i];
    if ((b &gt;= 'A' &amp;&amp; b &lt;= 'M') || (b &gt;= 'a' &amp;&amp; b &lt;= 'm'))
      b += 13;
    else if ((b &gt;= 'N' &amp;&amp; b &lt;= 'Z') || (b &gt;= 'n' &amp;&amp; b &lt;= 'z'))
      b -= 13;
    strncat(str_out, &amp;b, 1);
  }
  return str_out;
}</code></pre>
<p>The post <a href="https://onestringlab.com/rot13/">Belajar Bahasa C &#8211; ROT13</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Belajar Bahasa C &#8211; Credit Card Mask</title>
		<link>https://onestringlab.com/credit-card-mask/</link>
		
		<dc:creator><![CDATA[Rajo Intan]]></dc:creator>
		<pubDate>Sat, 10 Dec 2022 01:41:00 +0000</pubDate>
				<category><![CDATA[Codewars]]></category>
		<category><![CDATA[C Language]]></category>
		<category><![CDATA[Credit Card Mask]]></category>
		<guid isPermaLink="false">https://onestringlab.com/?p=866</guid>

					<description><![CDATA[<p>Usually when you buy something, you&#8217;re asked whether your credit card number, phone number or answer to your most secret question is still correct. However, &#8230; </p>
<p>The post <a href="https://onestringlab.com/credit-card-mask/">Belajar Bahasa C &#8211; Credit Card Mask</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Usually when you buy something, you&#8217;re asked whether your credit card number, phone number or answer to your most secret question is still correct. However, since someone could look over your shoulder, you don&#8217;t want that shown on your screen. Instead, we mask it.</p>



<p>Your task is to write a function&nbsp;<code>maskify</code>, which changes all but the last four characters into&nbsp;<code>'#'</code>.</p>



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



<h2 class="wp-block-heading" id="examples">Examples</h2>



<pre class="wp-block-code"><code lang="csharp" class="language-csharp">"4556364607935616" --&gt; "############5616"
     "64607935616" --&gt;      "#######5616"
               "1" --&gt;                "1"
                "" --&gt;                 ""

// "What was the name of your first pet?"

"Skippy" --&gt; "##ippy"

"Nananananananananananananananana Batman!"
--&gt;
"####################################man!"</code></pre>



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



<pre title="Credit Card Mask" class="wp-block-code"><code lang="csharp" class="language-csharp line-numbers">#include &lt;string.h&gt;
char *maskify(char *masked, const char *string)
{
  unsigned long i, slen = strlen(string);
  strcpy(masked, string);
  if (slen &gt; 4)
    for (i = 0; i &lt; slen - 4; i++)
      masked[i] = '#';
  return masked; // return it
}</code></pre>
<p>The post <a href="https://onestringlab.com/credit-card-mask/">Belajar Bahasa C &#8211; Credit Card Mask</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Belajar Bahasa C &#8211; Mexican Wave</title>
		<link>https://onestringlab.com/mexican-wave/</link>
		
		<dc:creator><![CDATA[Rajo Intan]]></dc:creator>
		<pubDate>Thu, 08 Dec 2022 01:52:00 +0000</pubDate>
				<category><![CDATA[Codewars]]></category>
		<category><![CDATA[C Language]]></category>
		<category><![CDATA[Mexican Wave]]></category>
		<guid isPermaLink="false">https://onestringlab.com/?p=855</guid>

					<description><![CDATA[<p>Introduction The wave (known as the Mexican wave in the English-speaking world outside North America) is an example of metachronal rhythm achieved in a packed &#8230; </p>
<p>The post <a href="https://onestringlab.com/mexican-wave/">Belajar Bahasa C &#8211; Mexican Wave</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Introduction</h2>



<p>The wave (known as the Mexican wave in the English-speaking world outside North America) is an example of metachronal rhythm achieved in a packed stadium when successive groups of spectators briefly stand, yell, and raise their arms. Immediately upon stretching to full height, the spectator returns to the usual seated position.</p>



<p>The result is a wave of standing spectators that travels through the crowd, even though individual spectators never move away from their seats. In many large arenas the crowd is seated in a contiguous circuit all the way around the sport field, and so the wave is able to travel continuously around the arena; in discontinuous seating arrangements, the wave can instead reflect back and forth through the crowd. When the gap in seating is narrow, the wave can sometimes pass through it. Usually only one wave crest will be present at any given time in an arena, although simultaneous, counter-rotating waves have been produced. (Source <a href="https://en.wikipedia.org/wiki/Wave_(audience)" target="_blank" rel="noreferrer noopener">Wikipedia</a>)</p>



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



<p>In this simple Kata your task is to create a function that turns a string into a Mexican Wave. You will be passed a string and you must return that string in an array where an uppercase letter is a person standing up. The problem link is <a href="https://www.codewars.com/kata/58f5c63f1e26ecda7e000029/train/c/" target="_blank" rel="noreferrer noopener">here</a>.</p>



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



<ul class="wp-block-list">
<li>The input string will always be lower case but maybe empty.</li>



<li>If the character in the string is whitespace then pass over it as if it was an empty seat</li>
</ul>



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



<pre class="wp-block-code"><code lang="csharp" class="language-csharp">wave("hello") =&gt; {"Hello", "hEllo", "heLlo", "helLo", "hellO"}</code></pre>



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



<pre title="Mexican Wave" class="wp-block-code"><code lang="csharp" class="language-csharp line-numbers">void wave(const char *y, char **target)
{
  /* you don't have to allocate memory, use target */
  /* y string is always null terminated */
  /* each string in target has length strlen(y) + 1 */

  int i, k;
  char temp;
  int slen = strlen(y);
  char *c = (char *)calloc((slen + 1), sizeof(char));

  for (i = 0; i &lt; slen; i++)
  {
    strcpy(c, "");
    for (k = 0; k &lt; slen; k++)
    {
      temp = (k == i &amp;&amp; y[k] != 32) ? toupper(y[k]) : y[k];
      strncat(c, &amp;temp, 1);
    }
    if (y[i] != 32)
      strcpy(*target++, c);
  }
}</code></pre>
<p>The post <a href="https://onestringlab.com/mexican-wave/">Belajar Bahasa C &#8211; Mexican Wave</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<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>
		<item>
		<title>Belajar Bahasa C &#8211; Is a number prime?</title>
		<link>https://onestringlab.com/is-a-number-prime/</link>
		
		<dc:creator><![CDATA[Rajo Intan]]></dc:creator>
		<pubDate>Tue, 06 Dec 2022 02:05:00 +0000</pubDate>
				<category><![CDATA[Codewars]]></category>
		<category><![CDATA[C Language]]></category>
		<category><![CDATA[Number]]></category>
		<category><![CDATA[Prime]]></category>
		<guid isPermaLink="false">https://onestringlab.com/?p=843</guid>

					<description><![CDATA[<p>Define a function that takes an integer argument and returns a logical value&#160;true&#160;or&#160;false&#160;depending on if the integer is a prime. Per Wikipedia, a prime number &#8230; </p>
<p>The post <a href="https://onestringlab.com/is-a-number-prime/">Belajar Bahasa C &#8211; Is a number prime?</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Define a function that takes an integer argument and returns a logical value&nbsp;<code>true</code>&nbsp;or&nbsp;<code>false</code>&nbsp;depending on if the integer is a prime.</p>



<p>Per Wikipedia, a prime number ( or a prime ) is a natural number greater than&nbsp;<code>1</code>&nbsp;that has no positive divisors other than&nbsp;<code>1</code>&nbsp;and itself.</p>



<p>The problem link is <a href="http://bit.ly/3FpRUvp" target="_blank" rel="noreferrer noopener">here</a></p>



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



<ul class="wp-block-list">
<li>You can assume you will be given an integer input.</li>



<li>You can not assume that the integer will be only positive. You may be given negative numbers as well ( or&nbsp;<code>0</code>&nbsp;).</li>



<li><strong>NOTE on performance</strong>: There are no fancy optimizations required, but still&nbsp;<em>the</em>&nbsp;most trivial solutions might time out. Numbers go up to 2^31 ( or similar, depending on language ). Looping all the way up to&nbsp;<code>n</code>, or&nbsp;<code>n/2</code>, will be too slow.</li>
</ul>



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



<pre class="wp-block-code"><code lang="csharp" class="language-csharp">is_prime(1)  /* false */
is_prime(2)  /* true  */
is_prime(-1) /* false */</code></pre>



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



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

bool is_prime(int num);

Test(Sample_Test, basic_test)
{
    cr_assert_not(is_prime(0), "Your solution returned that 0 is prime, but it's not");
    cr_assert_not(is_prime(1), "Your solution returned that 1 is prime, but it's not");
    cr_assert(is_prime(2), "Your solution returned that 2 is not prime, but it is");
    cr_assert(is_prime(73), "Your solution returned that 73 is not prime, but it is");
    cr_assert_not(is_prime(75), "Your solution returned that 75 is prime, but it's not");
    cr_assert_not(is_prime(-1), "Your solution returned that -1 is prime, but it's not");
}

Test(Sample_Test, test_prime)
{
    cr_assert(is_prime(3), "Your solution returned that 3 is not prime, but it is");
    cr_assert(is_prime(5), "Your solution returned that 5 is not prime, but it is");
    cr_assert(is_prime(7), "Your solution returned that 7 is not prime, but it is");
    cr_assert(is_prime(41), "Your solution returned that 41 is not prime, but it is");
    cr_assert(is_prime(5099), "Your solution returned that 5099 is not prime, but it is");
}

Test(Sample_Test, test_not_prime)
{
    cr_assert_not(is_prime(4), "Your solution returned that 4 is prime, but it's not");
    cr_assert_not(is_prime(6), "Your solution returned that 6 is prime, but it's not");
    cr_assert_not(is_prime(8), "Your solution returned that 8 is prime, but it's not");
    cr_assert_not(is_prime(9), "Your solution returned that 9 is prime, but it's not");
    cr_assert_not(is_prime(45), "Your solution returned that 45 is prime, but it's not");
    cr_assert_not(is_prime(-5), "Your solution returned that -5 is prime, but it's not");
    cr_assert_not(is_prime(-8), "Your solution returned that -8 is prime, but it's not");
    cr_assert_not(is_prime(-41), "Your solution returned that -41 is prime, but it's not");
}

Test(Sample_Test, test_large)
{
    cr_assert_not(is_prime(247464361), "Your solution returned that 247464361 is prime, but it's not");
    cr_assert(is_prime(1634300119), "Your solution returned that 1634300119 is not prime, but it is");
}</code></pre>



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



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

bool is_prime(int num)
{
  bool prime = true;
  int i, k;

  if (num &lt;= 1 || (num % 2 == 0 &amp;&amp; num != 2))
    prime = false;
  k = floor(sqrt(num));
  for (i = 3; i &lt;= k; i++)
    if (num % i == 0)
      prime = false;
  return prime;
}</code></pre>
<p>The post <a href="https://onestringlab.com/is-a-number-prime/">Belajar Bahasa C &#8211; Is a number prime?</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Belajar Bahasa C &#8211; Moving Zeros To The End</title>
		<link>https://onestringlab.com/moving-zeros-to-the-end/</link>
		
		<dc:creator><![CDATA[Rajo Intan]]></dc:creator>
		<pubDate>Mon, 05 Dec 2022 02:00:00 +0000</pubDate>
				<category><![CDATA[Codewars]]></category>
		<category><![CDATA[C Language]]></category>
		<category><![CDATA[Moving Zeros To The End]]></category>
		<guid isPermaLink="false">https://onestringlab.com/?p=821</guid>

					<description><![CDATA[<p>Write an algorithm that takes an array and moves all of the zeros to the end, preserving the order of the other elements. The problem &#8230; </p>
<p>The post <a href="https://onestringlab.com/moving-zeros-to-the-end/">Belajar Bahasa C &#8211; Moving Zeros To The End</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Write an algorithm that takes an array and moves all of the zeros to the end, preserving the order of the other elements. The problem link is <a href="http://bit.ly/3B9KKJj" target="_blank" rel="noreferrer noopener">here</a>.</p>



<p><strong>Examples</strong>:</p>



<pre class="wp-block-code"><code lang="csharp" class="language-csharp">move_zeros(10, int [] {1, 2, 0, 1, 0, 1, 0, 3, 0, 1}); // -&gt; int [] {1, 2, 1, 1, 3, 1, 0, 0, 0, 0}</code></pre>



<p><strong>Sample Tests:</strong></p>



<pre class="wp-block-code"><code lang="csharp" class="language-csharp">Test(move_zeros, sample_tests) {
    do_test(8, ((int []) {0, 1, 0, 2, 0, 3, 4, 5}), ((int []) {1, 2, 3, 4, 5, 0, 0, 0}));
    do_test(20, ((int []) {9, 0, 0, 9, 1, 2, 0, 1, 0, 1, 0, 3, 0, 1, 9, 0, 0, 0, 0, 9}), ((int []) {9, 9, 1, 2, 1, 1, 3, 1, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}));
    do_test(2, ((int []) {0, 0}), ((int []) {0, 0}));
    do_test(1, ((int []) {0}), ((int []) {0}));
    do_test(0, ((int []) {}), ((int []) {}));
}</code></pre>



<p><strong>Solution:</strong></p>



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

void move_zeros(size_t len, int arr[len])
{
  // mutate arr in place
  size_t i, j, k, temp;
  for (i = 0; i &lt; len; i++)
  {
    if (arr[i] == 0)
    {
      k = i;
      for (j = i + 1; j &lt; len; j++)
      {
        if (arr[j] != 0)
        {
          temp = arr[j];
          arr[j] = 0;
          arr[k] = temp;
          k = j;
        }
      }
    }
  }
}
</code></pre>
<p>The post <a href="https://onestringlab.com/moving-zeros-to-the-end/">Belajar Bahasa C &#8211; Moving Zeros To The End</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Belajar Bahasa C &#8211; Roman Numerals Decoder</title>
		<link>https://onestringlab.com/roman-numerals-decoder/</link>
		
		<dc:creator><![CDATA[Rajo Intan]]></dc:creator>
		<pubDate>Sun, 04 Dec 2022 03:24:06 +0000</pubDate>
				<category><![CDATA[Codewars]]></category>
		<category><![CDATA[C Language]]></category>
		<category><![CDATA[Roman Numerals Decoder]]></category>
		<guid isPermaLink="false">https://onestringlab.com/?p=805</guid>

					<description><![CDATA[<p>Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don&#8217;t need to validate &#8230; </p>
<p>The post <a href="https://onestringlab.com/roman-numerals-decoder/">Belajar Bahasa C &#8211; Roman Numerals Decoder</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don&#8217;t need to validate the form of the Roman numeral.</p>



<p>Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost digit and skipping any 0s. So 1990 is rendered &#8220;MCMXC&#8221; (1000 = M, 900 = CM, 90 = XC) and 2008 is rendered &#8220;MMVIII&#8221; (2000 = MM, 8 = VIII). The Roman numeral for 1666, &#8220;MDCLXVI&#8221;, uses each letter in descending order.</p>



<p><strong>Example:</strong></p>



<pre class="wp-block-code"><code class="">solution('XXI'); // should return 21</code></pre>



<p>The problem link is <a href="http://bit.ly/3Uv5guK" target="_blank" rel="noreferrer noopener">here</a>.</p>



<p><strong>Solution:</strong></p>



<pre title="Roman Numerals Decoder" class="wp-block-code"><code lang="csharp" class="language-csharp line-numbers">#include &lt;string.h&gt;

int roman_val(char roman)
{
  int val = 0;

  switch (roman)
  {
  case 'I':
    return val = 1;
    break;
  case 'V':
    return val = 5;
    break;
  case 'X':
    return val = 10;
    break;
  case 'L':
    return val = 50;
    break;
  case 'C':
    return val = 100;
    break;
  case 'D':
    return val = 500;
    break;
  case 'M':
    return val = 1000;
    break;
  }
  return val;
}

unsigned decode_roman(const char *roman_number)
{
  unsigned long len = strlen(roman_number);
  unsigned i, n, m, value = 0;

  for (i = 0; i &lt; len; i++)
  {
    n = roman_val(roman_number[i]);
    m = roman_val(roman_number[i + 1]);

    if (n &gt;= m)
      value += n;
    else if (n &lt; m)
      value += (m - n), i++;
  }
  return value;
}
</code></pre>
<p>The post <a href="https://onestringlab.com/roman-numerals-decoder/">Belajar Bahasa C &#8211; Roman Numerals Decoder</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Belajar Bahasa C &#8211; Complementary DNA</title>
		<link>https://onestringlab.com/complementary-dna/</link>
		
		<dc:creator><![CDATA[Rajo Intan]]></dc:creator>
		<pubDate>Sat, 03 Dec 2022 02:00:00 +0000</pubDate>
				<category><![CDATA[Codewars]]></category>
		<category><![CDATA[C Language]]></category>
		<category><![CDATA[Complementary DNA]]></category>
		<guid isPermaLink="false">https://onestringlab.com/?p=788</guid>

					<description><![CDATA[<p>Deoxyribonucleic acid (DNA) is a chemical found in the nucleus of cells and carries the &#8220;instructions&#8221; for the development and functioning of living organisms. If &#8230; </p>
<p>The post <a href="https://onestringlab.com/complementary-dna/">Belajar Bahasa C &#8211; Complementary DNA</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Deoxyribonucleic acid (DNA) is a chemical found in the nucleus of cells and carries the &#8220;instructions&#8221; for the development and functioning of living organisms.</p>



<p>If you want to know more: http://en.wikipedia.org/wiki/DNA</p>



<p>In DNA strings, symbols &#8220;A&#8221; and &#8220;T&#8221; are complements of each other, as &#8220;C&#8221; and &#8220;G&#8221;. Your function receives one side of the DNA (string, except for Haskell); you need to return the other complementary side. DNA strand is never empty or there is no DNA at all (again, except for Haskell).</p>



<p>More similar exercise are found here: http://rosalind.info/problems/list-view/ (source)</p>



<p>Example: (input &#8211;&gt; output)</p>



<pre class="wp-block-code"><code class="">"ATTGC" --&gt; "TAACG"
"GTAT" --&gt; "CATA"</code></pre>



<p>The problem link is <a href="https://bit.ly/3VBMbrN" target="_blank" rel="noreferrer noopener">here</a>.</p>



<p><strong>Solution:</strong></p>



<pre title="Complementary DNA" class="wp-block-code"><code lang="csharp" class="language-csharp line-numbers">#include &lt;string.h&gt;

char *dna_strand(const char *dna)
{

  int len = strlen(dna);
  int i;
  char *cdna = calloc(len + 1, sizeof(char));
  char temp;

  strcpy(cdna, "");

  for (i = 0; i &lt; len; i++)
  {
    if (dna[i] == 'A')
    {
      temp = 'T';
      strncat(cdna, &amp;temp, 1);
    }
    else if (dna[i] == 'T')
    {
      temp = 'A';
      strncat(cdna, &amp;temp, 1);
    }
    else if (dna[i] == 'C')
    {
      temp = 'G';
      strncat(cdna, &amp;temp, 1);
    }
    else if (dna[i] == 'G')
    {
      temp = 'C';
      strncat(cdna, &amp;temp, 1);
    }
  }
  return cdna;
}</code></pre>
<p>The post <a href="https://onestringlab.com/complementary-dna/">Belajar Bahasa C &#8211; Complementary DNA</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Belajar Bahasa C &#8211; Persistent Bugger</title>
		<link>https://onestringlab.com/persistent-bugger/</link>
		
		<dc:creator><![CDATA[Rajo Intan]]></dc:creator>
		<pubDate>Fri, 02 Dec 2022 04:28:00 +0000</pubDate>
				<category><![CDATA[Codewars]]></category>
		<category><![CDATA[C Language]]></category>
		<category><![CDATA[Persistent Bugger]]></category>
		<guid isPermaLink="false">https://onestringlab.com/?p=785</guid>

					<description><![CDATA[<p>Write a function,&#160;persistence, that takes in a positive parameter&#160;num&#160;and returns its multiplicative persistence, which is the number of times you must multiply the digits in&#160;num&#160;until &#8230; </p>
<p>The post <a href="https://onestringlab.com/persistent-bugger/">Belajar Bahasa C &#8211; Persistent Bugger</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Write a function,&nbsp;<code>persistence</code>, that takes in a positive parameter&nbsp;<code>num</code>&nbsp;and returns its multiplicative persistence, which is the number of times you must multiply the digits in&nbsp;<code>num</code>&nbsp;until you reach a single digit.</p>



<p>For example&nbsp;<strong>(Input &#8211;&gt; Output)</strong>:</p>



<pre class="wp-block-code"><code class="">39 --&gt; 3 (because 3*9 = 27, 2*7 = 14, 1*4 = 4 and 4 has only one digit)
999 --&gt; 4 (because 9*9*9 = 729, 7*2*9 = 126, 1*2*6 = 12, and finally 1*2 = 2)
4 --&gt; 0 (because 4 is already a one-digit number)</code></pre>



<p>The problem link is <a href="https://bit.ly/3gLAShQ">here</a>.</p>



<p><strong>Solution:</strong></p>



<pre class="wp-block-code"><code lang="csharp" class="language-csharp line-numbers">int persistence(int n)
{
  int x = 0;
  while (n &gt; 9)
  {
    int m = 1;
    while (n)
    {
      m = m * (n % 10);
      n = n / 10;
    }
    n = m;
    x++;
  }
  return x;
}</code></pre>
<p>The post <a href="https://onestringlab.com/persistent-bugger/">Belajar Bahasa C &#8211; Persistent Bugger</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Belajar Bahasa C &#8211; Mumbling</title>
		<link>https://onestringlab.com/mumbling/</link>
		
		<dc:creator><![CDATA[Rajo Intan]]></dc:creator>
		<pubDate>Thu, 01 Dec 2022 10:08:00 +0000</pubDate>
				<category><![CDATA[Codewars]]></category>
		<category><![CDATA[C Language]]></category>
		<category><![CDATA[Mumbling]]></category>
		<guid isPermaLink="false">https://onestringlab.com/?p=782</guid>

					<description><![CDATA[<p>This time no story, no theory. The examples below show you how to write function&#160;accum: Examples: The problem link is here. Solution:</p>
<p>The post <a href="https://onestringlab.com/mumbling/">Belajar Bahasa C &#8211; Mumbling</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>This time no story, no theory. The examples below show you how to write function&nbsp;<code>accum</code>: </p>



<p><strong>Examples</strong>:</p>



<pre class="wp-block-code"><code class="">accum("abcd") -&gt; "A-Bb-Ccc-Dddd"
accum("RqaEzty") -&gt; "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy"
accum("cwAt") -&gt; "C-Ww-Aaa-Tttt"</code></pre>



<p>The problem link is <a href="http://bit.ly/3GXJiNS" target="_blank" rel="noreferrer noopener">here</a>.</p>



<p><strong>Solution</strong>:</p>



<pre title="mumbling" class="wp-block-code"><code lang="csharp" class="language-csharp line-numbers">char *accum(const char *source)
{
  char temp;
  unsigned long i, j, mem;
  unsigned long length = strlen(source);

  mem = strlen(source);
  for (i = 0; i &lt;= length; i++)
  {
    mem += i;
  }

  char *mumbling = calloc(mem + 1, sizeof(char));

  for (i = 0; i &lt; length; i++)
  {
    for (j = 0; j &lt; i + 1; j++)
    {

      temp = (j == 0) ? toupper(source[i]) : tolower(source[i]);
      strncat(mumbling, &amp;temp, 1);
    }

    (i &lt; length - 1) ? strncat(mumbling, "-", 1) : "";
  }
  return mumbling;
}</code></pre>
<p>The post <a href="https://onestringlab.com/mumbling/">Belajar Bahasa C &#8211; Mumbling</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Belajar Bahasa C &#8211; Find the missing letter</title>
		<link>https://onestringlab.com/find-the-missing-letter/</link>
		
		<dc:creator><![CDATA[Rajo Intan]]></dc:creator>
		<pubDate>Wed, 30 Nov 2022 10:58:51 +0000</pubDate>
				<category><![CDATA[Codewars]]></category>
		<category><![CDATA[C Language]]></category>
		<category><![CDATA[Find the missing letter]]></category>
		<guid isPermaLink="false">https://onestringlab.com/?p=773</guid>

					<description><![CDATA[<p>Write a method that takes an array of consecutive (increasing) letters as input and that returns the missing letter in the array. You will always &#8230; </p>
<p>The post <a href="https://onestringlab.com/find-the-missing-letter/">Belajar Bahasa C &#8211; Find the missing letter</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Write a method that takes an array of consecutive (increasing) letters as input and that returns the missing letter in the array.</p>



<p>You will always get an valid array. And it will be always exactly one letter be missing. The length of the array will always be at least 2. The array will always contain letters in only one case.</p>



<p><strong>Example</strong>:</p>



<pre class="wp-block-code"><code class="">['a','b','c','d','f'] -&gt; 'e'
['O','Q','R','S'] -&gt; 'P'</code></pre>



<p>(Use the English alphabet with 26 letters!) Have fun coding it and please don&#8217;t forget to vote and rank this kata! :-). I have also created other katas. Take a look if you enjoyed this kata!</p>



<p>The link problem is <a href="https://bit.ly/3Ff9h22" target="_blank" rel="noreferrer noopener">here</a>.</p>



<p><strong>Solution</strong>:</p>



<pre title="Find the missing letter" class="wp-block-code"><code lang="cpp" class="language-cpp line-numbers">char findMissingLetter(char array[], int arrayLength)
{
  char miss, start;
  int i;

  start = array[0];
  for (i = 0; i &lt; arrayLength; i++)
  {
    if (start != array[i])
    {
      miss = start;
      break;
    }
    start = start + 1;
  }
  return miss;
}</code></pre>
<p>The post <a href="https://onestringlab.com/find-the-missing-letter/">Belajar Bahasa C &#8211; Find the missing letter</a> appeared first on <a href="https://onestringlab.com">Onestring Lab</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
