Insertion sort with pyramids
TLAC instruction cards
Insert one pyramid at a time into the sorted row. Compare it with the pyramid to its left; if the pair is out of order, swap them using A1 as a temporary space. Continue left until the new pyramid is in order. The input is 5, 4, 3, 1, 2 and the result is 1, 2, 3, 4, 5.
Read the numbered TLAC cards first, then use the debugger below. Skip a function’s enclosed cards until it is called; after returning, continue at the call site. The right-to-left search function is defined by the original program but is not called in this run.
Jump to the step-through debugger ↓
0001
Load the starting board: sizes 5, 4, 3, 1, 2 in F3–J3
0002
Place the turtle at E10 (X=4, Y=9)
0003
Display “initial board:”
0004
Display the current board
0005
Define function: Find the next unsorted pyramid · Run these cards only when called.
0006

For each x in columns 0 through 9, from left to right, repeat
0007


Display (“Ax:” + x written as text)
0008


Set (value, x, y) to the pyramid size and coordinates at X=x, Y=2; use “not found” if empty
0009


If value differs from “not found”, then
0010



Return to the caller with result: (value, x, y)
0011

Return to the caller with result: no value
0012
Define function: Find the rightmost pyramid in the sorting row · Run these cards only when called.
0013

For each x in columns 9 through 0, from right to left, repeat
0014


Display (“Bx:” + x written as text)
0015


Set (value, x, y) to the pyramid size and coordinates at X=x, Y=4; use “not found” if empty
0016


If value differs from “not found”, then
0017



Return to the caller with result: (value, x, y)
0018

Return to the caller with result: no value
0019
For each col in whole numbers from 0 up to, but not including, 5, repeat
0020

Display (“column ” + col written as text)
0021

Set (pyramid Number, x, y) to the result of calling “Find the next unsorted pyramid”
0022

Display (“HERE pyr ” + pyramid Number written as text)
0023

Move pyramid pyramid Number to X=col, Y=4
0024

Set current to col
0025

While current is greater than 0, repeat
0026


Set (left value, left x, left y) to the pyramid size and coordinates at X=(current − 1), Y=4; use “not found” if empty
0027


Set (current value, current x, current y) to the pyramid size and coordinates at X=current, Y=4; use “not found” if empty
0028


If (left value equals “not found”) or (current value equals “not found”), then
0029



Display “Error: Missing pyramid during bubble”
0030



Leave the innermost loop
0031


If left value is at most current value, then
0032



Leave the innermost loop
0033


Display (((“SWAP pyramids ” + left value written as text) + “ and ”) + current value written as text)
0034


Move pyramid current value to X=0, Y=0
0035


Move pyramid left value to X=current, Y=4
0036


Move pyramid current value to X=(current − 1), Y=4
0037


Update current: (current − 1)
0038
Display “Final sorted board:”
0039
Display the current board
Tarjetas de instrucciones TLAC
Inserta una pirámide a la vez en la fila ordenada. Compárala con la de su izquierda; si están desordenadas, intercámbialas usando A1 como espacio temporal. Continúa hacia la izquierda hasta que quede en orden. La entrada es 5, 4, 3, 1, 2 y el resultado es 1, 2, 3, 4, 5.
Lee primero las tarjetas TLAC numeradas y después usa el depurador de abajo. Salta las tarjetas internas de una función hasta que se llame; al volver, continúa desde la llamada. La función de búsqueda de derecha a izquierda está definida en el programa original, pero no se llama en esta ejecución.
0001
Cargar el tablero inicial: tamaños 5, 4, 3, 1, 2 en F3–J3
0002
Colocar la tortuga en E10 (X=4, Y=9)
0003
Mostrar “initial board:”
0004
Mostrar el tablero actual
0005
Definir función: Buscar la siguiente pirámide sin ordenar · Ejecutar estas tarjetas solo al llamar a la función.
0006

Para cada x en columnas 0 a 9, de izquierda a derecha, repetir
0007


Mostrar (“Ax:” + x escrito como texto)
0008


Poner (value, x, y) en el tamaño y las coordenadas de la pirámide en X=x, Y=2; usar “not found” si está vacío
0009


Si value es distinto de “not found”, entonces
0010



Volver a quien llamó a la función con el resultado: (value, x, y)
0011

Volver a quien llamó a la función con el resultado: sin valor
0012
Definir función: Buscar la pirámide más a la derecha en la fila de ordenación · Ejecutar estas tarjetas solo al llamar a la función.
0013

Para cada x en columnas 9 a 0, de derecha a izquierda, repetir
0014


Mostrar (“Bx:” + x escrito como texto)
0015


Poner (value, x, y) en el tamaño y las coordenadas de la pirámide en X=x, Y=4; usar “not found” si está vacío
0016


Si value es distinto de “not found”, entonces
0017



Volver a quien llamó a la función con el resultado: (value, x, y)
0018

