r/algorithms • • Jun 09 '15

A recursive algorithm to learning

void learnSubject(Subject subject) {

if(knowledge.contains(subject)) return;

for(Subject prerequisite : subject.prerequisites) {
    
    learnSubject(prerequisite);

}

knowledge.put(subject);

}

3 Upvotes

8 comments sorted by

4

u/wlu56 Jun 09 '15

Recursion Depth Exceeded! Stack Overflow! - Too much to learn

2

u/Codile Jun 10 '15

That's why you use Haskell cough

-2

u/nitiger Jun 09 '15

This won't even compile.

Unrecognized variable or constant: knowledge.contains

-----------------^

5

u/Iworkonspace Jun 09 '15

Did you remember to #include <brain.h> ?

3

u/nitiger Jun 09 '15

Ahh, there's the problem!

EDIT: Now I have a new error. "Fatal Error: No such file or directory brain.h" I think the system is corrupted.

2

u/[deleted] Jun 09 '15

TIL

1

u/brouwjon Jun 09 '15

Nice-- this is a cool way to lay it all out.

0

u/katyne Jun 09 '15

Like solving a maze that doesn't have any walls.. and never ends.