Skip to content

Instantly share code, notes, and snippets.

Avatar

Matheus Rosa mdsrosa

View GitHub Profile
@mdsrosa
mdsrosa / dijkstra.py
Last active Apr 14, 2016 — forked from econchick/gist:4666413
Python implementation of Dijkstra's Algorithm
View dijkstra.py
class Graph:
def __init__(self):
self.nodes = set()
self.edges = defaultdict(list)
self.distances = {}
def add_node(self, value):
self.nodes.add(value)
def add_edge(self, from_node, to_node, distance):
@mdsrosa
mdsrosa / dijkstra.py
Created Nov 21, 2015
Modified Python implementation of Dijkstra's Algorithm (https://gist.github.com/econchick/4666413)
View dijkstra.py
from collections import defaultdict, deque
class Graph(object):
def __init__(self):
self.nodes = set()
self.edges = defaultdict(list)
self.distances = {}
def add_node(self, value):
@mdsrosa
mdsrosa / date_challenge.py
Created Oct 28, 2015
Add minutes to a date and subtract minutes from a date without using any Python library
View date_challenge.py
import sys
def sum_minutes_to_date(str_date, minutes):
date, hour = str_date.split(' ')
day, month, year = date.split('/')
day = int(day)
month_start_with_0 = False
if month.startswith('0'): month_start_with_0 = True
month = int(month)