Click here to Skip to main content
15,906,567 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Working it out is simple... Pin
jeron117-Nov-16 9:19
jeron117-Nov-16 9:19 
GeneralRe: Working it out is simple... Pin
Manfred Rudolf Bihy17-Nov-16 9:33
professionalManfred Rudolf Bihy17-Nov-16 9:33 
GeneralRe: Working it out is simple... Pin
Pete O'Hanlon17-Nov-16 10:08
mvePete O'Hanlon17-Nov-16 10:08 
GeneralRe: Working it out is simple... Pin
Mycroft Holmes17-Nov-16 13:13
professionalMycroft Holmes17-Nov-16 13:13 
GeneralRe: Working it out is simple... Pin
HobbyProggy17-Nov-16 20:23
professionalHobbyProggy17-Nov-16 20:23 
GeneralRe: Working it out is simple... Pin
V.17-Nov-16 21:33
professionalV.17-Nov-16 21:33 
GeneralRe: Working it out is simple... Pin
super17-Nov-16 23:27
professionalsuper17-Nov-16 23:27 
GeneralAOTD: Euclidean Algorithm (calcGCD), Very Mod Pin
raddevus17-Nov-16 8:12
mvaraddevus17-Nov-16 8:12 
AOTD : Algo Of The Day
Did you know you could calc GCD (Greatest Common Divisor) of two numbers using only the modulus operator? Pretty cool.

I'm still reading the Modern Cryptography book[^] and I wrote an interesting algo based upon the author's description of the Euclidean Algorithm. I thought it was kind of neat.

Fire up LINQPad (free C# code running tool) [^] paste the code below and try it out. You'll like it.
C#
void Main()
{
	long first = 15332490;
	long second = 83749023324; // 15332490 // 15332489

	for (var x = 1; x < 10;x++){
		calcGCD (first, second);
		first +=1348; // for testing, add arbitrary value and calcGCG again...
	}
	
}


void calcGCD(long a, long b){
	long dividend = Math.Max(a, b);
	long divisor = Math.Min(a,b);
	while (divisor >= 1){
		var tempVal  = dividend % divisor;
		Console.WriteLine(String.Format("value : {0}", tempVal));
		dividend = divisor;
		divisor = tempVal;
	}
	if (dividend > 1){
		Console.WriteLine ("GCD is dividend : {0} ", dividend);
	}
	else{
		Console.WriteLine("The two numbers do not share a Common Divisor");
	}
	Console.WriteLine("##############################");
	Console.WriteLine();
}


Output looks like:
value : 2962944
value : 517770
value : 374094
value : 143676
value : 86742
value : 56934
value : 29808
value : 27126
value : 2682
value : 306
value : 234
value : 72
value : 18
value : 0
GCD is dividend : 18 
##############################

value : 10934006
value : 4399832
value : 2134342
value : 131148
value : 35974
value : 23226
value : 12748
value : 10478
value : 2270
value : 1398
value : 872
value : 526
value : 346
value : 180
value : 166
value : 14
value : 12
value : 2
value : 0
GCD is dividend : 2 
##############################

value : 11547684
value : 3788850
value : 181134
value : 166170
value : 14964
value : 1566
value : 870
value : 696
value : 174
value : 0
GCD is dividend : 174 
##############################

My book, Launch Your Android App, is available at Amazon.com (only $2.99USD over 350 pages).
Get my Android app on Google Play and F*orget All Your Passwords.

GeneralRe: AOTD: Euclidean Algorithm (calcGCD), Very Mod Pin
harold aptroot17-Nov-16 8:17
harold aptroot17-Nov-16 8:17 
GeneralRe: AOTD: Euclidean Algorithm (calcGCD), Very Mod Pin
raddevus17-Nov-16 8:19
mvaraddevus17-Nov-16 8:19 
GeneralRe: AOTD: Euclidean Algorithm (calcGCD), Very Mod Pin
BillWoodruff17-Nov-16 12:49
professionalBillWoodruff17-Nov-16 12:49 
GeneralRe: AOTD: Euclidean Algorithm (calcGCD), Very Mod Pin
raddevus17-Nov-16 13:43
mvaraddevus17-Nov-16 13:43 
GeneralRe: AOTD: Euclidean Algorithm (calcGCD), Very Mod Pin
BillWoodruff17-Nov-16 14:42
professionalBillWoodruff17-Nov-16 14:42 
GeneralRe: AOTD: Euclidean Algorithm (calcGCD), Very Mod Pin
raddevus18-Nov-16 2:28
mvaraddevus18-Nov-16 2:28 
GeneralRe: AOTD: Euclidean Algorithm (calcGCD), Very Mod Pin
Bassam Abdul-Baki18-Nov-16 1:02
professionalBassam Abdul-Baki18-Nov-16 1:02 
GeneralRe: AOTD: Euclidean Algorithm (calcGCD), Very Mod Pin
raddevus18-Nov-16 2:32
mvaraddevus18-Nov-16 2:32 
AnswerRe: AOTD: Euclidean Algorithm (calcGCD), Very Mod Pin
Patrice T18-Nov-16 10:42
mvePatrice T18-Nov-16 10:42 
GeneralThey Think I'm a Genius Pin
#realJSOP17-Nov-16 8:04
professional#realJSOP17-Nov-16 8:04 
GeneralRe: They Think I'm a Genius Pin
Mark_Wallace17-Nov-16 8:32
Mark_Wallace17-Nov-16 8:32 
GeneralRe: They Think I'm a Genius Pin
Jeremy Falcon17-Nov-16 11:07
professionalJeremy Falcon17-Nov-16 11:07 
GeneralRe: They Think I'm a Genius Pin
hooodaticus17-Nov-16 8:32
hooodaticus17-Nov-16 8:32 
GeneralRe: They Think I'm a Genius Pin
Jeremy Falcon17-Nov-16 11:05
professionalJeremy Falcon17-Nov-16 11:05 
GeneralRe: They Think I'm a Genius PinPopular
#realJSOP17-Nov-16 12:07
professional#realJSOP17-Nov-16 12:07 
GeneralRe: They Think I'm a Genius Pin
Jeremy Falcon17-Nov-16 12:13
professionalJeremy Falcon17-Nov-16 12:13 
GeneralRe: They Think I'm a Genius Pin
Nelek17-Nov-16 18:40
protectorNelek17-Nov-16 18:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.