Skip to content

Instantly share code, notes, and snippets.

View ananddamodaran's full-sized avatar
🎯
Focusing

Anand ananddamodaran

🎯
Focusing
View GitHub Profile
@ananddamodaran
ananddamodaran / gcd_optimized.py
Created January 22, 2024 14:59
Optimized Approach - Keeping Track of the Most Recent Common Factor https://youtu.be/2W3BKOSg958?si=ghlj6gfgPGuz5yAY
def gcd_optimized(m, n):
mrcf = 0 # Initialize the most recent common factor variable
for i in range(1, min(m, n) + 1): # Loop through numbers from 1 to min(m, n)
if m % i == 0 and n % i == 0: # Check if 'i' is a common factor of m and n
mrcf = i # Update the most recent common factor
return mrcf # Return the most recent common factor found
# Example usage
gcd_result_optimized = gcd_optimized(8, 12)
print("Optimized GCD:", gcd_result_optimized)
@ananddamodaran
ananddamodaran / gcd_using_list.py
Last active January 22, 2024 15:05
First Approach - Using a List to Store Common Factors https://youtu.be/2W3BKOSg958?si=ghlj6gfgPGuz5yAY
def gcd_using_list(m, n):
common_factors = [] # Initialize an empty list to store common factors
for i in range(1, min(m, n) + 1): # Loop through numbers from 1 to min(m, n)
if m % i == 0 and n % i == 0: # Check if 'i' is a common factor of m and n
common_factors.append(i) # Add to the list of common factors
return common_factors[-1] # Return the last element in the list (largest common factor)
# Example usage
gcd_result = gcd_using_list(8, 12)
print("GCD using list:", gcd_result)
@ananddamodaran
ananddamodaran / p6.c
Created June 22, 2019 15:33
Area of a triangle
/** Program No: 06
* Problem statement: Find the area of a triangle
*/
#include <stdio.h>
int main()
{
float base,height,area;
base = 4.0f;
data class NightMode
@ananddamodaran
ananddamodaran / p2.c
Last active August 25, 2017 07:04
Sum of two integers
/** Program No: 02
Aim : Sum of two integers **/
#include <stdio.h>
int main(){
int a,b,sum;
a=10;
b=20;
sum=a+b;