This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| You have a function rand7() that generates a random integer from 1 to 7. | |
| Use it to write a function rand5() that generates a random integer from 1 to 5. | |
| rand7() returns each integer with equal probability. | |
| rand5() must also return each integer with equal probability. | |
| */ | |
| function rand5(){ | |
| var x = rand7(); | |
| while(x > 5){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Topological sorting - Example of library dependencies | |
| //Imagine you are given library dependencies in this form in a FILE: | |
| // 4 libraries, 5 dependencies | |
| // 0 -> 1 | |
| // 1 -> 2 | |
| // 2 -> 3 | |
| // 2 -> 4 | |
| // 3 -> | |
| // 4 -> | |
| // Meaning library 0 depends on lib 1...lib 3 depends on nothing etc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Use Gists to store code you would like to remember later on | |
| console.log(window); // log the "window" object to the console |
NewerOlder