The following warnings occurred:
Warning [2] Undefined array key 257355 - Line: 275 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 275 errorHandler->error_callback
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined variable $thread - Line: 295 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 295 errorHandler->error_callback
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Trying to access array offset on value of type null - Line: 295 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 295 errorHandler->error_callback
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined variable $fid - Line: 295 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 295 errorHandler->error_callback
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined array key 257355 - Line: 331 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 331 errorHandler->error_callback
/inc/plugins/threaded_mode.php 304 ThreadedMode::buildtree
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined variable $theme - Line: 3 - File: inc/plugins/threaded_mode.php(305) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php(305) : eval()'d code 3 errorHandler->error_callback
/inc/plugins/threaded_mode.php 305 eval
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Trying to access array offset on value of type null - Line: 3 - File: inc/plugins/threaded_mode.php(305) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php(305) : eval()'d code 3 errorHandler->error_callback
/inc/plugins/threaded_mode.php 305 eval
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined variable $theme - Line: 3 - File: inc/plugins/threaded_mode.php(305) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php(305) : eval()'d code 3 errorHandler->error_callback
/inc/plugins/threaded_mode.php 305 eval
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Trying to access array offset on value of type null - Line: 3 - File: inc/plugins/threaded_mode.php(305) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php(305) : eval()'d code 3 errorHandler->error_callback
/inc/plugins/threaded_mode.php 305 eval
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined variable $lang - Line: 5 - File: inc/plugins/threaded_mode.php(305) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php(305) : eval()'d code 5 errorHandler->error_callback
/inc/plugins/threaded_mode.php 305 eval
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Attempt to read property "messages_in_thread" on null - Line: 5 - File: inc/plugins/threaded_mode.php(305) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php(305) : eval()'d code 5 errorHandler->error_callback
/inc/plugins/threaded_mode.php 305 eval
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks





[HP-Prime] Tower of Hanoi



#2

Tower of Hanoi
more info

http://arbinada.com/pmk/node/1099

[/pre]

EXPORT a,b,k1,k2;
EXPORT j,m,n,vstp,hstp;
EXPORT cl,c,d;
EXPORT lst,stp;

EXPORT PIRAMIDA()
BEGIN

stp:=0;
{{},{},{}}▶lst;
{{},{},{}}▶cl;

REPEAT
INPUT(n,"Введите количество дисков","n=","Натуральное число от 3 до 9",3);
UNTIL n≥3 AND n≤9 AND FP(n)==0;

CASE
IF n==3 THEN hstp:=15;vstp:=40; END;
IF n==4 THEN hstp:=12;vstp:=30; END;
IF n==5 THEN hstp:=10;vstp:=25; END;
IF n==6 THEN hstp:=8;vstp:=20; END;
IF n==7 THEN hstp:=7;vstp:=20; END;
IF n==8 THEN hstp:=6;vstp:=20; END;
IF n==9 THEN hstp:=5;vstp:=20; END;
END;

lst[1]:=MAKELIST(X,X,1,n,1);

