2

What the code looks like[1]

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

\usepackage{amsmath}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}

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:

\makeatletter
    \def\BState{\State\hskip-\ALG@thistlm}
    \makeatother
    %this changes the style of the comments 

    \begin{algorithm}
        \caption{Manhattan Distance}\label{euclid}
        \begin{algorithmic}[1]
            \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$
            \EndFor
            \State \textbf{return} $total$\Comment{The heuristic is the total}
            \EndProcedure
        \end{algorithmic}
    \end{algorithm}

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