#with(queue): #this is a fixed version of the line_vertices in everything.txt #(see comment in everthing.txt for usage) #this one allows teh start and end vertices to be boundary points our_line_vertices:=proc(m_func,startpt,first_neighbor,rest_neighbor) local lineT,vm,outlist,ending,last_pt; lineT:=gasket(m_func); vm:=vertices(m_func); make_neighbors(lineT,m_func,vm); outlist:=[startpt,lineT[startpt,first_neighbor]]; ending:=last_digits(lineT[startpt,first_neighbor]); last_pt:=lineT[startpt,first_neighbor]; while nops(lineT[last_pt,rest_neighbor])>1 and last_digits(lineT[last_pt,rest_neighbor])=ending do outlist:=[op(outlist),lineT[last_pt,rest_neighbor]]; last_pt:=lineT[last_pt,rest_neighbor]; od; outlist:=[op(outlist),lineT[last_pt,rest_neighbor]]; outlist; end; #returns the number of steps in the lvlth gasket between startv #and endv...ie the graph distance. #this uses a bredth first search verDist:=proc(lvl,startv,endv) local T,ver,vertex,Q,val,i,numneighbors; ver:=ourVertices(lvl); T:=gasket(lvl); make_neighbors(T,lvl,ver); for vertex in ver do T[vertex,5]:=false; end do; Q:=queue[new](); queue[enqueue](Q,[startv,0]); while not queue[empty](Q) do val:=queue[dequeue](Q); if val[1]=endv then return(val[2]); end if; if nops(val[1])<2 then numneighbors:=2; else numneighbors:=4; end if; for i from 1 to numneighbors do if not T[T[val[1],i],5] then queue[enqueue](Q,[T[val[1],i],val[2]+1]); T[T[val[1],i],5]:=true; end if; end do; end do; return(-1); end; #this is an optimzation of gasket in everything.txt #it sets T[i,-1] to be vertices(i) for i from 1 to m #this cuts down on calls to vertices in functions that #assume this call to verGasket verGasket:=proc(m) local i, vm, T; vm:= vertices(m); T:=table(); for i from 1 to nops(vm) do T[vm[i], 0] := vm[i] od; for i from 1 to m do T[i,-1]:=ourVertices(i); end do; return(T); end; #firstP:=proc(nums,len) # local l; # l:=[]; # for i from 1 to len do # l:=[op(l),nums[1]]; # end do; # return(l); #end; #nextP:=proc(nums,lastp) # local newp,lastnum; # lastnum:=nums[nops(nums)]; # #end;