Foros del Web » Programando para Internet » PHP »

Ayuda con algoritmo de a-z

Estas en el tema de Ayuda con algoritmo de a-z en el foro de PHP en Foros del Web. Bueno amigos les planteo el problema. Necesito recorrer de a-z de la siguiente forma Código: abc => "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-" a b c d e f g ...
  #1 (permalink)  
Antiguo 25/07/2010, 18:12
Avatar de xalupeao  
Fecha de Ingreso: mayo-2008
Ubicación: Santiago, Chile
Mensajes: 749
Antigüedad: 15 años, 11 meses
Puntos: 12
Ayuda con algoritmo de a-z

Bueno amigos les planteo el problema.

Necesito recorrer de a-z de la siguiente forma


Código:
abc => "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-"

a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
w
y
z

aa
ab
ac
ad
ae
af
ag
ah
ai
aj
ak
al
am
an
ao
ap
aq
ar
as
at
au
aw
ay
az

aa[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]
ab[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]
ac[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]
ad[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]
ae[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]
af[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]
ag[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]
ah[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]
ai[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]
aj[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]
ak[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]
al[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]
am[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]
an[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]
ao[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]
ap[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]
aq[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]
ar[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]
as[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]
at[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]
au[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]
aw[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]
ay[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]
az[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,w,y,z,-]

y al terminar esto siga asi

ba
bb
bc
bd
be
bf
bg
bh
bi
bj
bk
bl
bm
bn
bo
bp
bq
br
bs
bt
bu
bw
by
bz

................ y asi con todas las letras.

¿se entiende mas o menos lo que quiero generar?

-------------------
Tengo este codigo que acabo de hacer pero solo llego a las 2 parte.
--------------------

Código PHP:
Ver original
  1. <?php
  2.  
  3.     $largo = 34;
  4.     $switch=true;
  5.     $ready=true;
  6.     $x=0;
  7.     $abc = array(0,1,3,4,5,6,7,8,9,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','w','x','y','z','-');
  8.     while($switch){
  9.         if($ready){
  10.             for($i=0;$i<=$largo;$i++){
  11.             print $abc[$i].'<br />'; flush();
  12.             }
  13.         }
  14.         $ready=false;
  15.         for($i=0;$i<=$largo;$i++){
  16.         print $abc[$x].$abc[$i].'<br />'; flush();
  17.         }
  18.         $x++;
  19.         if($x > 34){
  20.             $switch=false;
  21.         }
  22.     }
  23. ?>
__________________
Hosting en Chile en Silverhost - La solución en Hosting en Chile.

Última edición por xalupeao; 25/07/2010 a las 18:33
  #2 (permalink)  
Antiguo 25/07/2010, 18:42
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 10 meses
Puntos: 1517
Respuesta: Ayuda con algoritmo de a-z

¿Algo así?
Código PHP:
Ver original
  1. <?php
  2. $str = 'abcdefghijklmnopqrstuvwyz';
  3. $mainLetter = '';
  4. $letter = '';
  5. for($i=0; $i<strlen($str); ++$i){
  6.     $mainLetter = $str[$i];
  7.     for($c=0; $c<strlen($str); $c++){
  8.         for($n=0; $n<strlen($str); $n++){
  9.             echo $letter . $str[$n] . '<br />';
  10.         }
  11.         $letter = $mainLetter . substr($str,0,$c);
  12.     }
  13. }
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos
  #3 (permalink)  
Antiguo 25/07/2010, 19:32
Avatar de xalupeao  
Fecha de Ingreso: mayo-2008
Ubicación: Santiago, Chile
Mensajes: 749
Antigüedad: 15 años, 11 meses
Puntos: 12
Respuesta: Ayuda con algoritmo de a-z

una consulta.

que diferencia hay entre ++$i con $i++?
__________________
Hosting en Chile en Silverhost - La solución en Hosting en Chile.
  #4 (permalink)  
Antiguo 25/07/2010, 19:44
Avatar de eZakto  
Fecha de Ingreso: julio-2008
Mensajes: 214
Antigüedad: 15 años, 9 meses
Puntos: 5
Respuesta: Ayuda con algoritmo de a-z

Cita:
Iniciado por xalupeao Ver Mensaje
que diferencia hay entre ++$i con $i++?
Creo que con el primero te ahorras algunos bits de memoria.
__________________
eZakto™
  #5 (permalink)  
Antiguo 25/07/2010, 21:24
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 10 meses
Puntos: 1517
Respuesta: Ayuda con algoritmo de a-z

Bueno, en ese caso es que estaba verificando algo antes de entregarlo y se me olvido cambiarlo
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos

Etiquetas: a-z, algoritmos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:50.