RECT_P();
RECT_P(0,0,319,239,#FF0000h,#FFFFFFh);

FOR j FROM 0 TO n-1 DO
RECT_P(7+hstp*j,239-vstp*(j+1),104-hstp*j,237-vstp*j,#000000h,#00FF00h);
END;

TEXTOUT_P("Количество шагов = "+STRING(stp),2,2,7,#000000h);

cl[1]:=MAKELIST({4,238-vstp*(X+1),107,238-vstp*X},X,0,n-1,1);
cl[2]:=MAKELIST({108,238-vstp*(X+1),211,238-vstp*X},X,0,n-1,1);
cl[3]:=MAKELIST({212,238-vstp*(X+1),315,238-vstp*X},X,0,n-1,1);

REPEAT
WAIT(0.3);
REPEAT
0▶k1;
MOUSE(0)▶a;
CASE
IF a≥4 AND a≤107 THEN 1▶k1; END;
IF a≥108 AND a≤211 THEN 2▶k1; END;
IF a≥212 AND a≤315 THEN 3▶k1; END;
END;
UNTIL k1≠0;

REPEAT
0▶k2;
MOUSE(0)▶b;
CASE
IF b≥4 AND b≤107 THEN 1▶k2; END;
IF b≥108 AND b≤211 THEN 2▶k2; END;
IF b≥212 AND b≤315 THEN 3▶k2; END;
END;

UNTIL k2≠0 AND k1≠k2;

CASE

IF SIZE(lst[k1])≠0 AND SIZE(lst[k2])≠0 THEN
IF head(lst[k1])<head(lst[k2]) THEN
SIZE(lst[k1])&#9654;a;
SIZE(lst[k2])+1&#9654;b;
cl[k1,a]&#9654;c;
cl[k2,b]&#9654;d;
SUBGROB_P(G0,d[1],d[2],d[3],d[4],G1);
BLIT_P(G0,d[1],d[2],d[3],d[4],G0,c[1],c[2],c[3],c[4]);
BLIT_P(G0,c[1],c[2],c[3],c[4],G1);
CONCAT(head(lst[k1]),lst[k2])&#9654;lst[k2];
tail(lst[k1])&#9654;lst[k1];
stp:=stp+1;
TEXTOUT_P(" ",217,2,7,#FFFFFFh,100,#FFFFFFh);
TEXTOUT_P(STRING(stp),217,2,7,#000000h,100,#FFFFFFh);
END;
END;

IF SIZE(lst[k1])&#8800;0 AND SIZE(lst[k2])==0 THEN
SIZE(lst[k1])&#9654;a;
1&#9654;b;
cl[k1,a]&#9654;c;
cl[k2,b]&#9654;d;
SUBGROB_P(G0,d[1],d[2],d[3],d[4],G1);
BLIT_P(G0,d[1],d[2],d[3],d[4],G0,c[1],c[2],c[3],c[4]);
BLIT_P(G0,c[1],c[2],c[3],c[4],G1);
CONCAT(head(lst[k1]),lst[k2])&#9654;lst[k2];
tail(lst[k1])&#9654;lst[k1];
stp:=stp+1;
TEXTOUT_P(" ",217,2,7,#FFFFFFh,100,#FFFFFFh);
TEXTOUT_P(STRING(stp),217,2,7,#000000h,100,#FFFFFFh);
END;

END;

UNTIL SIZE(lst[2])==n OR SIZE(lst[3])==n;

TEXTOUT_P("&#1055;&#1054;&#1041;&#1045;&#1044;&#1040; !",115,90,7,#000000h);

WAIT(5);

END;

ASCII GAME

pseudo Code

[pre]
// El objetivo del juego es mover los discos de la torre 1 a la 3 en la
// menor cantidad de movimientos posible. No se puede colocar un disco de
// un tamanio sobre otro mas chico

// Hay una matriz que representa las torres, cada columna contiene
// nros que representan los tamanios de los discos en esas torres (solo
// interesan los valores hasta la cantidad de discos de esa torre).
// Cuantos discos tiene cada torre lo dice el vector cant_discos.

Proceso Hanoi

Dimension torres[3,10], cant_discos[3]

// pedir y validar cuantos discos colocar en la primer torre
Escribir "Ingrese el nro de discos (1-8):"
leer discos
mientras discos<1 O discos>8 Hacer
Escribir "El numero de discos debe ser mayor a 0 y menor a 5:"
leer discos
finmientras

// inicializar los datos
cant_discos[1]<-discos
cant_discos[2]<-0
cant_discos[3]<-0
Para i<-1 Hasta discos hacer
torres[1,i]<-discos-i+1
FinPara


// jugar!
cant_movs<-0
Mientras cant_discos[3]<>discos Hacer // mientras no esten todos los discos en la tercer torre, el juego sigue

Limpiar Pantalla

Para i<-1 Hasta 3 Hacer // dibujar las tres torres
escribir "Torre ",i
si cant_discos[i]=0 Entonces
Escribir ""
sino
para j<-cant_discos[i] hasta 1 con paso -1 Hacer // recorrer los discos de la torre, de arriba hacia abajo
segun torres[i,j] Hacer // dibujar cada disco
1: Escribir " XX"
2: Escribir " XXXXXX"
3: Escribir " XXXXXXXXXX"
4: Escribir " XXXXXXXXXXXXXX"
5: Escribir " XXXXXXXXXXXXXXXXXX"
6: Escribir " XXXXXXXXXXXXXXXXXXXXXX"
7: Escribir " XXXXXXXXXXXXXXXXXXXXXXXXXX"
8: Escribir " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
finsegun
FinPara
finsi
Escribir " ----------------------------------"
Escribir ""
FinPara

// solicitar movimiento
Escribir "Mover desde la torre: "
leer t1
Escribir "hacia la torre: "
leer t2

si t1<1 O t1>3 O t2<1 O t2>3 Entonces // controlar que el nro de torre sea valido
Escribir "Movimiento invalido"
Esperar Tecla
sino
Si cant_discos[t1]=0 Entonces // controlar que la torre 1 tengo al menos un disco
Escribir "Movimiento invalido"
Esperar Tecla
Sino
disco_a_mover <- torres[t1,cant_discos[t1]] // obtener tamanio del disco que se quiere mover
puede_mover<-verdadero
Si cant_discos[t2]<>0 entonces // controlar que la torre dos no tenga discos o tenga solo discos mas grandes
Si torres[t2,cant_discos[t2]]<disco_a_mover Entonces
puede_mover<-Falso
FinSi
FinSi
Si puede_mover Entonces // si paso todos los controles, mover
cant_movs <- cant_movs+1
cant_discos[t2]<-cant_discos[t2]+1
torres[t2,cant_discos[t2]] <- disco_a_mover
cant_discos[t1]<-cant_discos[t1]-1
Sino
Escribir "Movimiento invalido"
Esperar Tecla
FinSi
FinSi
FinSi

FinMientras

// mostrar resultado
Limpiar Pantalla
Escribir "Juego finalizado en ",cant_movs," movimientos!"

FinProceso


Possibly Related Threads…
Thread Author Replies Views Last Post
  OT - Tower of Hanoi Chuck 5 1,670 11-18-2010, 08:38 PM
Last Post: Chuck
  Towers of Hanoi in RPN Kiyoshi Akima 24 4,727 11-18-2010, 12:33 PM
Last Post: Kiyoshi Akima

Forum Jump: