Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Solving problems with my craft

Raheem Azeez Abiodun raheemazeezabiodun

🎯
Solving problems with my craft
View GitHub Profile
@raheemazeezabiodun
raheemazeezabiodun / two_dimensional_vectors.cpp
Created Jan 8, 2020
Different ways of looping through a vector in c++
View two_dimensional_vectors.cpp
/*
different ways of looping through a vector in c++
*/
#include <iostream>
#include <vector>
#include <numeric> // for style_four
using std::cout;
using std::vector;
@raheemazeezabiodun
raheemazeezabiodun / try_else.py
Created Sep 19, 2019
An example of how to use try except else in Python
View try_else.py
"""
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 = {
@raheemazeezabiodun
raheemazeezabiodun / dispatch_on_type.py
Last active Sep 19, 2019
A way of dispatching action based on type in Python.
View dispatch_on_type.py
"""
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
@raheemazeezabiodun
raheemazeezabiodun / gcd.py
Created Jul 23, 2019
Computing greatest common divisor
View gcd.py
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:
@raheemazeezabiodun
raheemazeezabiodun / fibonacci.py
Created Jul 22, 2019
A fibonacci sequence with a better approach
View fibonacci.py
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])