bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

commit 1ac322c3215b797258c85dbbdb8b8a8c764b05d2
parent 3336fd8f727d1c01a3528af06f2bf251740dbd3d
Author: Amit Dutta <amitdutta4255@gmail.com>
Date:   Thu, 23 Oct 2025 12:11:14 +0530

new

Diffstat:
Mdocs/index.html | 225++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Mletusc/luc037.c | 2+-
Mletusc/luc038.c | 2+-
Mletusc/luc039.c | 2+-
Aletusc/luc040-logic.c | 127+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mletusc/luc040.c | 62+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Aletusc/luc041.c | 4++++
7 files changed, 419 insertions(+), 5 deletions(-)

diff --git a/docs/index.html b/docs/index.html @@ -720,7 +720,7 @@ int main() <div class="flex items-center"> <svg class="w-6 h-6 text-blue-500 mr-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"></path></svg> <span class="font-medium text-gray-800">letusc</span> - <span class="ml-2 text-sm text-gray-500">(48 files)</span> + <span class="ml-2 text-sm text-gray-500">(50 files)</span> </div> <div class="flex items-center space-x-4"> <a href="https://github.com/notamitgamer/bsc/tree/main/letusc" target="_blank" class="p-1 rounded-full text-gray-500 hover:bg-gray-200 hover:text-gray-800 transition-colors" onclick="event.stopPropagation()" title="View folder on GitHub"> @@ -2703,6 +2703,229 @@ int main() <li> <div class="flex items-center p-3 pl-8 hover:bg-gray-50 transition-colors duration-200"> <svg class="w-6 h-6 text-green-500 mr-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"></path></svg> + <span class="text-gray-700">luc040-logic.c</span> + <div class="ml-auto flex items-center space-x-4"> + <a href="https://github.com/notamitgamer/bsc/blob/main/letusc/luc040-logic.c" target="_blank" class="p-1 rounded-full text-gray-500 hover:bg-gray-200 hover:text-gray-800 transition-colors" title="View file on GitHub"> + <svg class="w-6 h-6" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.477 2 12c0 4.418 2.865 8.168 6.839 9.492.5.092.682-.217.682-.482 0-.237-.009-.868-.014-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.031-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.203 2.398.1 2.651.64.7 1.03 1.595 1.03 2.688 0 3.848-2.338 4.695-4.566 4.942.359.308.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.001 10.001 0 0022 12c0-5.523-4.477-10-10-10z" clip-rule="evenodd"></path></svg> + </a> + <button onclick="showCode('code-letusc-luc040-logic_c', 'luc040-logic.c')" class="text-green-600 font-semibold text-sm hover:underline">View Code</button> + </div> + </div> + <div id="code-letusc-luc040-logic_c" class="hidden" data-github-url="https://github.com/notamitgamer/bsc/blob/main/letusc/luc040-logic.c"> + <pre><code class="language-c">/* Ramanujan number (1729) is the smallest number that can be +expressed as sum of cubes in two different ways - 1729 can be +expressed as 1^3 + 12^3 and 9^3 + 10^3. Write a program to print all such +numbers up to a reasonable limit. */ +/* Author - Amit Dutta, Date - 22th OCT, 2025 */ +/* Let Us C, Chap- 6, Page - 106, Qn No.: B(g) */ + +// 1. INCLUDE SECTION +#include &lt;stdio.h&gt; // Includes the standard input/output library, necessary for printf() + +// 2. CONSTANT DEFINITIONS (MACROS) +// These define fixed values we can easily use and change later. +#define LIMIT 100000 // The maximum number we want to search up to. +// The maximum base value (a, b, c, or d) we need to check. +// Since 47^3 is greater than 100,000, checking bases up to 47 covers the LIMIT. +#define MAX_BASE_VAL 47 + +// 3. MAIN FUNCTION +int main() +{ + // 4. VARIABLE DECLARATION + + // sum1 and sum2 store the results of a^3 + b^3 and c^3 + d^3. + // We use &#x27;long long&#x27; because cubes (like 47^3) are large and can exceed + // the capacity of a standard &#x27;int&#x27;, preventing errors. + long long sum1, sum2; + + int count = 0; // Counter to keep track of how many Ramanujan numbers we find. + + // This flag is used to optimize the search. If we find the second way (c^3 + d^3) + // to make sum1, we set this to 1 and immediately stop the inner loops. + int found_match; + + // Print introductory message to the user. + printf(&quot;Ramanujan Number Finder (a^3 + b^3 = c^3 + d^3)\n&quot;); + printf(&quot;Searching up to %d (Max base value is %d)\n&quot;, LIMIT, MAX_BASE_VAL); + printf(&quot;---------------------------------------------------\n&quot;); + + // 5. OUTER LOOPS: Establishing the FIRST SUM (a^3 + b^3 = sum1) + + // Loop for &#x27;a&#x27; (the smaller base of the first pair) + for (int a = 1; a &lt;= MAX_BASE_VAL; a++) + { + + // Loop for &#x27;b&#x27; (the larger base of the first pair) + // We start &#x27;b&#x27; at &#x27;a + 1&#x27; to enforce the rule a &lt; b. + // This prevents us from checking redundant pairs like (1, 12) and (12, 1). + for (int b = a + 1; b &lt;= MAX_BASE_VAL; b++) + { + + // Calculate the first sum: sum1 = a^3 + b^3 + // (long long) is a cast to ensure the math is done using the &#x27;long long&#x27; type. + sum1 = (long long)a * a * a + (long long)b * b * b; + + // Optimization 1: Check if the sum exceeds the global limit. + if (sum1 &gt; LIMIT) + { + // Since &#x27;b&#x27; is increasing, any further increase will also be over the limit. + // We stop the &#x27;b&#x27; loop and move to the next &#x27;a&#x27;. + break; + } + + // Reset the flag for every new sum1. + // We start searching for a second way for this new &#x27;sum1&#x27;, so we reset the flag to 0. + found_match = 0; + + // 6. INNER LOOPS: Searching for the SECOND SUM (c^3 + d^3 = sum2) + + // Loop for &#x27;c&#x27; (the smaller base of the second pair) + // We start &#x27;c&#x27; at &#x27;a + 1&#x27; to enforce the rule a &lt; c. + // This ensures the two pairs {(a, b) and (c, d)} are truly distinct (e.g., 1729 = 1^3 + 12^3 and 9^3 + 10^3). + for (int c = a + 1; c &lt;= MAX_BASE_VAL; c++) + { + + // Optimization 2: Check the flag to exit the &#x27;c&#x27; loop early. + if (found_match) + { + // If we already found the second way (c, d) in a previous iteration of &#x27;c&#x27;, stop searching and move to the next (a, b) pair. + break; + } + + // Loop for &#x27;d&#x27; (the larger base of the second pair) + // We start &#x27;d&#x27; at &#x27;c + 1&#x27; to enforce c &lt; d. + for (int d = c + 1; d &lt;= MAX_BASE_VAL; d++) + { + + // Calculate the second sum: sum2 = c^3 + d^3 + sum2 = (long long)c * c * c + (long long)d * d * d; + + // Optimization 3: Check if the second sum has passed the first sum. + if (sum2 &gt; sum1) + { + // Since &#x27;d&#x27; is increasing, any further increase will also be greater than sum1. + // We stop the &#x27;d&#x27; loop and move to the next &#x27;c&#x27;. + break; + } + + // 7. CONDITION CHECK: Have we found a Ramanujan number? + // Check if the two sums are equal. + if (sum1 == sum2) + { + count++; // Increment the counter + + // Print the result in the required format. + printf(&quot;[%d] %lld = %d^3 + %d^3 = %d^3 + %d^3\n&quot;, + count, sum1, a, b, c, d); + + // Set the flag to 1, confirming we found the second way. + found_match = 1; + + // Stop the &#x27;d&#x27; loop immediately, as we found the required second pair. + break; + } + } + // If found_match was set to 1, the &#x27;break&#x27; in the d loop will execute, + // then the &#x27;if (found_match) break;&#x27; in the c loop will execute, + // and the program will move to the next (a, b) pair. + } + } + } + + // 8. CONCLUSION + printf(&quot;---------------------------------------------------\n&quot;); + printf(&quot;Search complete. Found %d Ramanujan-type numbers.\n&quot;, count); + + return 0; // Standard way to indicate successful program execution. +} +</code></pre> + </div> + </li> + + <li> + <div class="flex items-center p-3 pl-8 hover:bg-gray-50 transition-colors duration-200"> + <svg class="w-6 h-6 text-green-500 mr-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"></path></svg> + <span class="text-gray-700">luc040.c</span> + <div class="ml-auto flex items-center space-x-4"> + <a href="https://github.com/notamitgamer/bsc/blob/main/letusc/luc040.c" target="_blank" class="p-1 rounded-full text-gray-500 hover:bg-gray-200 hover:text-gray-800 transition-colors" title="View file on GitHub"> + <svg class="w-6 h-6" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.477 2 12c0 4.418 2.865 8.168 6.839 9.492.5.092.682-.217.682-.482 0-.237-.009-.868-.014-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.031-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.203 2.398.1 2.651.64.7 1.03 1.595 1.03 2.688 0 3.848-2.338 4.695-4.566 4.942.359.308.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.001 10.001 0 0022 12c0-5.523-4.477-10-10-10z" clip-rule="evenodd"></path></svg> + </a> + <button onclick="showCode('code-letusc-luc040_c', 'luc040.c')" class="text-green-600 font-semibold text-sm hover:underline">View Code</button> + </div> + </div> + <div id="code-letusc-luc040_c" class="hidden" data-github-url="https://github.com/notamitgamer/bsc/blob/main/letusc/luc040.c"> + <pre><code class="language-c">/* Ramanujan number (1729) is the smallest number that can be +expressed as sum of cubes in two different ways - 1729 can be +expressed as 1^3 + 12^3 and 9^3 + 10^3. Write a program to print all such +numbers up to a reasonable limit. */ +/* Author - Amit Dutta, Date - 22th OCT, 2025 */ +/* Let Us C, Chap- 6, Page - 106, Qn No.: B(g) */ + +#include &lt;stdio.h&gt; + +#define limit 100000 +#define max_base 47 + +int main() +{ + + long long sum1, sum2; + int count = 0; + + printf(&quot;Ramanujan numbers : \n&quot;); + + int found_match; + + for (int a = 1; a &lt;= max_base; a++) + { + for (int b = a + 1; b &lt;= max_base; b++) + { + sum1 = (long long)a * a * a + (long long)b * b * b; + if (sum1 &gt; limit) + { + break; + } + + found_match = 0; + + for (int c = a + 1; c &lt;= max_base; c++) + { + if (found_match) + { + break; + } + for (int d = c + 1; d &lt;= max_base; d++) + { + sum2 = (long long)c * c * c + (long long)d * d * d; + if (sum2 &gt; sum1) + { + break; + } + if (sum1 == sum2) + { + count++; + printf(&quot;(%d.) %lld = %d^3 + %d^3 = %d^3 + %d^3\n&quot;, count, sum1, a, b, c, d); + + found_match = 1; + break; + } + } + } + } + } + + printf(&quot;-------------------------------\n&quot;); + printf(&quot;Search complete.&quot;); + + return 0; +}</code></pre> + </div> + </li> + + <li> + <div class="flex items-center p-3 pl-8 hover:bg-gray-50 transition-colors duration-200"> + <svg class="w-6 h-6 text-green-500 mr-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"></path></svg> <span class="text-gray-700">lucproblem001.c</span> <div class="ml-auto flex items-center space-x-4"> <a href="https://github.com/notamitgamer/bsc/blob/main/letusc/lucproblem001.c" target="_blank" class="p-1 rounded-full text-gray-500 hover:bg-gray-200 hover:text-gray-800 transition-colors" title="View file on GitHub"> diff --git a/letusc/luc037.c b/letusc/luc037.c @@ -2,7 +2,7 @@ (x-1)/x + 1/2 ((x-1)/x)^2 + 1/2 ((x-1)/x)^3 + 1/2 ((x-1)/x)^4 + ... If x is input through the keyboard, write a program to calculate the sum of the first seven terms of this series. */ -/* Author - Amit Dutta, Date - 21th OCT, 2025 */ +/* Author - Amit Dutta, Date - 21st OCT, 2025 */ /* Let Us C, Chap- 6, Page - 106, Qn No.: B(d) */ #include <stdio.h> diff --git a/letusc/luc038.c b/letusc/luc038.c @@ -1,6 +1,6 @@ /* Write a program to generate all Pythagorean Triplets with slide length less than or equal to 30. */ -/* Author - Amit Dutta, Date - 21th OCT, 2025 */ +/* Author - Amit Dutta, Date - 21st OCT, 2025 */ /* Let Us C, Chap- 6, Page - 106, Qn No.: B(e) */ #include <stdio.h> diff --git a/letusc/luc039.c b/letusc/luc039.c @@ -2,7 +2,7 @@ steadily at the rate of 10% per year for last 10 years. Write a program to determine the population at the end of each year in the last decade. */ -/* Author - Amit Dutta, Date - 21th OCT, 2025 */ +/* Author - Amit Dutta, Date - 21st OCT, 2025 */ /* Let Us C, Chap- 6, Page - 106, Qn No.: B(f) */ #include <stdio.h> diff --git a/letusc/luc040-logic.c b/letusc/luc040-logic.c @@ -0,0 +1,127 @@ +/* Ramanujan number (1729) is the smallest number that can be +expressed as sum of cubes in two different ways - 1729 can be +expressed as 1^3 + 12^3 and 9^3 + 10^3. Write a program to print all such +numbers up to a reasonable limit. */ +/* Author - Amit Dutta, Date - 22nd - 23rd OCT, 2025 */ +/* Let Us C, Chap- 6, Page - 106, Qn No.: B(g) */ + +// 1. INCLUDE SECTION +#include <stdio.h> // Includes the standard input/output library, necessary for printf() + +// 2. CONSTANT DEFINITIONS (MACROS) +// These define fixed values we can easily use and change later. +#define LIMIT 100000 // The maximum number we want to search up to. +// The maximum base value (a, b, c, or d) we need to check. +// Since 47^3 is greater than 100,000, checking bases up to 47 covers the LIMIT. +#define MAX_BASE_VAL 47 + +// 3. MAIN FUNCTION +int main() +{ + // 4. VARIABLE DECLARATION + + // sum1 and sum2 store the results of a^3 + b^3 and c^3 + d^3. + // We use 'long long' because cubes (like 47^3) are large and can exceed + // the capacity of a standard 'int', preventing errors. + long long sum1, sum2; + + int count = 0; // Counter to keep track of how many Ramanujan numbers we find. + + // This flag is used to optimize the search. If we find the second way (c^3 + d^3) + // to make sum1, we set this to 1 and immediately stop the inner loops. + int found_match; + + // Print introductory message to the user. + printf("Ramanujan Number Finder (a^3 + b^3 = c^3 + d^3)\n"); + printf("Searching up to %d (Max base value is %d)\n", LIMIT, MAX_BASE_VAL); + printf("---------------------------------------------------\n"); + + // 5. OUTER LOOPS: Establishing the FIRST SUM (a^3 + b^3 = sum1) + + // Loop for 'a' (the smaller base of the first pair) + for (int a = 1; a <= MAX_BASE_VAL; a++) + { + + // Loop for 'b' (the larger base of the first pair) + // We start 'b' at 'a + 1' to enforce the rule a < b. + // This prevents us from checking redundant pairs like (1, 12) and (12, 1). + for (int b = a + 1; b <= MAX_BASE_VAL; b++) + { + + // Calculate the first sum: sum1 = a^3 + b^3 + // (long long) is a cast to ensure the math is done using the 'long long' type. + sum1 = (long long)a * a * a + (long long)b * b * b; + + // Optimization 1: Check if the sum exceeds the global limit. + if (sum1 > LIMIT) + { + // Since 'b' is increasing, any further increase will also be over the limit. + // We stop the 'b' loop and move to the next 'a'. + break; + } + + // Reset the flag for every new sum1. + // We start searching for a second way for this new 'sum1', so we reset the flag to 0. + found_match = 0; + + // 6. INNER LOOPS: Searching for the SECOND SUM (c^3 + d^3 = sum2) + + // Loop for 'c' (the smaller base of the second pair) + // We start 'c' at 'a + 1' to enforce the rule a < c. + // This ensures the two pairs {(a, b) and (c, d)} are truly distinct (e.g., 1729 = 1^3 + 12^3 and 9^3 + 10^3). + for (int c = a + 1; c <= MAX_BASE_VAL; c++) + { + + // Optimization 2: Check the flag to exit the 'c' loop early. + if (found_match) + { + // If we already found the second way (c, d) in a previous iteration of 'c', stop searching and move to the next (a, b) pair. + break; + } + + // Loop for 'd' (the larger base of the second pair) + // We start 'd' at 'c + 1' to enforce c < d. + for (int d = c + 1; d <= MAX_BASE_VAL; d++) + { + + // Calculate the second sum: sum2 = c^3 + d^3 + sum2 = (long long)c * c * c + (long long)d * d * d; + + // Optimization 3: Check if the second sum has passed the first sum. + if (sum2 > sum1) + { + // Since 'd' is increasing, any further increase will also be greater than sum1. + // We stop the 'd' loop and move to the next 'c'. + break; + } + + // 7. CONDITION CHECK: Have we found a Ramanujan number? + // Check if the two sums are equal. + if (sum1 == sum2) + { + count++; // Increment the counter + + // Print the result in the required format. + printf("[%d] %lld = %d^3 + %d^3 = %d^3 + %d^3\n", + count, sum1, a, b, c, d); + + // Set the flag to 1, confirming we found the second way. + found_match = 1; + + // Stop the 'd' loop immediately, as we found the required second pair. + break; + } + } + // If found_match was set to 1, the 'break' in the d loop will execute, + // then the 'if (found_match) break;' in the c loop will execute, + // and the program will move to the next (a, b) pair. + } + } + } + + // 8. CONCLUSION + printf("---------------------------------------------------\n"); + printf("Search complete. Found %d Ramanujan-type numbers.\n", count); + + return 0; // Standard way to indicate successful program execution. +} diff --git a/letusc/luc040.c b/letusc/luc040.c @@ -2,5 +2,64 @@ expressed as sum of cubes in two different ways - 1729 can be expressed as 1^3 + 12^3 and 9^3 + 10^3. Write a program to print all such numbers up to a reasonable limit. */ -/* Author - Amit Dutta, Date - 22th OCT, 2025 */ +/* Author - Amit Dutta, Date - 22nd - 23rd OCT, 2025 */ /* Let Us C, Chap- 6, Page - 106, Qn No.: B(g) */ + +#include <stdio.h> + +#define limit 100000 +#define max_base 47 + +int main() +{ + + long long sum1, sum2; + int count = 0; + + printf("Ramanujan numbers : \n"); + + int found_match; + + for (int a = 1; a <= max_base; a++) + { + for (int b = a + 1; b <= max_base; b++) + { + sum1 = (long long)a * a * a + (long long)b * b * b; + if (sum1 > limit) + { + break; + } + + found_match = 0; + + for (int c = a + 1; c <= max_base; c++) + { + if (found_match) + { + break; + } + for (int d = c + 1; d <= max_base; d++) + { + sum2 = (long long)c * c * c + (long long)d * d * d; + if (sum2 > sum1) + { + break; + } + if (sum1 == sum2) + { + count++; + printf("(%d.) %lld = %d^3 + %d^3 = %d^3 + %d^3\n", count, sum1, a, b, c, d); + + found_match = 1; + break; + } + } + } + } + } + + printf("-------------------------------\n"); + printf("Search complete."); + + return 0; +}+ \ No newline at end of file diff --git a/letusc/luc041.c b/letusc/luc041.c @@ -0,0 +1,3 @@ +/* Write */ +/* Author - Amit Dutta, Date - 23rd OCT, 2025 */ +/* Let Us C, Chap- 6, Page - 106, Qn No.: B(h) */+ \ No newline at end of file
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror