Programming language shootout: code most like pseudocode for Dijkstra's Algorithm
- by Casebash
Okay, so this question here asked which language is most like executable pseudocode, so why not find out by actually writing some code! Here we have a competition where I will award a 100 point bounty (I know its not much, but I am poor after the recalc) to the code which most resembles this pseudocode. I've read through this a few times so I'm pretty sure that this pseudocode below is correct and about as unambiguous as pseudocode can be.
Personally, I'm going to have a go in Python and probably Haskell as well, but I'm just learning the later so my attempt will probably be pretty poor.
Note: Obviously to implement anything looking like this you'll have to define quite a few library functions.
define DirectedGraph G with:
Vertices as V, Edges as E
define Vertex A, Z
declare each e in E as having properties:
Boolean fixed with:
initial=false
Real minSoFar with:
initial=0 for A else infinity
define PriorityQueue pq with:
objects=V
initial=A
priority v=v.minSoFar
create triggers for v in V:
when v.minSoFar event reduced then pq.addOrUpdate v
when v.fixed event becomesTrue then pq.remove v
Repeat until Z.fixed==True:
define Vertex U=pq.pop()
U.fixed=True
for Edge E adjacentTo U with other Vertex V:
V.minSoFar=U.minSoFar+length(E) if reducesValue
return Z.name, Z.minSoFar