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
/* | |
different ways of looping through a vector in c++ | |
*/ | |
#include <iostream> | |
#include <vector> | |
#include <numeric> // for style_four | |
using std::cout; | |
using std::vector; |
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
""" | |
The try block tries to execute an expression | |
If an error occurs, it calls the except block alone | |
If no error occur, it calls the else block | |
The idea behind this is, if the school exists, print it out | |
""" | |
schools = { |
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
""" | |
This demonstrates how to use singledispatch for dispatching on type | |
We want to draw each based on the type. Typically, we can use if else statement to check the type | |
then call the function that does draw the shape, however, we will keep having multiple if elif statement. | |
This is just another pythonic way of doing it | |
""" | |
from functools import singledispatch |
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
def slow_gcd(arg1,arg2): | |
gcd = 0 | |
for num in range(1, arg1 + arg2+ 1): | |
if (arg1 % num == 0) and (arg2 %num == 0): | |
gcd = num | |
return gcd | |
def fast_gcd(arg1,arg2): | |
if arg2 == 0: |
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
def slow_fibonacci_number(n): | |
if n <= 1: | |
return n | |
return slow_fibonacci_number(n - 1) + slow_fibonacci_number(n - 2) | |
def fast_fibonacci_number(n): | |
numbers = [0, 1] | |
for num in range(2, n+1): | |
numbers.append(numbers[num - 1] + numbers[num - 2]) |