Skip to content

Instantly share code, notes, and snippets.

View Julisam's full-sized avatar
💭
Data Science lover

Julius Odunuga Julisam

💭
Data Science lover
View GitHub Profile
@Julisam
Julisam / calculator.js
Created June 24, 2022 13:56
Introduction to JavaScript
// basic arithmetic calculator without a frontend
var operations = ["+", "-", "*", "/", "**", "%"]
let operation = prompt("Please enter operation");
// check if operation is valid
while (true){
if (!(operations.includes(operation))){
operation = prompt("Invalid operation: Enter operation again")
}
else {
@Julisam
Julisam / introduction.js
Last active June 24, 2022 12:56
Introduction to Javascript
// JavaScript code that prints out my name, height, and country on the screen
console.log("Name: Julius Odunuga")
console.log("Height: 1.7m");
console.log("Country: Nigeria");
@Julisam
Julisam / isThereCycle.py
Last active June 10, 2021 06:05
AlgorithmFriday_Week9
import networkx as nx
def isThereCycle(graph):
if graph==None or type(graph) != dict or len(graph)<0: return False
edges = [(a.upper(),b.upper()) for a in graph for b in graph[a]]
G = nx.DiGraph(edges)
if list(nx.simple_cycles(G)):
return True
else:
return False
@Julisam
Julisam / all_combinations.py
Created May 30, 2021 14:47
AlgorithmFriday_Week8
# First define the list of chars for all digits
num_dict = {'2': ['a', 'b', 'c'],
'3': ['d', 'e', 'f'],
'4': ['g', 'h', 'i'],
'5': ['j', 'k', 'l'],
'6': ['m', 'n', 'o'],
'7': ['p', 'q', 'r', 's'],
'8': ['t', 'u', 'v'],
'9': ['w', 'x', 'y', 'z'],
# just incase 0 and 1 is part of input, we can safely skip
@Julisam
Julisam / shortest_interval.py
Last active May 28, 2021 09:52
AlgorithmFriday_Week7
def shortest_interval(time_arr = []):
if time_arr == None or not isinstance(time_arr, list):
return 0
else:
# convert time_array to minutes
timeInMin = []
for time in time_arr:
try:
h,m = time.split(':')
if int(h)<24 and int(m)<60:
@Julisam
Julisam / shuffleClass.py
Last active May 21, 2021 10:51
AlgorithmFriday_Week6
def shiftLeft(arr, numm):
for _ in range(numm): # O(k)
temp = arr[0]
for i in range(len(arr)-1): # O(n)
arr[i] = arr[i+1]
arr[-1] = temp
return arr
def shiftRight(arr, numm):
for _ in range(numm): # O(k)
@Julisam
Julisam / merge_sorted_list.py
Created May 9, 2021 05:47
AlgorithmFriday_Week5:
def merge_sorted_list(a=[],b=[]):
try:
if (a == None or len(a)==0) and (b== None or len(b)==0):
return []
elif a==None or len(a)==0:
return b
elif b==None or len(b)==0:
return a
# if last element in a is not greater than first element in b, then append b to a
elif a[-1]<=b[0]:
@Julisam
Julisam / get_product.py
Last active May 9, 2021 04:53
AlgorithmFriday_Week4
def get_product(nums=[]):
"""
Given an integer array nums,
returns an arry products, such that each entry at position i, in products is a produc of all the other lements in nms except num[i]
Examle: nums=[4,5,10,2]
Output: [100,80,40,200]
"""
try:
def remove_instance(nums, val):
"""
Given an array nums, and a value val, returns the new length of the array with the value removed
i.e. the number of items in nums with val
Input: nums=[5, 2, 2, 5, 3] and val = 5
Output: 3
"""
try:
#check for cases of an empty array
if len(nums) == 0:
@Julisam
Julisam / Algo1_RemoveDuplicate.py
Created April 9, 2021 22:56
Algorithm Fridays Code Snippet
def remove_duplicates(input_array):
"""
Given a sorted array containing duplicates this function
returns the length of the array without the duplicates
i.e. the number of unique items in the array
Input: nums=[0,0,1,1,2,2,3,3,4]
Output: 5
# O(n) time, O(1) space complexity