What the code looks like[1]

I have written some latex code for some pseudocode I written which uses:


I was wondering whether there is a standard for algorithms in latex or just in general?

Should I be using that square root or sqrt(state), should I be accessing the array item by state[i] should I be using fractions or just a divide symbol?

Heres the code:

    %this changes the style of the comments 

        \caption{Manhattan Distance}\label{euclid}
            \Procedure{ManDist}{$state$}    \Comment{The current puzzle configuration }
            \State$total\gets 0$
            \State$puzzleLength\gets sizeOf(state)$
            \State$dimensions\gets \sqrt{puzzleLength}$
            \For{$i\gets 1, puzzleLength$}  \Comment{Loops through each tile of the puzzle}
                \State $tileValue\gets state[i]$
                \State $expectedRow\gets \dfrac{(tileValue -1)}{dimensions}$
                \State $expectedCol\gets (tileValue -1)\bmod dimensions$
                \State $rowNum \gets \dfrac{i}{dimensions}$
                \State $rowNum\gets i \bmod dimensions$
                \State $total\gets total \texttt{+} \mid{expectedRow-rowNum}\mid\texttt{+}\mid{expectedCol-colNum}\mid$
            \State \textbf{return} $total$\Comment{The heuristic is the total}

closed as primarily opinion-based by user36296, CarLaTeX, Schweinebacke, gernot, Werner Apr 13 '17 at 15:55

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Welcome to TeX.SX! There is no standard for pseudo algorithms. Yours looks fine. The answer to your questions is largely a matter of taste and aesthetics. Regarding spacing it might be better to use / or div instead of fractions, but as said, this is a matter of taste ... – gernot Apr 13 '17 at 15:01
  • Was just really looking for a little guidance I've been through the entire algorithmc documentation but there's no pseudocode which have any form of calculations in that I can reference to @gernot – user3667111 Apr 13 '17 at 16:20