Click here to Skip to main content
15,913,854 members
Home / Discussions / Python
   

Python

 
QuestionMessage Closed Pin
6-Dec-22 21:28
Tangent Technologies6-Dec-22 21:28 
AnswerRe: Variables Pin
trønderen6-Dec-22 22:29
trønderen6-Dec-22 22:29 
QuestionDSA DOUBT Pin
Krishang Gupta1-Dec-22 11:03
Krishang Gupta1-Dec-22 11:03 
AnswerRe: DSA DOUBT Pin
Richard Deeming1-Dec-22 22:08
mveRichard Deeming1-Dec-22 22:08 
QuestionHow to iterate within a list in python? Pin
ryandaniel1724-Nov-22 18:48
ryandaniel1724-Nov-22 18:48 
AnswerRe: How to iterate within a list in python? Pin
Richard MacCutchan24-Nov-22 22:13
mveRichard MacCutchan24-Nov-22 22:13 
AnswerRe: How to iterate within a list in python? Pin
Gulshan Negi15-Mar-23 23:28
professionalGulshan Negi15-Mar-23 23:28 
QuestionPlz Help Trying to make driving game more realistic and fun (pygame) Pin
s897422-Nov-22 20:41
s897422-Nov-22 20:41 
AnswerRe: Plz Help Trying to make driving game more realistic and fun (pygame) Pin
Gulshan Negi14-Feb-23 21:34
professionalGulshan Negi14-Feb-23 21:34 
QuestionPython Code Related Pin
Mr.Zeenore18-Nov-22 12:28
Mr.Zeenore18-Nov-22 12:28 
AnswerRe: Python Code Related Pin
Dave Kreskowiak18-Nov-22 17:55
mveDave Kreskowiak18-Nov-22 17:55 
GeneralRe: Python Project Question Pin
Mr.Zeenore18-Nov-22 21:36
Mr.Zeenore18-Nov-22 21:36 
AnswerRe: Python Project Question Pin
OriginalGriff18-Nov-22 21:36
mveOriginalGriff18-Nov-22 21:36 
GeneralRe: Python Project Question Pin
Craig Robbins7-Dec-22 1:06
Craig Robbins7-Dec-22 1:06 
GeneralRe: Python Project Question Pin
trønderen7-Dec-22 3:04
trønderen7-Dec-22 3:04 
GeneralRe: Python Code Related Pin
Mr.Zeenore18-Nov-22 20:09
Mr.Zeenore18-Nov-22 20:09 
GeneralRe: Python Code Related Pin
Dave Kreskowiak19-Nov-22 4:07
mveDave Kreskowiak19-Nov-22 4:07 
AnswerRe: Python Code Related Pin
Richard MacCutchan18-Nov-22 22:35
mveRichard MacCutchan18-Nov-22 22:35 
QuestionPython vs. PHP - Web Application Development Pin
vitaassure15-Nov-22 10:30
professionalvitaassure15-Nov-22 10:30 
AnswerRe: Python vs. PHP - Web Application Development Pin
Gerry Schmitz15-Nov-22 12:11
mveGerry Schmitz15-Nov-22 12:11 
AnswerRe: Python vs. PHP - Web Application Development Pin
Richard MacCutchan15-Nov-22 21:34
mveRichard MacCutchan15-Nov-22 21:34 
QuestionPython code Pin
Masande Nogemane3-Nov-22 6:34
Masande Nogemane3-Nov-22 6:34 
AnswerRe: Python code Pin
Richard MacCutchan3-Nov-22 7:47
mveRichard MacCutchan3-Nov-22 7:47 
QuestionPython Code Heuristic Algorithm Pin
Member 1581467330-Oct-22 19:31
Member 1581467330-Oct-22 19:31 
Me enviaron hacer que el algorimo heruistico que esta de forma lineal sea dinamico, osea que el cambio de posicion lo genere de forma dinamica mediante el ingreso del tamaño del array, pero no me sale me podrian ayudar??? solo he logrado que imprima el array pero no me sale el cambio de posicion

Google translate:
They sent me to make the heruistic algorithm that is linearly dynamic, that is, the change of position is generated dynamically by entering the size of the array, but it doesn't work out, could you help me??? I have only managed to print the array but I do not get the change of position

Python
# Puzle Lineal con heurística  
from re import I
from ClaseNodo import Nodo
def buscar_solucion_heuristica(nodo_inicial, solucion, visitados):
        visitados.append(nodo_inicial.get_datos())
        if nodo_inicial.get_datos() == solucion:
            return nodo_inicial
        else:
            # expandir nodos sucesores (hijos)
            dato_nodo = nodo_inicial.get_datos()
            i=0
            while i < tamaño :
                hijo=[]
                hijo.append(dato_nodo)
                i=i+1
            hijo=[dato_nodo[1], dato_nodo[0], dato_nodo[2], dato_nodo[3], dato_nodo[4], dato_nodo[5]]
            hijo_izquierdo = Nodo(hijo)
            hijo=[dato_nodo[1], dato_nodo[0], dato_nodo[3], dato_nodo[2], dato_nodo[4], dato_nodo[5]]
            hijo_central = Nodo(hijo)
            hijo=[dato_nodo[1], dato_nodo[0], dato_nodo[3], dato_nodo[2], dato_nodo[5], dato_nodo[4]]
            hijo_derecho = Nodo(hijo)
            nodo_inicial.set_hijos([hijo_izquierdo, hijo_central, hijo_derecho])
            for nodo_hijo in nodo_inicial.get_hijos():
                if not nodo_hijo.get_datos() in visitados and mejora(nodo_inicial, nodo_hijo):
                    # llamada recursiva
                    sol= buscar_solucion_heuristica(nodo_hijo, solucion, visitados)
                    if sol != None:
                        return sol

                
            return None

def mejora(nodo_padre, nodo_hijo):
    calidad_padre=0
    calidad_hijo=0
    dato_padre = nodo_padre.get_datos()
    dato_hijo = nodo_hijo.get_datos()
    for n in range(1,len(dato_padre)):
        if (dato_padre[n]>dato_padre[n-1]):
            calidad_padre = calidad_padre + 1;
        if (dato_hijo[n]>dato_hijo[n-1]):
            calidad_hijo = calidad_hijo + 1;
            
    if calidad_hijo>=calidad_padre:
        return True
    else:
        return False 

if __name__ == "__main__":
            i=0
            j=0
            estado_inicial=[]
            tamaño =int(input("Por Favor, Introduzca el tamaño del array"))
            while i < tamaño:
                inicio =int(input("Por Favor, Introduzca un numero"))
                estado_inicial.append(inicio)
                i=i+1
            
            solucion=[]
            while j < tamaño:
                final =int(input("Por Favor, Introduzca el solucion"))
                solucion.append(final)
                j=j+1   
            nodo_solucion = None
            visitados=[]
            nodo_inicial = Nodo(estado_inicial)
            nodo = buscar_solucion_heuristica(nodo_inicial, solucion, \
                                          visitados)
            # mostrar resultado
            resultado=[]
            while nodo.get_padre() != None:
                resultado.append(nodo.get_datos())
                nodo = nodo.get_padre()
            resultado.append(estado_inicial)
            resultado.reverse()
            print(resultado)

AnswerRe: Python Code Heuristic Algorithm Pin
OriginalGriff30-Oct-22 19:34
mveOriginalGriff30-Oct-22 19:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.