Click here to Skip to main content
14,365,424 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: Well, I may be looking for work soon Pin
#realJSOP26-Apr-19 0:26
mve#realJSOP26-Apr-19 0:26 
GeneralRe: Well, I may be looking for work soon Pin
markrlondon26-Apr-19 2:41
membermarkrlondon26-Apr-19 2:41 
GeneralRe: Well, I may be looking for work soon Pin
#realJSOP26-Apr-19 2:59
mve#realJSOP26-Apr-19 2:59 
GeneralRe: Well, I may be looking for work soon Pin
markrlondon26-Apr-19 3:03
membermarkrlondon26-Apr-19 3:03 
GeneralRe: Well, I may be looking for work soon Pin
#realJSOP26-Apr-19 3:17
mve#realJSOP26-Apr-19 3:17 
GeneralRe: Well, I may be looking for work soon Pin
markrlondon26-Apr-19 5:31
membermarkrlondon26-Apr-19 5:31 
GeneralRe: Well, I may be looking for work soon Pin
RickZeeland26-Apr-19 2:48
mveRickZeeland26-Apr-19 2:48 
GeneralClassic computer science problems Pin
raddevus25-Apr-19 9:47
mvaraddevus25-Apr-19 9:47 
I stumbled upon this new book and I've completed the intro and first chapter.
Classic Computer Science Problems in Python: David Kopec: 9781617295980: Amazon.com: Books[^]

It's actually quite good.
The author writes clearly and makes a point that he backs up with code.
It covers some nice topics that I've been wanting from an introductory level and then proceeding deeper.
* Search algorithms
* Common techniques for graphs
* Neural networks
* Genetic algorithms
* Adversarial search

Wishing For C#
I've been looking for something like this but written in C#.
So, I've begun re-writing the algorithms in C#.
Here are all fibonacci algos rewritten in C#.
I learned quite a bit from rewriting them.

It's a good example to go from recursion to memoization to for loop to yield.

int fibWithRecursion(int n){
        // Of course the stack will explode before you can calc very large fibs.
	if (n < 2){
		return n;
	}
	return fibWithRecursion(n -1) + fibWithRecursion(n-2);
}

Dictionary<decimal,decimal> d = new Dictionary<decimal,decimal>();
decimal fib(decimal n){
        if (n<2) return n;
	// ### using memoization
	if (!d.ContainsKey(n)){
		decimal x = fib(n-1) + fib(n-2);
		d.Add(n,x);
	}
	return d[n];
}

decimal fibViaFor(decimal n){
	if (n == 0) return n;
	decimal prev = 0;
	decimal next = 1;
	
	for (int i = 1; i < n;i++){
		decimal oldPrev = prev;
		prev = next;
		next = oldPrev + next;
	}
	return next;
}

IEnumerable<decimal> fibViaIterator(decimal n){
	decimal prev =0;
	decimal next = 1;
	for (decimal i = 0; i < n; i++){
		yield return prev;
		decimal localFib = prev + next;
		prev = next;
		next = localFib;
	}
}

Grab a free copy of LINQPad - The .NET Programmer's Playground[^] and try them out.

Here's the driver code you can use to try each algo:

for (int x = 0; x<15;x++){
		Console.Write($"{fibWithRecursion(x)} ");
	}
	Console.Write("\n");
	
	for (int x = 0; x<15;x++){
		Console.Write($"{fib(x)} ");
	}
	Console.Write("\n");
	
	for (int x = 0; x<15;x++){
		Console.Write($"{fibViaFor(x)} ");
	}
	Console.Write("\n");
	
	foreach (decimal x in fibViaIterator(15)){
		Console.Write($"{x} ");
	}
	Console.Write("\n");



Output looks like the following (each algo produces 1 line):
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

GeneralRe: Classic computer science problems Pin
Marc Clifton25-Apr-19 9:52
protectorMarc Clifton25-Apr-19 9:52 
GeneralRe: Classic computer science problems Pin
raddevus25-Apr-19 9:57
mvaraddevus25-Apr-19 9:57 
GeneralRe: Classic computer science problems Pin
Fueled By Caffeine25-Apr-19 22:16
memberFueled By Caffeine25-Apr-19 22:16 
GeneralRe: Classic computer science problems Pin
raddevus26-Apr-19 3:14
mvaraddevus26-Apr-19 3:14 
GeneralRe: Classic computer science problems Pin
Dominic Burford25-Apr-19 23:01
professionalDominic Burford25-Apr-19 23:01 
GeneralRe: Classic computer science problems Pin
pkfox26-Apr-19 1:32
professionalpkfox26-Apr-19 1:32 
GeneralRe: Classic computer science problems Pin
raddevus26-Apr-19 3:15
mvaraddevus26-Apr-19 3:15 
GeneralRe: Classic computer science problems Pin
harold aptroot26-Apr-19 5:34
memberharold aptroot26-Apr-19 5:34 
GeneralRe: Classic computer science problems Pin
raddevus26-Apr-19 6:34
mvaraddevus26-Apr-19 6:34 
GeneralRe: Classic computer science problems Pin
harold aptroot26-Apr-19 7:09
memberharold aptroot26-Apr-19 7:09 
GeneralRe: Classic computer science problems Pin
raddevus26-Apr-19 8:30
mvaraddevus26-Apr-19 8:30 
GeneralSmartXML Pin
Bassam Abdul-Baki25-Apr-19 9:05
professionalBassam Abdul-Baki25-Apr-19 9:05 
GeneralRe: SmartXML Pin
Mark_Wallace25-Apr-19 9:07
memberMark_Wallace25-Apr-19 9:07 
GeneralRe: SmartXML Pin
Bassam Abdul-Baki25-Apr-19 10:13
professionalBassam Abdul-Baki25-Apr-19 10:13 
GeneralRe: SmartXML Pin
Marc Clifton25-Apr-19 9:54
protectorMarc Clifton25-Apr-19 9:54 
GeneralRe: SmartXML Pin
Bassam Abdul-Baki25-Apr-19 10:13
professionalBassam Abdul-Baki25-Apr-19 10:13 
GeneralRe: SmartXML Pin
Mark_Wallace25-Apr-19 10:55
memberMark_Wallace25-Apr-19 10:55 

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.