Skip to content

Instantly share code, notes, and snippets.

View piki's full-sized avatar
🔨
Computering

Patrick Reynolds piki

🔨
Computering
View GitHub Profile
@piki
piki / graph.rb
Last active December 15, 2021 15:09 — forked from jithinabraham/graph.rb
Dijkstra's algorithm implemented in ruby
#ruby 2.3.1 recomended
require 'set'
class Graph
attr_reader :graph, :nodes, :previous, :distance #getter methods
INFINITY = 1 << 64
def initialize
@graph = {} # the graph // {node => { edge1 => weight, edge2 => weight}, node2 => ...
@nodes = Set.new