Latex演算法標準

Latex演算法標準

代碼是什麼樣的[1]

我為我編寫的一些偽代碼編寫了一些乳膠程式碼,其中使用:

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

我想知道乳膠中的演算法是否有一個標準,或者只是一般的標準?

我應該使用平方根還是 sqrt(state),我應該state[i]使用分數還是僅使用除號來存取數組項?

程式碼如下:

\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}

相關內容