Volver a quien llamó a la función con el resultado: sin valor
0019
Para cada col en enteros desde 0 hasta 5, sin incluirlo, repetir
0020

Mostrar (“column ” + col escrito como texto)
0021

Poner (pyramid Number, x, y) en el resultado de llamar a «Buscar la siguiente pirámide sin ordenar»
0022

Mostrar (“HERE pyr ” + pyramid Number escrito como texto)
0023

Mover la pirámide pyramid Number a X=col, Y=4
0024

Poner current en col
0025

Mientras current es mayor que 0, repetir
0026


Poner (left value, left x, left y) en el tamaño y las coordenadas de la pirámide en X=(current − 1), Y=4; usar “not found” si está vacío
0027


Poner (current value, current x, current y) en el tamaño y las coordenadas de la pirámide en X=current, Y=4; usar “not found” si está vacío
0028


Si (left value es igual a “not found”) o (current value es igual a “not found”), entonces
0029



Mostrar “Error: Missing pyramid during bubble”
0030



Salir del bucle más interno
0031


Si left value es como máximo current value, entonces
0032



Salir del bucle más interno
0033


Mostrar (((“SWAP pyramids ” + left value escrito como texto) + “ and ”) + current value escrito como texto)
0034


Mover la pirámide current value a X=0, Y=0
0035


Mover la pirámide left value a X=current, Y=4
0036


Mover la pirámide current value a X=(current − 1), Y=4
0037


Actualizar current: (current − 1)
0038
Mostrar “Final sorted board:”
0039
Mostrar el tablero actual
TLAC命令カード
ピラミッドを1つずつ整列済みの行へ挿入します。左隣と比べ、順序が逆ならA1を一時置き場にして交換します。正しい位置に来るまで左へ進めます。入力は5、4、3、1、2、結果は1、2、3、4、5です。
まず番号付きのTLACカードを読み、その下のデバッガーを使ってください。関数の中は呼び出されるまで飛ばし、戻ったら呼び出し元から続けます。右から左へ探す関数は元のプログラムで定義されていますが、この実行では呼び出されません。
0001
初期盤面を読み込む:F3~J3にサイズ5、4、3、1、2
0002
亀をE10(X=4、Y=9)に置く
0003
“initial board:”を表示する
0004
現在の盤面を表示する
0005
関数を定義する:次の未整列ピラミッドを探す · 呼び出されたときにだけ中のカードを実行します。
0006

左から右へ列0~9の各xについて繰り返す
0007


(“Ax:” + xを文字列にする)を表示する
0008


(value, x, y)をX=x、Y=2にあるピラミッドのサイズと座標。なければ「not found」にする
0009


もしvalueが“not found”と異なるなら
0010



呼び出し元に戻る(結果:(value, x, y))
0011

呼び出し元に戻る(結果:値なし)
0012
関数を定義する:整列用の行で一番右のピラミッドを探す · 呼び出されたときにだけ中のカードを実行します。
0013

右から左へ列9~0の各xについて繰り返す
0014


(“Bx:” + xを文字列にする)を表示する
0015


(value, x, y)をX=x、Y=4にあるピラミッドのサイズと座標。なければ「not found」にする
0016


もしvalueが“not found”と異なるなら
0017



呼び出し元に戻る(結果:(value, x, y))
0018

呼び出し元に戻る(結果:値なし)
0019
0から5の直前までの整数の各colについて繰り返す
0020

(“column ” + colを文字列にする)を表示する
0021

(pyramid Number, x, y)を「次の未整列ピラミッドを探す」を呼び出した結果にする
0022

(“HERE pyr ” + pyramid Numberを文字列にする)を表示する
0023

ピラミッドpyramid NumberをX=col、Y=4へ動かす
0024

currentをcolにする
0025

currentが0より大きいの間、繰り返す
0026


(left value, left x, left y)をX=(current − 1)、Y=4にあるピラミッドのサイズと座標。なければ「not found」にする
0027


(current value, current x, current y)をX=current、Y=4にあるピラミッドのサイズと座標。なければ「not found」にする
0028


もし(left valueが“not found”に等しい) または (current valueが“not found”に等しい)なら
0029



“Error: Missing pyramid during bubble”を表示する
0030



一番内側の繰り返しを抜ける
0031


もしleft valueがcurrent value以下なら
0032



一番内側の繰り返しを抜ける
0033


(((“SWAP pyramids ” + left valueを文字列にする) + “ and ”) + current valueを文字列にする)を表示する
0034


ピラミッドcurrent valueをX=0、Y=0へ動かす
0035


ピラミッドleft valueをX=current、Y=4へ動かす
0036


ピラミッドcurrent valueをX=(current − 1)、Y=4へ動かす
0037


currentを更新する:(current − 1)
0038
“Final sorted board:”を表示する
0039
現在の盤面を表示する



































































































